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