abstract class ConfigEntityRevisionsAccessCheckBase in Config Entity Revisions 8.2
Class ConfigEntityRevisionsAccessCheckBase.
@package Drupal\config_entity_revisions
Hierarchy
- class \Drupal\config_entity_revisions\ConfigEntityRevisionsAccessCheckBase implements AccessInterface
Expanded class hierarchy of ConfigEntityRevisionsAccessCheckBase
1 file declares its use of ConfigEntityRevisionsAccessCheckBase
- ViewRevisionsAccessCheck.php in modules/
view_revisions/ src/ Access/ ViewRevisionsAccessCheck.php
File
- src/
ConfigEntityRevisionsAccessCheckBase.php, line 17
Namespace
Drupal\config_entity_revisionsView source
abstract class ConfigEntityRevisionsAccessCheckBase implements AccessInterface {
/**
* The view storage.
*
* @var \Drupal\view_revisions\ViewRevisionsStorage
*/
protected $configEntityStorage;
/**
* A static cache of access checks.
*
* @var array
*/
protected $access = [];
/**
* Constructs a new ViewRevisionsAccessCheck.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(EntityManagerInterface $entity_manager) {
$this->configEntityStorage = $entity_manager
->getStorage($this
->entityType());
}
/**
* Checks routing access for the entity's default revision.
*
* @param \Symfony\Component\Routing\Route $route
* The route to check against.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
* @param 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 \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigEntityRevisionsAccessCheckBase:: |
protected | property | A static cache of access checks. | |
ConfigEntityRevisionsAccessCheckBase:: |
protected | property | The view storage. | |
ConfigEntityRevisionsAccessCheckBase:: |
public | function | Checks routing access for the entity's default revision. | |
ConfigEntityRevisionsAccessCheckBase:: |
public | function | Constructs a new ViewRevisionsAccessCheck. |