3 namespace Drupal\paragraphs;
5 use Drupal\Core\Entity\EntityAccessControlHandler;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Session\AccountInterface;
8 use Drupal\Core\Access\AccessResult;
11 * Access controller for the paragraphs entity.
13 * @see \Drupal\paragraphs\Entity\Paragraph.
15 class ParagraphAccessControlHandler extends EntityAccessControlHandler {
20 protected function checkAccess(EntityInterface $paragraph, $operation, AccountInterface $account) {
21 // Allowed when the operation is not view or the status is true.
22 /** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
23 $access_result = AccessResult::allowedIf($operation != 'view' || $paragraph->status->value);
24 if ($paragraph->getParentEntity() != NULL) {
25 // Delete permission on the paragraph, should just depend on 'update'
26 // access permissions on the parent.
27 $operation = ($operation == 'delete') ? 'update' : $operation;
28 // Library items have no support for parent entity access checking.
29 if ($paragraph->getParentEntity()->getEntityTypeId() != 'paragraphs_library_item') {
30 $parent_access = $paragraph->getParentEntity()->access($operation, $account, TRUE);
31 $access_result = $access_result->andIf($parent_access);
34 return $access_result;
40 protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
41 // Allowed when nobody implements.
42 return AccessResult::allowed();