public function NodeSelection::validateReferenceableNewEntities in Drupal 8
Same name and namespace in other branches
- 9 core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php \Drupal\node\Plugin\EntityReferenceSelection\NodeSelection::validateReferenceableNewEntities()
- 10 core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php \Drupal\node\Plugin\EntityReferenceSelection\NodeSelection::validateReferenceableNewEntities()
Validates which newly created entities can be referenced.
This method should replicate the logic implemented by \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface::validateReferenceableEntities(), but applied to newly created entities that have not been saved yet.
Parameters
\Drupal\Core\Entity\EntityInterface[] $entities: An array of entities to check.
Return value
\Drupal\Core\Entity\EntityInterface[] The incoming $entities parameter, filtered for valid entities. Array keys are preserved.
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\EntityReferenceSelectionCode
public function validateReferenceableNewEntities(array $entities) {
$entities = parent::validateReferenceableNewEntities($entities);
// Mirror the conditions checked in buildEntityQuery().
if (!$this->currentUser
->hasPermission('bypass node access') && !count($this->moduleHandler
->getImplementations('node_grants'))) {
$entities = array_filter($entities, function ($node) {
/** @var \Drupal\node\NodeInterface $node */
return $node
->isPublished();
});
}
return $entities;
}