You are here

class CartEventSubscriber in Commerce Cart Flyout 8

Replaces the original CartEventSubscriber from commerce_cart module.

This prevents `_cart_api` routes from triggering messages.

Hierarchy

Expanded class hierarchy of CartEventSubscriber

1 file declares its use of CartEventSubscriber
CommerceCartFlyoutServiceProvider.php in src/CommerceCartFlyoutServiceProvider.php

File

src/EventSubscriber/CartEventSubscriber.php, line 17

Namespace

Drupal\commerce_cart_flyout\EventSubscriber
View source
class CartEventSubscriber extends CommerceCartEventSubscriber {

  /**
   * The route match.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $routeMatch;

  /**
   * Constructs a new CartEventSubscriber object.
   *
   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
   *   The messenger.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The string translation.
   */
  public function __construct(MessengerInterface $messenger, TranslationInterface $string_translation, RouteMatchInterface $route_match) {
    parent::__construct($messenger, $string_translation);
    $this->routeMatch = $route_match;
  }

  /**
   * {@inheritdoc}
   */
  public function displayAddToCartMessage(CartEntityAddEvent $event) {
    if (!$this->routeMatch
      ->getRouteObject()
      ->hasRequirement('_cart_api')) {
      parent::displayAddToCartMessage($event);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CartEventSubscriber::$messenger protected property The messenger.
CartEventSubscriber::$routeMatch protected property The route match.
CartEventSubscriber::displayAddToCartMessage public function Displays an add to cart message. Overrides CartEventSubscriber::displayAddToCartMessage
CartEventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
CartEventSubscriber::__construct public function Constructs a new CartEventSubscriber object. Overrides CartEventSubscriber::__construct
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.