function FirstOrLast::apply

Overrides OrderOperation::apply

File

core/lib/Drupal/Core/Hook/OrderOperation/FirstOrLast.php, line 32

Class

FirstOrLast
Moves one listener to the start or end of the list.

Namespace

Drupal\Core\Hook\OrderOperation

Code

public function apply(array &$identifiers, array $module_finder) : void {
    $index = array_search($this->identifier, $identifiers);
    if ($index === FALSE) {
        // The element does not exist.
        return;
    }
    unset($identifiers[$index]);
    if ($this->isLast) {
        $identifiers[] = $this->identifier;
    }
    else {
        $identifiers = [
            $this->identifier,
            $identifiers,
        ];
    }
    $identifiers = array_values($identifiers);
}

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