ConfigEntityRevisionsAccessCheckBase.php in Config Entity Revisions 8.2
Namespace
Drupal\config_entity_revisionsFile
src/ConfigEntityRevisionsAccessCheckBase.phpView source
<?php
namespace Drupal\config_entity_revisions;
use Drupal\content_moderation\ModerationInformation;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\Routing\Route;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityManagerInterface;
/**
* Class ConfigEntityRevisionsAccessCheckBase.
*
* @package Drupal\config_entity_revisions
*/
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);
}
}
Classes
Name![]() |
Description |
---|---|
ConfigEntityRevisionsAccessCheckBase | Class ConfigEntityRevisionsAccessCheckBase. |