function TermSelection::createNewEntity

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

Overrides DefaultSelection::createNewEntity

File

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

Class

TermSelection
Provides specific access control for the taxonomy_term entity type.

Namespace

Drupal\taxonomy\Plugin\EntityReferenceSelection

Code

public function createNewEntity($entity_type_id, $bundle, $label, $uid) {
    $term = parent::createNewEntity($entity_type_id, $bundle, $label, $uid);
    // In order to create a referenceable term, it needs to published.
    
    /** @var \Drupal\taxonomy\TermInterface $term */
    $term->setPublished();
    return $term;
}

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