You are here

function taxonomy_term_depth_entity_update in Taxonomy Term Depth 8

Same name and namespace in other branches
  1. 8.2 taxonomy_term_depth.module \taxonomy_term_depth_entity_update()
  2. 7 taxonomy_term_depth.module \taxonomy_term_depth_entity_update()

Implements hook_entity_update();

1 call to taxonomy_term_depth_entity_update()
taxonomy_term_depth_entity_insert in ./taxonomy_term_depth.module
Implements hook_entity_insert()

File

./taxonomy_term_depth.module, line 47
Main module file.

Code

function taxonomy_term_depth_entity_update($entity) {

  // Update depth of the item on save
  if ($entity
    ->getEntityTypeId() == 'taxonomy_term') {

    /**
     * @var $entity \Drupal\taxonomy\Entity\Term
     */

    // Only update if depth was changed
    // @fixme: Uncomment this condition since v2.0

    //if (NULL === $entity->depth_level->first() || $entity->depth_level->first()->value != _taxonomy_term_depth_get_nocache($entity->id())) {
    $depth = taxonomy_term_depth_get_by_tid($entity
      ->id(), TRUE);
    $entity->depth_level
      ->setValue([
      'value' => $depth,
    ]);

    //}
  }
}