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