1. 8.2.x core/modules/taxonomy/src/Plugin/migrate/source/d6/Vocabulary.php
  2. 8.2.x core/modules/taxonomy/src/Entity/Vocabulary.php
  3. 8.2.x core/modules/taxonomy/src/Plugin/migrate/source/d7/Vocabulary.php
  4. 8.0.x core/modules/taxonomy/src/Entity/Vocabulary.php
  5. 8.0.x core/modules/taxonomy/src/Plugin/migrate/source/d6/Vocabulary.php
  6. 8.0.x core/modules/taxonomy/src/Plugin/migrate/source/d7/Vocabulary.php
  7. 8.1.x core/modules/taxonomy/src/Plugin/migrate/source/d7/Vocabulary.php
  8. 8.1.x core/modules/taxonomy/src/Plugin/migrate/source/d6/Vocabulary.php
  9. 8.1.x core/modules/taxonomy/src/Entity/Vocabulary.php
  10. 8.3.x core/modules/taxonomy/src/Plugin/migrate/source/d7/Vocabulary.php
  11. 8.3.x core/modules/taxonomy/src/Entity/Vocabulary.php
  12. 8.3.x core/modules/taxonomy/src/Plugin/migrate/source/d6/Vocabulary.php

Namespace

Drupal\taxonomy\Entity

File

core/modules/taxonomy/src/Entity/Vocabulary.php
View source
  1. <?php
  2. namespace Drupal\taxonomy\Entity;
  3. use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
  4. use Drupal\Core\Entity\EntityStorageInterface;
  5. use Drupal\taxonomy\VocabularyInterface;
  6. /**
  7. * Defines the taxonomy vocabulary entity.
  8. *
  9. * @ConfigEntityType(
  10. * id = "taxonomy_vocabulary",
  11. * label = @Translation("Taxonomy vocabulary"),
  12. * handlers = {
  13. * "storage" = "Drupal\taxonomy\VocabularyStorage",
  14. * "list_builder" = "Drupal\taxonomy\VocabularyListBuilder",
  15. * "form" = {
  16. * "default" = "Drupal\taxonomy\VocabularyForm",
  17. * "reset" = "Drupal\taxonomy\Form\VocabularyResetForm",
  18. * "delete" = "Drupal\taxonomy\Form\VocabularyDeleteForm"
  19. * }
  20. * },
  21. * admin_permission = "administer taxonomy",
  22. * config_prefix = "vocabulary",
  23. * bundle_of = "taxonomy_term",
  24. * entity_keys = {
  25. * "id" = "vid",
  26. * "label" = "name",
  27. * "weight" = "weight"
  28. * },
  29. * links = {
  30. * "add-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/add",
  31. * "delete-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/delete",
  32. * "reset-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/reset",
  33. * "overview-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/overview",
  34. * "edit-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}",
  35. * "collection" = "/admin/structure/taxonomy",
  36. * },
  37. * config_export = {
  38. * "name",
  39. * "vid",
  40. * "description",
  41. * "hierarchy",
  42. * "weight",
  43. * }
  44. * )
  45. */
  46. class Vocabulary extends ConfigEntityBundleBase implements VocabularyInterface {
  47. /**
  48. * The taxonomy vocabulary ID.
  49. *
  50. * @var string
  51. */
  52. protected $vid;
  53. /**
  54. * Name of the vocabulary.
  55. *
  56. * @var string
  57. */
  58. protected $name;
  59. /**
  60. * Description of the vocabulary.
  61. *
  62. * @var string
  63. */
  64. protected $description;
  65. /**
  66. * The type of hierarchy allowed within the vocabulary.
  67. *
  68. * Possible values:
  69. * - VocabularyInterface::HIERARCHY_DISABLED: No parents.
  70. * - VocabularyInterface::HIERARCHY_SINGLE: Single parent.
  71. * - VocabularyInterface::HIERARCHY_MULTIPL: Multiple parents.
  72. *
  73. * @var int
  74. */
  75. protected $hierarchy = VocabularyInterface::HIERARCHY_DISABLED;
  76. /**
  77. * The weight of this vocabulary in relation to other vocabularies.
  78. *
  79. * @var int
  80. */
  81. protected $weight = 0;
  82. /**
  83. * {@inheritdoc}
  84. */
  85. public function getHierarchy() {
  86. return $this->hierarchy;
  87. }
  88. /**
  89. * {@inheritdoc}
  90. */
  91. public function setHierarchy($hierarchy) {
  92. $this->hierarchy = $hierarchy;
  93. return $this;
  94. }
  95. /**
  96. * {@inheritdoc}
  97. */
  98. public function id() {
  99. return $this->vid;
  100. }
  101. /**
  102. * {@inheritdoc}
  103. */
  104. public function getDescription() {
  105. return $this->description;
  106. }
  107. /**
  108. * {@inheritdoc}
  109. */
  110. public static function preDelete(EntityStorageInterface $storage, array $entities) {
  111. parent::preDelete($storage, $entities);
  112. // Only load terms without a parent, child terms will get deleted too.
  113. entity_delete_multiple('taxonomy_term', $storage->getToplevelTids(array_keys($entities)));
  114. }
  115. /**
  116. * {@inheritdoc}
  117. */
  118. public static function postDelete(EntityStorageInterface $storage, array $entities) {
  119. parent::postDelete($storage, $entities);
  120. // Reset caches.
  121. $storage->resetCache(array_keys($entities));
  122. if (reset($entities)->isSyncing()) {
  123. return;
  124. }
  125. $vocabularies = array();
  126. foreach ($entities as $vocabulary) {
  127. $vocabularies[$vocabulary->id()] = $vocabulary->id();
  128. }
  129. // Load all Taxonomy module fields and delete those which use only this
  130. // vocabulary.
  131. $field_storages = entity_load_multiple_by_properties('field_storage_config', array('module' => 'taxonomy'));
  132. foreach ($field_storages as $field_storage) {
  133. $modified_storage = FALSE;
  134. // Term reference fields may reference terms from more than one
  135. // vocabulary.
  136. foreach ($field_storage->getSetting('allowed_values') as $key => $allowed_value) {
  137. if (isset($vocabularies[$allowed_value['vocabulary']])) {
  138. $allowed_values = $field_storage->getSetting('allowed_values');
  139. unset($allowed_values[$key]);
  140. $field_storage->setSetting('allowed_values', $allowed_values);
  141. $modified_storage = TRUE;
  142. }
  143. }
  144. if ($modified_storage) {
  145. $allowed_values = $field_storage->getSetting('allowed_values');
  146. if (empty($allowed_values)) {
  147. $field_storage->delete();
  148. }
  149. else {
  150. // Update the field definition with the new allowed values.
  151. $field_storage->save();
  152. }
  153. }
  154. }
  155. }
  156. }

Classes

Namesort descending Description
Vocabulary Defines the taxonomy vocabulary entity.