You are here

public function LazySubscriber::onInitClear in Feeds 8.3

Adds clear plugins as event listeners.

File

src/EventSubscriber/LazySubscriber.php, line 138

Class

LazySubscriber
Event listener that registers Feeds plugins as event listeners.

Namespace

Drupal\feeds\EventSubscriber

Code

public function onInitClear(InitEvent $event, $event_name, EventDispatcherInterface $dispatcher) {
  if ($this->clearInited === TRUE) {
    return;
  }
  $this->clearInited = TRUE;
  foreach ($event
    ->getFeed()
    ->getType()
    ->getPlugins() as $plugin) {
    if (!$plugin instanceof ClearableInterface) {
      continue;
    }
    $dispatcher
      ->addListener(FeedsEvents::CLEAR, function (ClearEvent $event) use ($plugin) {
      $feed = $event
        ->getFeed();
      $plugin
        ->clear($feed, $feed
        ->getState(StateInterface::CLEAR));
    });
  }
}