You are here

FieldCollectionItemAccessControlHandler.php in Field collection 8.3

Same filename and directory in other branches
  1. 8 src/FieldCollectionItemAccessControlHandler.php

File

src/FieldCollectionItemAccessControlHandler.php
View source
<?php

namespace Drupal\field_collection;

use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
class FieldCollectionItemAccessControlHandler extends EntityAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {

    /** @var \Drupal\field_collection\Entity\FieldCollectionItem $entity */
    $result = parent::checkAccess($entity, $operation, $account);
    if (!$result
      ->isForbidden()) {
      $host = $entity
        ->getHost();
      if (NULL !== $host && !empty(method_exists($host, 'access'))) {
        return $host
          ->access($operation, $account, TRUE);
      }
      elseif (!$entity
        ->isNew()) {
        throw new \RuntimeException($this
          ->t('Host entity for field collection item (@id) was not set.', [
          '@id' => $entity
            ->id(),
        ]));
      }
    }
    return $result;
  }

}