You are here

public function ConfigEntityRevisionsAccessCheckBase::access in Config Entity Revisions 8.2

Checks routing access for the entity's default revision.

Parameters

\Symfony\Component\Routing\Route $route: The route to check against.

\Drupal\Core\Session\AccountInterface $account: The currently logged in account.

string $entity_id: (optional) An entity. Used for checking access to the entity's default revision when $revision is unspecified. Ignored when $revision is specified. If neither $revision nor $entity are specified, then access is denied.

Return value

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

File

src/ConfigEntityRevisionsAccessCheckBase.php, line 59

Class

ConfigEntityRevisionsAccessCheckBase
Class ConfigEntityRevisionsAccessCheckBase.

Namespace

Drupal\config_entity_revisions

Code

public function access(Route $route, AccountInterface $account = NULL, $entity_id = '') {

  // Neutral doesn't mean "Ignore me". See
  // https://www.drupal.org/project/drupal/issues/2991698.
  if (!$entity_id) {
    return AccessResult::allowed();
  }
  $entity = $this->configEntityStorage
    ->load($entity_id);
  if (!$entity) {
    return AccessResult::allowed();
  }

  // These are config entities - no published field to worry about.
  $published = TRUE;
  $settings = $entity
    ->getContentEntityId();
  if (is_null($settings)) {
    return AccessResult::allowed();
  }
  $content_moderation = \Drupal::moduleHandler()
    ->moduleExists('content_moderation');
  if ($content_moderation) {
    $moderationInformation = new ModerationInformation(\Drupal::entityTypeManager(), \Drupal::service('entity_type.bundle.info'));
    $contentEntity = $entity
      ->getContentEntity();
    if ($contentEntity) {
      $published = $moderationInformation
        ->isDefaultRevisionPublished($contentEntity);
    }
  }
  return AccessResult::allowedIf($entity && ($published || $this
    ->administerCheck($account) || $account
    ->hasPermission('view any unpublished content')))
    ->cachePerPermissions()
    ->addCacheableDependency($entity);
}