You are here

public function TermSelection::validateReferenceableNewEntities in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php \Drupal\taxonomy\Plugin\EntityReferenceSelection\TermSelection::validateReferenceableNewEntities()
  2. 9 core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php \Drupal\taxonomy\Plugin\EntityReferenceSelection\TermSelection::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\EntityReferenceSelection

Code

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;
}