function TermSelection::validateReferenceableNewEntities

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

Overrides DefaultSelection::validateReferenceableNewEntities

File

core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php, line 130

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

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