diff --git a/README.md b/README.md index 7257bf4..afa33c6 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ CONTENTS OF THIS FILE INTRODUCTION ------------ -Commerce Promo Bar allows stores to display notifications and promotional information -via the bar on top pages or any positions. +Commerce Promo Bar allows stores to display notifications and promotional +information via the bar on top pages or any positions. REQUIREMENTS @@ -33,7 +33,8 @@ CONFIGURATION 1. Navigate to Administration > Extend and enable the Commerce Promo Bar module. 2. Navigate to Home > Administration > Structure > Block layout and - place Commerce Promo Bar block onto region where you want to show promo bars. + place Commerce Promo Bar block onto region where you want to show + promo bars. (if you want to show only one promobar always - uncheck Stack promo bars) 3. Navigate to Home > Administration > Commerce > Configuration > Promo Bar. if you want to add fields, or change display & form view modes. diff --git a/commerce_promo_bar.info.yml b/commerce_promo_bar.info.yml index 28c0555..576f189 100644 --- a/commerce_promo_bar.info.yml +++ b/commerce_promo_bar.info.yml @@ -8,4 +8,3 @@ dependencies: - commerce:commerce_promotion - drupal:options - color_field:color_field - diff --git a/commerce_promo_bar.module b/commerce_promo_bar.module index 5003978..716448c 100644 --- a/commerce_promo_bar.module +++ b/commerce_promo_bar.module @@ -35,13 +35,14 @@ function commerce_promo_bar_theme() { * * @param array $variables * An associative array containing: - * - elements: An associative array containing the commerce promo bar information and any - * fields attached to the entity. + * - elements: An associative array + * It contains the commerce promo bar information and + * any fields attached to the entity. * - attributes: HTML attributes for the containing element. */ function template_preprocess_commerce_promo_bar(array &$variables) { $variables['view_mode'] = $variables['elements']['#view_mode']; - /** @var PromoBarInterface $commerce_promo_bar */ + /** @var \Drupal\commerce_promo_bar\Entity\PromoBarInterface $commerce_promo_bar */ $commerce_promo_bar = $variables['elements']['#commerce_promo_bar']; $variables['promo_bar_entity'] = $commerce_promo_bar; $variables['promo_bar'] = []; @@ -64,7 +65,7 @@ function commerce_promo_bar_preprocess_field(&$variables, $hook) { $delta = 0; while (!empty($element[$delta])) { $variables['items'][$delta]['content']['#text'] = $token_service->replace($variables['items'][$delta]['content']['#text'], [ - 'commerce_promo_bar' => $element['#object'] + 'commerce_promo_bar' => $element['#object'], ]); $delta++; } diff --git a/css/promo_bar.form.css b/css/promo_bar.form.css index 42b501d..464896e 100644 --- a/css/promo_bar.form.css +++ b/css/promo_bar.form.css @@ -19,8 +19,8 @@ /* Wide screens */ @media - screen and (min-width: 780px), - (orientation: landscape) and (min-device-height: 780px) { +screen and (min-width: 780px), +(orientation: landscape) and (min-device-height: 780px) { .layout-region-promo_bar-main, .layout-region-promo_bar-footer { @@ -54,7 +54,7 @@ * toolbar width (240px). In this case, 240px + 780px. */ @media - screen and (max-width: 1020px) { +screen and (max-width: 1020px) { .toolbar-vertical.toolbar-tray-open .layout-region-promo_bar-main, .toolbar-vertical.toolbar-tray-open .layout-region-promo_bar-footer, diff --git a/src/Event/PromoBarEvents.php b/src/Event/PromoBarEvents.php index 74dd39e..14c694a 100644 --- a/src/Event/PromoBarEvents.php +++ b/src/Event/PromoBarEvents.php @@ -2,6 +2,9 @@ namespace Drupal\commerce_promo_bar\Event; +/** + * Implements class PromoBarEvents. + */ final class PromoBarEvents { /** diff --git a/src/Plugin/Block/PromoBarBlock.php b/src/Plugin/Block/PromoBarBlock.php index b451b06..51ed53b 100644 --- a/src/Plugin/Block/PromoBarBlock.php +++ b/src/Plugin/Block/PromoBarBlock.php @@ -12,6 +12,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Session\AccountProxyInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Component\Datetime\TimeInterface; /** * Provides a 'Promo bar block'. @@ -51,6 +52,13 @@ class PromoBarBlock extends BlockBase implements ContainerFactoryPluginInterface */ protected $promoBarStorage; + /** + * The time service. + * + * @var \Drupal\Component\Datetime\TimeInterface + */ + protected $time; + /** * Construct. * @@ -66,18 +74,22 @@ class PromoBarBlock extends BlockBase implements ContainerFactoryPluginInterface * The current store. * @param \Drupal\Core\Session\AccountProxyInterface $current_user * The current user. + * @param \Drupal\Component\Datetime\TimeInterface $time + * The time service. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, - EntityTypeManagerInterface $entity_type_manager, + EntityTypeManagerInterface $entity_type_manager, CurrentStoreInterface $current_store, - AccountProxyInterface $current_user) { + AccountProxyInterface $current_user, + TimeInterface $time) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityTypeManager = $entity_type_manager; $this->currentStore = $current_store; $this->currentUser = $current_user; $this->promoBarStorage = $entity_type_manager->getStorage('commerce_promo_bar'); + $this->time = $time; } /** @@ -90,7 +102,8 @@ class PromoBarBlock extends BlockBase implements ContainerFactoryPluginInterface $plugin_definition, $container->get('entity_type.manager'), $container->get('commerce_store.current_store'), - $container->get('current_user') + $container->get('current_user'), + $container->get('datetime.time'), ); } @@ -131,7 +144,7 @@ class PromoBarBlock extends BlockBase implements ContainerFactoryPluginInterface $promo_bars = $this->promoBarStorage->loadAvailable($this->currentStore->getStore(), $this->currentUser->getRoles()); $timezone = $this->currentStore->getStore()->getTimezone(); - $timestamp = \Drupal::time()->getRequestTime(); + $timestamp = $this->time->getRequestTime(); $date = DrupalDateTime::createFromTimestamp($timestamp, $timezone); $js_settings = []; foreach ($promo_bars as $promo_bar) { diff --git a/templates/commerce-promo-bar.html.twig b/templates/commerce-promo-bar.html.twig index 862500e..95f72cc 100644 --- a/templates/commerce-promo-bar.html.twig +++ b/templates/commerce-promo-bar.html.twig @@ -34,4 +34,3 @@ {% endif %} -