Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. LatestRevisionCheck.php

function LatestRevisionCheck::access

Checks that there is a pending revision available.

This checker assumes the presence of an '_entity_access' requirement key in the same form as used by EntityAccessCheck.

Parameters

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

\Drupal\Core\Routing\RouteMatchInterface $route_match: The parametrized route.

\Drupal\Core\Session\AccountInterface $account: The current user account.

Return value

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

See also

\Drupal\Core\Entity\EntityAccessCheck

File

core/modules/content_moderation/src/Access/LatestRevisionCheck.php, line 55

Class

LatestRevisionCheck
Access check for the entity moderation tab.

Namespace

Drupal\content_moderation\Access

Code

public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
    // This tab should not show up unless there's a reason to show it.
    $entity = $this->loadEntity($route, $route_match);
    if ($this->moderationInfo
        ->hasPendingRevision($entity)) {
        // Check the global permissions first.
        $access_result = AccessResult::allowedIfHasPermissions($account, [
            'view latest version',
            'view any unpublished content',
        ]);
        if (!$access_result->isAllowed()) {
            // Check entity owner access.
            $owner_access = AccessResult::allowedIfHasPermissions($account, [
                'view latest version',
                'view own unpublished content',
            ]);
            $owner_access = $owner_access->andIf(AccessResult::allowedIf($entity instanceof EntityOwnerInterface && $entity->getOwnerId() == $account->id()));
            $access_result = $access_result->orIf($owner_access);
        }
        return $access_result->addCacheableDependency($entity);
    }
    return AccessResult::forbidden('No pending revision for moderated entity.')->addCacheableDependency($entity);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal