You are here

class SupportsContentModerationAccessCheck in Scheduled Transitions 8

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

Check if entity supports content moderation.

Supports revisions, has active workflow, etc.

Hierarchy

Expanded class hierarchy of SupportsContentModerationAccessCheck

1 file declares its use of SupportsContentModerationAccessCheck
ScheduledTransitionsRouteProvider.php in src/Routing/ScheduledTransitionsRouteProvider.php
1 string reference to 'SupportsContentModerationAccessCheck'
scheduled_transitions.services.yml in ./scheduled_transitions.services.yml
scheduled_transitions.services.yml
1 service uses SupportsContentModerationAccessCheck
access_check.scheduled_transitions.supports_content_moderation in ./scheduled_transitions.services.yml
Drupal\scheduled_transitions\Access\SupportsContentModerationAccessCheck

File

src/Access/SupportsContentModerationAccessCheck.php, line 25

Namespace

Drupal\scheduled_transitions\Access
View 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

Namesort descending Modifiers Type Description Overrides
SupportsContentModerationAccessCheck::$moderationInformation protected property General service for moderation-related questions about Entity API.
SupportsContentModerationAccessCheck::$scheduledTransitionsUtility protected property Utilities for Scheduled Transitions module.
SupportsContentModerationAccessCheck::access public function Checks the entity supports content moderation.
SupportsContentModerationAccessCheck::ACCESS_CHECK_ID public constant Value of 'applies_to' in service tag.
SupportsContentModerationAccessCheck::__construct public function Constructs a new SupportsContentModerationAccessCheck.