d49c368f9453ba35e44bb947f3c6ef063b55e222
[yaffs-website] / web / modules / contrib / paragraphs / src / ParagraphAccessControlHandler.php
1 <?php
2
3 namespace Drupal\paragraphs;
4
5 use Drupal\Core\Entity\EntityAccessControlHandler;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Session\AccountInterface;
8 use Drupal\Core\Access\AccessResult;
9
10 /**
11  * Access controller for the paragraphs entity.
12  *
13  * @see \Drupal\paragraphs\Entity\Paragraph.
14  */
15 class ParagraphAccessControlHandler extends EntityAccessControlHandler {
16
17   /**
18    * {@inheritdoc}
19    */
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     if ($paragraph->getParentEntity() != NULL) {
24       // Delete permission on the paragraph, should just depend on 'update'
25       // access permissions on the parent.
26       $operation = ($operation == 'delete') ? 'update' : $operation;
27       $parent_access = $paragraph->getParentEntity()->access($operation, $account, TRUE);
28       return AccessResult::allowedIf($operation != 'view' || $paragraph->status->value)
29         ->andIf($parent_access);
30     }
31     return AccessResult::allowedIf($operation != 'view' || $paragraph->status->value);
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
38     // Allowed when nobody implements.
39     return AccessResult::allowed();
40   }
41
42 }