FieldCollectionItemAccessControlHandler.php in Field collection 8.3
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 {
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
$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;
}
}