diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php index 744fd34..167befa 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php @@ -130,10 +130,10 @@ public function validate(array $form, array &$form_state) { } /** - * Overrides Drupal\Core\Entity\EntityFormController::submit(). + * Overrides Drupal\Core\Entity\EntityFormController::buildEntity(). */ - public function submit(array $form, array &$form_state) { - $term = parent::submit($form, $form_state); + public function buildEntity(array $form, array &$form_state) { + $term = parent::buildEntity($form, $form_state); // Prevent leading and trailing spaces in term names. $term->name->value = trim($term->name->value); @@ -143,6 +143,9 @@ public function submit(array $form, array &$form_state) { $term->description->value = $description['value']; $term->format->value = $description['format']; + // Assign parents with proper delta values starting from 0. + $term->parent = array_keys($form_state['values']['parent']); + return $term; } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php index 26790c9..bea7976 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php @@ -79,11 +79,8 @@ protected function postDelete($entities) { */ protected function postSave(EntityInterface $entity, $update) { // Only change the parents if a value is set, keep the existing values if - // not. They are keyed by term id if set through the UI, so take the first - // value. - $parents = $entity->parent->getValue(); - $parent = reset($parents); - if (isset($parent['value'])) { + // not. + if (isset($entity->parent->value)) { db_delete('taxonomy_term_hierarchy') ->condition('tid', $entity->id()) ->execute();