NodeSelection.php in Drupal 9
File
core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php
View source
<?php
namespace Drupal\node\Plugin\EntityReferenceSelection;
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
use Drupal\node\NodeInterface;
class NodeSelection extends DefaultSelection {
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
if (!$this->currentUser
->hasPermission('bypass node access') && !count($this->moduleHandler
->getImplementations('node_grants'))) {
$query
->condition('status', NodeInterface::PUBLISHED);
}
return $query;
}
public function createNewEntity($entity_type_id, $bundle, $label, $uid) {
$node = parent::createNewEntity($entity_type_id, $bundle, $label, $uid);
$node
->setPublished();
return $node;
}
public function validateReferenceableNewEntities(array $entities) {
$entities = parent::validateReferenceableNewEntities($entities);
if (!$this->currentUser
->hasPermission('bypass node access') && !count($this->moduleHandler
->getImplementations('node_grants'))) {
$entities = array_filter($entities, function ($node) {
return $node
->isPublished();
});
}
return $entities;
}
}
Classes
Name |
Description |
NodeSelection |
Provides specific access control for the node entity type. |