1. 8.5.x core/modules/node/src/Access/NodeAddAccessCheck.php NodeAddAccessCheck
  2. 8.0.x core/modules/node/src/Access/NodeAddAccessCheck.php NodeAddAccessCheck
  3. 8.1.x core/modules/node/src/Access/NodeAddAccessCheck.php NodeAddAccessCheck
  4. 8.2.x core/modules/node/src/Access/NodeAddAccessCheck.php NodeAddAccessCheck
  5. 8.3.x core/modules/node/src/Access/NodeAddAccessCheck.php NodeAddAccessCheck
  6. 8.4.x core/modules/node/src/Access/NodeAddAccessCheck.php NodeAddAccessCheck
  7. 8.6.x core/modules/node/src/Access/NodeAddAccessCheck.php NodeAddAccessCheck

Determines access to for node add pages.

Hierarchy

Expanded class hierarchy of NodeAddAccessCheck

Related topics

1 string reference to 'NodeAddAccessCheck'
node.services.yml in core/modules/node/node.services.yml
core/modules/node/node.services.yml
1 service uses NodeAddAccessCheck

File

core/modules/node/src/Access/NodeAddAccessCheck.php, line 16

Namespace

Drupal\node\Access
View source
class NodeAddAccessCheck implements AccessInterface {

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  protected $entityManager;

  /**
   * Constructs a EntityCreateAccessCheck object.
   *
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct(EntityManagerInterface $entity_manager) {
    $this->entityManager = $entity_manager;
  }

  /**
   * Checks access to the node add page for the node type.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in account.
   * @param \Drupal\node\NodeTypeInterface $node_type
   *   (optional) The node type. If not specified, access is allowed if there
   *   exists at least one node type for which the user may create a node.
   *
   * @return string
   *   A \Drupal\Core\Access\AccessInterface constant value.
   */
  public function access(AccountInterface $account, NodeTypeInterface $node_type = NULL) {
    $access_control_handler = $this->entityManager
      ->getAccessControlHandler('node');

    // If checking whether a node of a particular type may be created.
    if ($account
      ->hasPermission('administer content types')) {
      return AccessResult::allowed()
        ->cachePerPermissions();
    }
    if ($node_type) {
      return $access_control_handler
        ->createAccess($node_type
        ->id(), $account, [], TRUE);
    }

    // If checking whether a node of any type may be created.
    foreach ($this->entityManager
      ->getStorage('node_type')
      ->loadMultiple() as $node_type) {
      if (($access = $access_control_handler
        ->createAccess($node_type
        ->id(), $account, [], TRUE)) && $access
        ->isAllowed()) {
        return $access;
      }
    }

    // No opinion.
    return AccessResult::neutral();
  }

}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description Overrides
NodeAddAccessCheck::$entityManager protected property The entity manager.
NodeAddAccessCheck::access public function Checks access to the node add page for the node type.
NodeAddAccessCheck::__construct public function Constructs a EntityCreateAccessCheck object.