comparison core/modules/node/src/Access/NodeAddAccessCheck.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
1 <?php 1 <?php
2 2
3 namespace Drupal\node\Access; 3 namespace Drupal\node\Access;
4 4
5 use Drupal\Core\Access\AccessResult; 5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Entity\EntityManagerInterface; 6 use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
7 use Drupal\Core\Entity\EntityTypeManagerInterface;
7 use Drupal\Core\Routing\Access\AccessInterface; 8 use Drupal\Core\Routing\Access\AccessInterface;
8 use Drupal\Core\Session\AccountInterface; 9 use Drupal\Core\Session\AccountInterface;
9 use Drupal\node\NodeTypeInterface; 10 use Drupal\node\NodeTypeInterface;
10 11
11 /** 12 /**
12 * Determines access to for node add pages. 13 * Determines access to for node add pages.
13 * 14 *
14 * @ingroup node_access 15 * @ingroup node_access
15 */ 16 */
16 class NodeAddAccessCheck implements AccessInterface { 17 class NodeAddAccessCheck implements AccessInterface {
18 use DeprecatedServicePropertyTrait;
17 19
18 /** 20 /**
19 * The entity manager. 21 * {@inheritdoc}
22 */
23 protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
24
25 /**
26 * The entity type manager.
20 * 27 *
21 * @var \Drupal\Core\Entity\EntityManagerInterface 28 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
22 */ 29 */
23 protected $entityManager; 30 protected $entityTypeManager;
24 31
25 /** 32 /**
26 * Constructs a EntityCreateAccessCheck object. 33 * Constructs a EntityCreateAccessCheck object.
27 * 34 *
28 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager 35 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
29 * The entity manager. 36 * The entity type manager.
30 */ 37 */
31 public function __construct(EntityManagerInterface $entity_manager) { 38 public function __construct(EntityTypeManagerInterface $entity_type_manager) {
32 $this->entityManager = $entity_manager; 39 $this->entityTypeManager = $entity_type_manager;
33 } 40 }
34 41
35 /** 42 /**
36 * Checks access to the node add page for the node type. 43 * Checks access to the node add page for the node type.
37 * 44 *
43 * 50 *
44 * @return string 51 * @return string
45 * A \Drupal\Core\Access\AccessInterface constant value. 52 * A \Drupal\Core\Access\AccessInterface constant value.
46 */ 53 */
47 public function access(AccountInterface $account, NodeTypeInterface $node_type = NULL) { 54 public function access(AccountInterface $account, NodeTypeInterface $node_type = NULL) {
48 $access_control_handler = $this->entityManager->getAccessControlHandler('node'); 55 $access_control_handler = $this->entityTypeManager->getAccessControlHandler('node');
49 // If checking whether a node of a particular type may be created. 56 // If checking whether a node of a particular type may be created.
50 if ($account->hasPermission('administer content types')) { 57 if ($account->hasPermission('administer content types')) {
51 return AccessResult::allowed()->cachePerPermissions(); 58 return AccessResult::allowed()->cachePerPermissions();
52 } 59 }
53 if ($node_type) { 60 if ($node_type) {
54 return $access_control_handler->createAccess($node_type->id(), $account, [], TRUE); 61 return $access_control_handler->createAccess($node_type->id(), $account, [], TRUE);
55 } 62 }
56 // If checking whether a node of any type may be created. 63 // If checking whether a node of any type may be created.
57 foreach ($this->entityManager->getStorage('node_type')->loadMultiple() as $node_type) { 64 foreach ($this->entityTypeManager->getStorage('node_type')->loadMultiple() as $node_type) {
58 if (($access = $access_control_handler->createAccess($node_type->id(), $account, [], TRUE)) && $access->isAllowed()) { 65 if (($access = $access_control_handler->createAccess($node_type->id(), $account, [], TRUE)) && $access->isAllowed()) {
59 return $access; 66 return $access;
60 } 67 }
61 } 68 }
62 69