You are here

public function SchedulerManager::isAllowed in Scheduler 2.x

Same name and namespace in other branches
  1. 8 src/SchedulerManager.php \Drupal\scheduler\SchedulerManager::isAllowed()

Checks whether a scheduled process on an entity is allowed.

Other modules can prevent scheduled publishing or unpublishing by implementing any or all of the following: hook_scheduler_publishing_allowed() hook_scheduler_unpublishing_allowed() hook_scheduler_{type}_publishing_allowed() hook_scheduler_{type}_unpublishing_allowed()

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity on which the process is to be performed.

string $process: The process to be checked. Values are 'publish' or 'unpublish'.

Return value

bool TRUE if the process is allowed, FALSE if not.

2 calls to SchedulerManager::isAllowed()
SchedulerManager::publish in src/SchedulerManager.php
Publish scheduled entities.
SchedulerManager::unpublish in src/SchedulerManager.php
Unpublish scheduled entities.

File

src/SchedulerManager.php, line 624

Class

SchedulerManager
Defines a scheduler manager.

Namespace

Drupal\scheduler

Code

public function isAllowed(EntityInterface $entity, $process) {

  // Default to TRUE.
  $result = TRUE;

  // Get all implementations of the required hook function.
  $hook_implementations = $this
    ->getHookImplementations($process . 'ing_allowed', $entity);

  // Call the hook functions. If any specifically return FALSE the overall
  // result is FALSE. If a hook returns nothing it will not affect the result.
  foreach ($hook_implementations as $function) {
    $returned = $function($entity);
    $result &= !(isset($returned) && $returned == FALSE);
  }
  return $result;
}