public function TermSelection::validateReferenceableNewEntities in Drupal 9
Same name and namespace in other branches
- 8 core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php \Drupal\taxonomy\Plugin\EntityReferenceSelection\TermSelection::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/ taxonomy/ src/ Plugin/ EntityReferenceSelection/ TermSelection.php, line 129
Class
- TermSelection
- Provides specific access control for the taxonomy_term entity type.
Namespace
Drupal\taxonomy\Plugin\EntityReferenceSelectionCode
public function validateReferenceableNewEntities(array $entities) {
$entities = parent::validateReferenceableNewEntities($entities);
// Mirror the conditions checked in buildEntityQuery().
if (!$this->currentUser
->hasPermission('administer taxonomy')) {
$entities = array_filter($entities, function ($term) {
/** @var \Drupal\taxonomy\TermInterface $term */
return $term
->isPublished();
});
}
return $entities;
}