You are here

public function FieldCollectionItemHostRevisionsOperationCheck::access in Field collection 8

Same name and namespace in other branches
  1. 8.3 src/Access/FieldCollectionItemHostRevisionsOperationCheck.php \Drupal\field_collection\Access\FieldCollectionItemHostRevisionsOperationCheck::access()

Checks operation access on the field collection item's host's revisions.

Parameters

\Drupal\Core\Session\AccountInterface $account: The currently logged in account.

TODO: Document params

Return value

string A \Drupal\Core\Access\AccessInterface constant value.

File

src/Access/FieldCollectionItemHostRevisionsOperationCheck.php, line 52

Class

FieldCollectionItemHostRevisionsOperationCheck
Determines access to revision operations on the field collection item's host.

Namespace

Drupal\field_collection\Access

Code

public function access(Route $route, AccountInterface $account, $field_collection_item_revision = NULL, FieldCollectionItem $field_collection_item = NULL) {
  if ($field_collection_item_revision) {
    $field_collection_item = \Drupal::entityTypeManager()
      ->getStorage('field_collection_item')
      ->loadRevision($field_collection_item_revision);
  }
  $operation = $route
    ->getRequirement('_access_field_collection_item_host_revisions');
  $host = $field_collection_item
    ->getHost();
  if ($host
    ->getEntityType()
    ->id() == 'node') {
    return AccessResult::allowedIf($account
      ->hasPermission($operation . ' ' . $host
      ->getType() . ' revisions'));
  }
  else {
    if ($host
      ->getEntityType()
      ->id() == 'field_collection_item') {
      return $this
        ->access($route, $account, $host->revision_id, $host);
    }
    else {
      return AccessResult::allowedIf($field_collection_item && $field_collection_item
        ->getHost()
        ->access($operation, $account))
        ->cachePerPermissions();
    }
  }
}