class FirstOrLast
Moves one listener to the start or end of the list.
@internal
Hierarchy
- class \Drupal\Core\Hook\OrderOperation\OrderOperation
- class \Drupal\Core\Hook\OrderOperation\FirstOrLast extends \Drupal\Core\Hook\OrderOperation\OrderOperation
Expanded class hierarchy of FirstOrLast
File
-
core/
lib/ Drupal/ Core/ Hook/ OrderOperation/ FirstOrLast.php, line 12
Namespace
Drupal\Core\Hook\OrderOperationView source
class FirstOrLast extends OrderOperation {
/**
* Constructor.
*
* @param string $identifier
* Identifier of the implementation to move to a new position. The format
* is the class followed by "::" then the method name. For example,
* "Drupal\my_module\Hook\MyModuleHooks::methodName".
* @param bool $isLast
* TRUE to move to the end, FALSE to move to the start.
*/
public function __construct(string $identifier, bool $isLast) {
}
/**
* {@inheritdoc}
*/
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);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
FirstOrLast::apply | public | function | Changes the order of a list of hook implementations. | Overrides OrderOperation::apply |
FirstOrLast::__construct | public | function | Constructor. | |
OrderOperation::pack | final public | function | Converts the operation to a structure that can be stored in the container. | |
OrderOperation::unpack | final public static | function | Converts the stored operation to objects that can apply ordering rules. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.