function ContainerAwareEventDispatcher::removeListener

Same name in other branches
  1. 9 core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::removeListener()
  2. 8.9.x core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::removeListener()
  3. 10 core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::removeListener()
1 call to ContainerAwareEventDispatcher::removeListener()
ContainerAwareEventDispatcher::removeSubscriber in core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php

File

core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php, line 222

Class

ContainerAwareEventDispatcher
A performance optimized container aware event dispatcher.

Namespace

Drupal\Component\EventDispatcher

Code

public function removeListener($event_name, $listener) : void {
    if (!isset($this->listeners[$event_name])) {
        return;
    }
    foreach ($this->listeners[$event_name] as $priority => $definitions) {
        foreach ($definitions as $key => $definition) {
            if (!isset($definition['callable'])) {
                if (!$this->container
                    ->initialized($definition['service'][0])) {
                    continue;
                }
                $definition['callable'] = [
                    $this->container
                        ->get($definition['service'][0]),
                    $definition['service'][1],
                ];
            }
            if (is_array($definition['callable']) && isset($definition['callable'][0]) && $definition['callable'][0] instanceof \Closure && !$listener instanceof \Closure) {
                $definition['callable'][0] = $definition['callable'][0]();
            }
            if (is_array($definition['callable']) && isset($definition['callable'][0]) && !$definition['callable'][0] instanceof \Closure && is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
                $listener[0] = $listener[0]();
            }
            if ($definition['callable'] === $listener) {
                unset($definitions[$key]);
            }
        }
        if ($definitions) {
            $this->listeners[$event_name][$priority] = $definitions;
        }
        else {
            unset($this->listeners[$event_name][$priority]);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.