protected function VocabularyStorageController::postSave

Overrides Drupal\Core\Config\Entity\ConfigStorageController::postSave().

Overrides ConfigStorageController::postSave

File

drupal/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php, line 21
Definition of Drupal\taxonomy\VocabularyStorageController.

Class

VocabularyStorageController
Defines a controller class for taxonomy vocabularies.

Namespace

Drupal\taxonomy

Code

protected function postSave(EntityInterface $entity, $update) {
  if (!$update) {
    entity_invoke_bundle_hook('create', 'taxonomy_term', $entity
      ->id());
  }
  elseif ($entity
    ->getOriginalID() != $entity
    ->id()) {

    // Reflect machine name changes in the definitions of existing 'taxonomy'
    // fields.
    $fields = field_read_fields();
    foreach ($fields as $field_name => $field) {
      $update_field = FALSE;
      if ($field['type'] == 'taxonomy_term_reference') {
        foreach ($field['settings']['allowed_values'] as $key => &$value) {
          if ($value['vocabulary'] == $entity
            ->getOriginalID()) {
            $value['vocabulary'] = $entity
              ->id();
            $update_field = TRUE;
          }
        }
        if ($update_field) {
          field_update_field($field);
        }
      }
    }

    // Update bundles.
    entity_invoke_bundle_hook('rename', 'taxonomy_term', $entity
      ->getOriginalID(), $entity
      ->id());
  }
  parent::postSave($entity, $update);
  $this
    ->resetCache($update ? array(
    $entity
      ->getOriginalID(),
  ) : array());
}