function NodeSelection::validateReferenceableNewEntities

Same name in other branches
  1. 8.9.x core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php \Drupal\node\Plugin\EntityReferenceSelection\NodeSelection::validateReferenceableNewEntities()
  2. 10 core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php \Drupal\node\Plugin\EntityReferenceSelection\NodeSelection::validateReferenceableNewEntities()
  3. 11.x core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php \Drupal\node\Plugin\EntityReferenceSelection\NodeSelection::validateReferenceableNewEntities()

Overrides DefaultSelection::validateReferenceableNewEntities

File

core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php, line 53

Class

NodeSelection
Provides specific access control for the node entity type.

Namespace

Drupal\node\Plugin\EntityReferenceSelection

Code

public function validateReferenceableNewEntities(array $entities) {
    $entities = parent::validateReferenceableNewEntities($entities);
    // Mirror the conditions checked in buildEntityQuery().
    if (!$this->currentUser
        ->hasPermission('bypass node access') && !$this->moduleHandler
        ->hasImplementations('node_grants')) {
        $entities = array_filter($entities, function ($node) {
            
            /** @var \Drupal\node\NodeInterface $node */
            return $node->isPublished();
        });
    }
    return $entities;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.