You are here

class FilterConditionsEventSubscriber in Commerce Core 8.2

Same name in this branch
  1. 8.2 modules/payment/src/EventSubscriber/FilterConditionsEventSubscriber.php \Drupal\commerce_payment\EventSubscriber\FilterConditionsEventSubscriber
  2. 8.2 modules/promotion/src/EventSubscriber/FilterConditionsEventSubscriber.php \Drupal\commerce_promotion\EventSubscriber\FilterConditionsEventSubscriber

Hierarchy

Expanded class hierarchy of FilterConditionsEventSubscriber

1 string reference to 'FilterConditionsEventSubscriber'
commerce_promotion.services.yml in modules/promotion/commerce_promotion.services.yml
modules/promotion/commerce_promotion.services.yml
1 service uses FilterConditionsEventSubscriber
commerce_promotion.filter_conditions_subscriber in modules/promotion/commerce_promotion.services.yml
Drupal\commerce_promotion\EventSubscriber\FilterConditionsEventSubscriber

File

modules/promotion/src/EventSubscriber/FilterConditionsEventSubscriber.php, line 8

Namespace

Drupal\commerce_promotion\EventSubscriber
View source
class FilterConditionsEventSubscriber implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events = [
      'commerce.filter_conditions' => 'onFilterConditions',
    ];
    return $events;
  }

  /**
   * Removes unneeded conditions.
   *
   * Promotions have store and order_types base fields that are used for
   * filtering, so there's no need to have conditions targeting the same data.
   *
   * @param \Drupal\commerce\Event\FilterConditionsEvent $event
   *   The event.
   */
  public function onFilterConditions(FilterConditionsEvent $event) {
    if ($event
      ->getParentEntityTypeId() == 'commerce_promotion') {
      $definitions = $event
        ->getDefinitions();
      unset($definitions['order_store']);
      unset($definitions['order_type']);
      $event
        ->setDefinitions($definitions);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FilterConditionsEventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
FilterConditionsEventSubscriber::onFilterConditions public function Removes unneeded conditions.