class SupportsContentModerationAccessCheck in Scheduled Transitions 8
Same name and namespace in other branches
- 2.x src/Access/SupportsContentModerationAccessCheck.php \Drupal\scheduled_transitions\Access\SupportsContentModerationAccessCheck
Check if entity supports content moderation.
Supports revisions, has active workflow, etc.
Hierarchy
- class \Drupal\scheduled_transitions\Access\SupportsContentModerationAccessCheck implements AccessInterface
Expanded class hierarchy of SupportsContentModerationAccessCheck
1 file declares its use of SupportsContentModerationAccessCheck
1 string reference to 'SupportsContentModerationAccessCheck'
1 service uses SupportsContentModerationAccessCheck
File
- src/
Access/ SupportsContentModerationAccessCheck.php, line 25
Namespace
Drupal\scheduled_transitions\AccessView source
class SupportsContentModerationAccessCheck implements AccessInterface {
/**
* Value of 'applies_to' in service tag.
*/
public const ACCESS_CHECK_ID = '_scheduled_transitions_supports_content_moderation';
/**
* General service for moderation-related questions about Entity API.
*
* @var \Drupal\content_moderation\ModerationInformationInterface
*/
protected $moderationInformation;
/**
* Utilities for Scheduled Transitions module.
*
* @var \Drupal\scheduled_transitions\ScheduledTransitionsUtilityInterface
*/
protected $scheduledTransitionsUtility;
/**
* Constructs a new SupportsContentModerationAccessCheck.
*
* @param \Drupal\content_moderation\ModerationInformationInterface $moderationInformation
* General service for moderation-related questions about Entity API.
* @param \Drupal\scheduled_transitions\ScheduledTransitionsUtilityInterface $scheduledTransitionsUtility
* Utilities for Scheduled Transitions module.
*/
public function __construct(ModerationInformationInterface $moderationInformation, ScheduledTransitionsUtilityInterface $scheduledTransitionsUtility) {
$this->moderationInformation = $moderationInformation;
$this->scheduledTransitionsUtility = $scheduledTransitionsUtility;
}
/**
* Checks the entity supports content moderation.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
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.');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SupportsContentModerationAccessCheck:: |
protected | property | General service for moderation-related questions about Entity API. | |
SupportsContentModerationAccessCheck:: |
protected | property | Utilities for Scheduled Transitions module. | |
SupportsContentModerationAccessCheck:: |
public | function | Checks the entity supports content moderation. | |
SupportsContentModerationAccessCheck:: |
public | constant | Value of 'applies_to' in service tag. | |
SupportsContentModerationAccessCheck:: |
public | function | Constructs a new SupportsContentModerationAccessCheck. |