Chris@0: entityTypeManager()->getStorage('taxonomy_term')->getVocabularyHierarchyType($this->id()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function setHierarchy($hierarchy) { Chris@18: @trigger_error('\Drupal\taxonomy\VocabularyInterface::setHierarchy() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.x. Reset the cache of the taxonomy_term storage controller instead.', E_USER_DEPRECATED); Chris@18: $this->entityTypeManager()->getStorage('taxonomy_term')->resetCache(); Chris@0: return $this; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function id() { Chris@0: return $this->vid; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getDescription() { Chris@0: return $this->description; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function preDelete(EntityStorageInterface $storage, array $entities) { Chris@0: parent::preDelete($storage, $entities); Chris@0: Chris@0: // Only load terms without a parent, child terms will get deleted too. Chris@0: entity_delete_multiple('taxonomy_term', $storage->getToplevelTids(array_keys($entities))); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function postDelete(EntityStorageInterface $storage, array $entities) { Chris@0: parent::postDelete($storage, $entities); Chris@0: Chris@0: // Reset caches. Chris@0: $storage->resetCache(array_keys($entities)); Chris@0: Chris@0: if (reset($entities)->isSyncing()) { Chris@0: return; Chris@0: } Chris@0: Chris@0: $vocabularies = []; Chris@0: foreach ($entities as $vocabulary) { Chris@0: $vocabularies[$vocabulary->id()] = $vocabulary->id(); Chris@0: } Chris@0: // Load all Taxonomy module fields and delete those which use only this Chris@0: // vocabulary. Chris@0: $field_storages = entity_load_multiple_by_properties('field_storage_config', ['module' => 'taxonomy']); Chris@0: foreach ($field_storages as $field_storage) { Chris@0: $modified_storage = FALSE; Chris@0: // Term reference fields may reference terms from more than one Chris@0: // vocabulary. Chris@0: foreach ($field_storage->getSetting('allowed_values') as $key => $allowed_value) { Chris@0: if (isset($vocabularies[$allowed_value['vocabulary']])) { Chris@0: $allowed_values = $field_storage->getSetting('allowed_values'); Chris@0: unset($allowed_values[$key]); Chris@0: $field_storage->setSetting('allowed_values', $allowed_values); Chris@0: $modified_storage = TRUE; Chris@0: } Chris@0: } Chris@0: if ($modified_storage) { Chris@0: $allowed_values = $field_storage->getSetting('allowed_values'); Chris@0: if (empty($allowed_values)) { Chris@0: $field_storage->delete(); Chris@0: } Chris@0: else { Chris@0: // Update the field definition with the new allowed values. Chris@0: $field_storage->save(); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: }