diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php index fe6669b..f0b9776 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php @@ -106,6 +106,7 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $ if (!$update) { entity_invoke_bundle_hook('create', 'taxonomy_term', $this->id()); + taxonomy_add_description_field($this, 'Description'); } elseif ($this->getOriginalID() != $this->id()) { // Reflect machine name changes in the definitions of existing 'taxonomy' diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index e05ec0d..68bed3b 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -1187,3 +1187,54 @@ function taxonomy_library_info() { return $libraries; } + +/** + * Adds the default description field to a taxonomy term type. + * + * @param \Drupal\taxonomy\VocabularyInterface $type + * A vocabulary type object. + * @param $label + * (Optional) The label for the description instance. + * @return + * A description field instance. + */ +function taxonomy_add_description_field(VocabularyInterface $type, $label = 'Description') { + // Add the description field as needed. + $field = field_info_field('taxonomy_term', 'description'); + $instance = field_info_instance('taxonomy_term', 'description', $type->id()); + + if (empty($field)) { + $field = entity_create('field_entity', array( + 'name' => 'description', + 'entity_type' => 'taxonomy_term', + 'type' => 'text_long', + )); + $field->save(); + } + if (empty($instance)) { + $instance = entity_create('field_instance', array( + 'field_name' => 'description', + 'entity_type' => 'taxonomy_term', + 'bundle' => $type->id(), + 'label' => $label, + 'settings' => array('text_processing' => 1), + )); + $instance->save(); + + entity_get_form_display('taxonomy_term', $type->id(), 'default') + ->setComponent('description', array( + 'type' => 'text_long', + )) + ->save(); + + // Assign display settings for the 'default' and 'teaser' view modes. + entity_get_display('taxonomy_term', $type->id(), 'default') + ->setComponent('description', array( + 'label' => 'hidden', + 'type' => 'text_default', + )) + ->save(); + } + + return $instance; +} \ No newline at end of file