You are here

class FieldCollectionItemHostRevisionsOperationCheck in Field collection 8

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

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

Hierarchy

Expanded class hierarchy of FieldCollectionItemHostRevisionsOperationCheck

1 string reference to 'FieldCollectionItemHostRevisionsOperationCheck'
field_collection.services.yml in ./field_collection.services.yml
field_collection.services.yml
1 service uses FieldCollectionItemHostRevisionsOperationCheck
access_check.field_collection_item.host_revisions_operation in ./field_collection.services.yml
Drupal\field_collection\Access\FieldCollectionItemHostRevisionsOperationCheck

File

src/Access/FieldCollectionItemHostRevisionsOperationCheck.php, line 15

Namespace

Drupal\field_collection\Access
View source
class FieldCollectionItemHostRevisionsOperationCheck implements AccessInterface {

  /**
   * The permission handler.
   *
   * @var \Drupal\user\PermissionHandlerInterface
   */
  protected $permissionHandler;

  /**
   * The field collection item storage.
   *
   * @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage
   */
  protected $fieldCollectionItemStorage;

  /**
   * Constructs a new FieldCollectionItemHostRevisionsOperationCheck.
   *
   * @param \Drupal\user\PermissionHandlerInterface $permission_handler
   *   The permission handler.
   */
  public function __construct(PermissionHandlerInterface $permission_handler) {
    $this->permissionHandler = $permission_handler;
  }

  /**
   * Checks operation access on the field collection item's host's revisions.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in account.
   *
   * TODO: Document params
   *
   * @return string
   *   A \Drupal\Core\Access\AccessInterface constant value.
   */
  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();
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FieldCollectionItemHostRevisionsOperationCheck::$fieldCollectionItemStorage protected property The field collection item storage.
FieldCollectionItemHostRevisionsOperationCheck::$permissionHandler protected property The permission handler.
FieldCollectionItemHostRevisionsOperationCheck::access public function Checks operation access on the field collection item's host's revisions.
FieldCollectionItemHostRevisionsOperationCheck::__construct public function Constructs a new FieldCollectionItemHostRevisionsOperationCheck.