public function SchedulerManager::getHookImplementations in Scheduler 2.x
Returns an array of hook function names implemented for a hook type.
The return array will include all implementations of the general hook function called for all entity types, plus all implemented hooks for the specific type of entity being processed. In addition, for node entities, the original hook functions (prior to entity plugins) are added to maintain backwards-compatibility.
Parameters
string $hookType: The identifier of the hook function, for example 'publish_process' or 'unpublishing_allowed' or 'hide_publish_date'.
\Drupal\Core\Entity\EntityInterface|string $entity: The entity object which is being processed, or a string containing the entity type id (for example 'node' or 'media').
Return value
array An array of callable function names for the implementations of this hook function for the type of entity being processed.
4 calls to SchedulerManager::getHookImplementations()
- SchedulerManager::isAllowed in src/
SchedulerManager.php - Checks whether a scheduled process on an entity is allowed.
- SchedulerManager::publish in src/
SchedulerManager.php - Publish scheduled entities.
- SchedulerManager::throwSchedulerException in src/
SchedulerManager.php - Handles throwing exceptions.
- SchedulerManager::unpublish in src/
SchedulerManager.php - Unpublish scheduled entities.
File
- src/
SchedulerManager.php, line 660
Class
- SchedulerManager
- Defines a scheduler manager.
Namespace
Drupal\schedulerCode
public function getHookImplementations(string $hookType, $entity) {
$entityTypeId = is_object($entity) ? $entity
->getEntityTypeid() : $entity;
$hooks = [
$hookType,
"{$entityTypeId}_{$hookType}",
];
// For backwards compatibility the original node hook is also added.
if ($entityTypeId == 'node') {
$legacy_node_hooks = [
'hide_publish_date' => 'hide_publish_on_field',
'hide_unpublish_date' => 'hide_unpublish_on_field',
'list' => 'nid_list',
'list_alter' => 'nid_list_alter',
'publish_process' => 'publish_action',
'unpublish_process' => 'unpublish_action',
'publishing_allowed' => 'allow_publishing',
'unpublishing_allowed' => 'allow_unpublishing',
];
$hooks[] = $legacy_node_hooks[$hookType];
}
// Get all modules that implement these hooks, then use array_walk to append
// the $hook to the end of the module, thus giving the full function name.
$all_hook_implementations = [];
foreach ($hooks as $hook) {
$hook = "scheduler_{$hook}";
$implementations = $this->moduleHandler
->getImplementations($hook);
array_walk($implementations, function (&$item) use ($hook) {
$item = $item . '_' . $hook;
});
$all_hook_implementations = array_merge($all_hook_implementations, $implementations);
}
return $all_hook_implementations;
}