diff --git a/commerce_cart_flyout.info.yml b/commerce_cart_flyout.info.yml index 3a75147..94d0c69 100644 --- a/commerce_cart_flyout.info.yml +++ b/commerce_cart_flyout.info.yml @@ -1,7 +1,6 @@ name: Commerce Cart Flyout description: Replaces the default cart block to use a offcanvas flyout -core: 8.x -core_version_requirement: ^8 || ^9 +core_version_requirement: ^9 || ^10 type: module dependencies: - commerce:commerce_cart diff --git a/commerce_cart_flyout.libraries.yml b/commerce_cart_flyout.libraries.yml index aabc771..226f97b 100644 --- a/commerce_cart_flyout.libraries.yml +++ b/commerce_cart_flyout.libraries.yml @@ -10,11 +10,11 @@ flyout: css/module.css: { } dependencies: - core/jquery - - core/jquery.once + - core/once - core/drupal - core/drupalSettings - - core/backbone - - core/underscore + - core/internal.backbone + - core/internal.underscore add_to_cart: version: VERSION @@ -27,9 +27,9 @@ add_to_cart: js/views/AddToCart.js: { } dependencies: - core/jquery - - core/jquery.once + - core/once - core/drupal - core/drupalSettings - - core/backbone - - core/underscore + - core/internal.backbone + - core/internal.underscore - commerce_cart_flyout/flyout diff --git a/js/add-to-cart.es6.js b/js/add-to-cart.es6.js index d7c988c..493ccab 100644 --- a/js/add-to-cart.es6.js +++ b/js/add-to-cart.es6.js @@ -1,4 +1,4 @@ -(($, _, Drupal, drupalSettings) => { +(($, _, Drupal, once, drupalSettings) => { Drupal.theme.addToCartButton = () => { return drupalSettings.theme.commerce_cart_flyout_add_to_cart_button }; @@ -22,7 +22,7 @@ Drupal.addToCart = {}; Drupal.behaviors.addToCart = { attach(context) { - $(context).find('[data-product]').once('flyout-add-to-cart').each((k,el) => { + $(once('flyout-add-to-cart', $(context).find('[data-product]', context))).each((k,el) => { const model = new Drupal.addToCart.AddToCartModel( drupalSettings.addToCart[el.dataset.product] ); @@ -30,4 +30,4 @@ }); } } -})(jQuery, _, Drupal, drupalSettings); +})(jQuery, _, Drupal, once, drupalSettings); diff --git a/js/add-to-cart.js b/js/add-to-cart.js index afa8d84..b354276 100644 --- a/js/add-to-cart.js +++ b/js/add-to-cart.js @@ -5,7 +5,7 @@ * @preserve **/ -(function ($, _, Drupal, drupalSettings) { +(function ($, _, Drupal, once, drupalSettings) { Drupal.theme.addToCartButton = function () { return drupalSettings.theme.commerce_cart_flyout_add_to_cart_button; }; @@ -37,10 +37,10 @@ Drupal.addToCart = {}; Drupal.behaviors.addToCart = { attach: function attach(context) { - $(context).find('[data-product]').once('flyout-add-to-cart').each(function (k, el) { + $(once('flyout-add-to-cart', $(context).find('[data-product]', context))).each(function (k, el) { var model = new Drupal.addToCart.AddToCartModel(drupalSettings.addToCart[el.dataset.product]); new Drupal.addToCart.AddToCartView({ el: el, model: model }); }); } }; -})(jQuery, _, Drupal, drupalSettings); \ No newline at end of file +})(jQuery, _, Drupal, once, drupalSettings); \ No newline at end of file diff --git a/js/module.es6.js b/js/module.es6.js index 4a0984f..63267b1 100644 --- a/js/module.es6.js +++ b/js/module.es6.js @@ -1,4 +1,4 @@ -(($, _, Drupal, drupalSettings) => { +(($, _, Drupal, once, drupalSettings) => { const cache = {}; Drupal.cartFlyout = { templates: {}, @@ -65,7 +65,7 @@ Drupal.behaviors.cartFlyout = { attach(context) { Drupal.cartFlyout.templates = drupalSettings.cartFlyout.templates; - $(context).find('.cart-flyout').once('cart-block-render').each(function () { + $(once('cart-block-render', $(context).find('.cart-flyout'), context)).each(function () { Drupal.cartFlyout.createFlyout(); const model = new Drupal.cartFlyout.CartBlockModel( drupalSettings.cartFlyout @@ -85,4 +85,4 @@ }); } }; -})(jQuery, _, Drupal, drupalSettings); +})(jQuery, _, Drupal, once, drupalSettings); diff --git a/js/module.js b/js/module.js index 9a027d0..07038b6 100644 --- a/js/module.js +++ b/js/module.js @@ -5,7 +5,7 @@ * @preserve **/ -(function ($, _, Drupal, drupalSettings) { +(function ($, _, Drupal, once, drupalSettings) { var cache = {}; Drupal.cartFlyout = { templates: {}, @@ -71,7 +71,7 @@ Drupal.behaviors.cartFlyout = { attach: function attach(context) { Drupal.cartFlyout.templates = drupalSettings.cartFlyout.templates; - $(context).find('.cart-flyout').once('cart-block-render').each(function () { + $(once('cart-block-render', $(context).find('.cart-flyout'), context)).each(function () { Drupal.cartFlyout.createFlyout(); var model = new Drupal.cartFlyout.CartBlockModel(drupalSettings.cartFlyout); Drupal.cartFlyout.models.push(model); @@ -89,4 +89,4 @@ }); } }; -})(jQuery, _, Drupal, drupalSettings); \ No newline at end of file +})(jQuery, _, Drupal, once, drupalSettings); \ No newline at end of file diff --git a/src/Plugin/Block/CartBlock.php b/src/Plugin/Block/CartBlock.php index 9c1982d..75e2b5d 100644 --- a/src/Plugin/Block/CartBlock.php +++ b/src/Plugin/Block/CartBlock.php @@ -5,6 +5,7 @@ namespace Drupal\commerce_cart_flyout\Plugin\Block; use Drupal\Core\Access\AccessResult; use Drupal\Core\Block\BlockBase; use Drupal\Core\Cache\Cache; +use Drupal\Core\Extension\ExtensionList; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Render\Markup; @@ -12,8 +13,6 @@ use Drupal\Core\Render\RenderContext; use Drupal\Core\Render\RendererInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; -use Drupal\Core\Template\Loader\ThemeRegistryLoader; -use Drupal\Core\Theme\Registry; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -41,6 +40,14 @@ class CartBlock extends BlockBase implements ContainerFactoryPluginInterface { * @var \Drupal\Core\Render\RendererInterface */ protected $renderer; + /** + * The extension list service object. + * + * @var \Drupal\Core\Extension\ExtensionList + */ + + protected $extensionList; + /** * Constructs a new CartBlock object. @@ -55,11 +62,14 @@ class CartBlock extends BlockBase implements ContainerFactoryPluginInterface { * The route match. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer. + * * @param \Drupal\Core\Extension\ExtensionList $extensionList + * The extension list service object. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match, RendererInterface $renderer) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match, RendererInterface $renderer, ExtensionList $extensionList) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->routeMatch = $route_match; $this->renderer = $renderer; + $this->extensionList = $extensionList; } /** @@ -71,7 +81,8 @@ class CartBlock extends BlockBase implements ContainerFactoryPluginInterface { $plugin_id, $plugin_definition, $container->get('current_route_match'), - $container->get('renderer') + $container->get('renderer'), + $container->get('extension.list.module') ); } @@ -125,7 +136,7 @@ class CartBlock extends BlockBase implements ContainerFactoryPluginInterface { 'offcanvas_contents_items' => $this->renderTemplate('commerce_cart_flyout_offcanvas_contents_items'), ], 'url' => Url::fromRoute('commerce_cart.page')->toString(), - 'icon' => file_url_transform_relative(file_create_url(drupal_get_path('module', 'commerce') . '/icons/ffffff/cart.png')), + 'icon' => \Drupal::service('file_url_generator')->generateString(\Drupal::service('extension.list.module')->getPath('commerce') . '/icons/ffffff/cart.png'), ], ], ],