protected function TermStorageController::postSave

Overrides Drupal\Core\Entity\DatabaseStorageController::postSave().

Overrides DatabaseStorageController::postSave

File

drupal/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php, line 80
Definition of Drupal\taxonomy\TermStorageController.

Class

TermStorageController
Defines a Controller class for taxonomy terms.

Namespace

Drupal\taxonomy

Code

protected function postSave(EntityInterface $entity, $update) {

  // Only change the parents if a value is set, keep the existing values if
  // not.
  if (isset($entity->parent->value)) {
    db_delete('taxonomy_term_hierarchy')
      ->condition('tid', $entity
      ->id())
      ->execute();
    $query = db_insert('taxonomy_term_hierarchy')
      ->fields(array(
      'tid',
      'parent',
    ));
    foreach ($entity->parent as $parent) {
      $query
        ->values(array(
        'tid' => $entity
          ->id(),
        'parent' => (int) $parent->value,
      ));
    }
    $query
      ->execute();
  }
}