You are here

public function SupportsContentModerationAccessCheck::access in Scheduled Transitions 8

Same name and namespace in other branches
  1. 2.x src/Access/SupportsContentModerationAccessCheck.php \Drupal\scheduled_transitions\Access\SupportsContentModerationAccessCheck::access()

Checks the entity supports content moderation.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

File

src/Access/SupportsContentModerationAccessCheck.php, line 65

Class

SupportsContentModerationAccessCheck
Check if entity supports content moderation.

Namespace

Drupal\scheduled_transitions\Access

Code

public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) : AccessResultInterface {

  /** @var string $routeEntityType */
  $routeEntityTypeId = $route
    ->getOption(ScheduledTransitionsRouteProvider::ROUTE_ENTITY_TYPE);
  $entity = $route_match
    ->getParameter($routeEntityTypeId);
  if ($entity instanceof ContentEntityInterface) {
    $access = (new CacheableMetadata())
      ->addCacheableDependency($entity)
      ->addCacheTags([
      SettingsForm::SETTINGS_TAG,
    ]);
    $enabledBundles = $this->scheduledTransitionsUtility
      ->getBundles();
    if (in_array($entity
      ->bundle(), $enabledBundles[$entity
      ->getEntityTypeId()] ?? [], TRUE) && $this->moderationInformation
      ->isModeratedEntity($entity)) {
      return AccessResult::allowed()
        ->addCacheableDependency($access);
    }
    return AccessResult::forbidden('Scheduled transitions not supported on this entity.')
      ->addCacheableDependency($access);
  }
  return AccessResult::forbidden('No entity provided.');
}