Version 1
[yaffs-website] / web / core / modules / node / src / Access / NodePreviewAccessCheck.php
1 <?php
2
3 namespace Drupal\node\Access;
4
5 use Drupal\Core\Entity\EntityManagerInterface;
6 use Drupal\Core\Routing\Access\AccessInterface;
7 use Drupal\Core\Session\AccountInterface;
8 use Drupal\node\NodeInterface;
9
10 /**
11  * Determines access to node previews.
12  *
13  * @ingroup node_access
14  */
15 class NodePreviewAccessCheck implements AccessInterface {
16
17   /**
18    * The entity manager.
19    *
20    * @var \Drupal\Core\Entity\EntityManagerInterface
21    */
22   protected $entityManager;
23
24   /**
25    * Constructs a EntityCreateAccessCheck object.
26    *
27    * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
28    *   The entity manager.
29    */
30   public function __construct(EntityManagerInterface $entity_manager) {
31     $this->entityManager = $entity_manager;
32   }
33
34   /**
35    * Checks access to the node preview page.
36    *
37    * @param \Drupal\Core\Session\AccountInterface $account
38    *   The currently logged in account.
39    * @param \Drupal\node\NodeInterface $node_preview
40    *   The node that is being previewed.
41    *
42    * @return string
43    *   A \Drupal\Core\Access\AccessInterface constant value.
44    */
45   public function access(AccountInterface $account, NodeInterface $node_preview) {
46     if ($node_preview->isNew()) {
47       $access_controller = $this->entityManager->getAccessControlHandler('node');
48       return $access_controller->createAccess($node_preview->bundle(), $account, [], TRUE);
49     }
50     else {
51       return $node_preview->access('update', $account, TRUE);
52     }
53   }
54
55 }