function Term::preSave

Same name in other branches
  1. 9 core/modules/taxonomy/src/Entity/Term.php \Drupal\taxonomy\Entity\Term::preSave()
  2. 8.9.x core/modules/taxonomy/src/Entity/Term.php \Drupal\taxonomy\Entity\Term::preSave()
  3. 10 core/modules/taxonomy/src/Entity/Term.php \Drupal\taxonomy\Entity\Term::preSave()

Overrides ContentEntityBase::preSave

File

core/modules/taxonomy/src/Entity/Term.php, line 124

Class

Term
Defines the taxonomy term entity.

Namespace

Drupal\taxonomy\Entity

Code

public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);
    // Terms with no parents are mandatory children of <root>.
    if (!$this->get('parent')
        ->count()) {
        $this->parent->target_id = 0;
    }
}

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