diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index 82f8802..6dedb2d 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -86,6 +86,14 @@ public function form(array $form, array &$form_state, EntityInterface $node) { $tempstore_id = drupal_container()->get('request')->query->get('tempstore_id'); if (!empty($tempstore_id) && ($data = node_tempstore_load($tempstore_id))) { $node = $data; + + // Restore the destination if we previewed the node + if (isset($node->destination)) { + $form['node_destination'] = array( + '#type' => 'hidden', + '#value' => $node->destination, + ); + } } // Override the default CSS class name, since the user-defined node type @@ -391,6 +399,17 @@ public function submit(array $form, array &$form_state) { public function preview(array $form, array &$form_state) { $entity = $this->getEntity($form_state); $entity->in_preview = TRUE; + + // In case the destination parameter is set + if (isset($_GET['destination'])) { + $entity->destination = $_GET['destination']; + unset($_GET['destination']); + } + // In case we already previewed the node, but we want to preview it again. + elseif (isset($form_state['values']['node_destination'])) { + $entity->destination = $form_state['values']['node_destination']; + } + drupal_container()->get('user.tempstore')->get('node')->set($entity->tempstore_id, $entity); $form_state['redirect'] = 'node/preview/' . $entity->tempstore_id; } @@ -427,6 +446,11 @@ public function save(array $form, array &$form_state) { $form_state['rebuild'] = TRUE; } + // In case we visited the node preview, override the redirect. + if (isset($form_state['values']['node_destination'])) { + $form_state['redirect'] = $form_state['values']['node_destination']; + } + // Remove from tempstore. drupal_container()->get('user.tempstore')->get('node')->delete($node->tempstore_id); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php index a21f5b9..169481b 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php @@ -57,7 +57,7 @@ public function formElement(array $items, $delta, array $element, $langcode, arr $tags[] = $item; } else { - $tags[$item['tid']] = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : taxonomy_term_load($item['tid']); + $tags[$tid] = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : taxonomy_term_load($tid); } } $element += array( diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 6a40bdb..bad8286 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -950,7 +950,18 @@ function _taxonomy_get_tid_from_term(Term $term) { function taxonomy_implode_tags($tags, $vid = NULL) { $typed_tags = array(); foreach ($tags as $tag) { - if (is_array($tag) && $tag['tid'] == 'autocreate' && $label = $tag['name']) { + $label = ''; + if (is_array($tag) && $tag['tid'] == 'autocreate') { + $label = $tag['name']; + } + // Extract terms belonging to the vocabulary in question. + else if (!isset($vid) || $tag->bundle() == $vid) { + // Make sure we have a completed loaded taxonomy term. + if ($tag instanceof EntityInterface) { + $label = $tag->label(); + } + } + if (!empty($label)) { // Commas and quotes in tag names are special cases, so encode 'em. if (strpos($label, ',') !== FALSE || strpos($label, '"') !== FALSE) { $typed_tags[] = '"' . str_replace('"', '""', $label) . '"'; @@ -959,19 +970,6 @@ function taxonomy_implode_tags($tags, $vid = NULL) { $typed_tags[] = $label; } } - // Extract terms belonging to the vocabulary in question. - else if (!isset($vid) || $tag->bundle() == $vid) { - // Make sure we have a completed loaded taxonomy term. - if ($tag instanceof EntityInterface && $label = $tag->label()) { - // Commas and quotes in tag names are special cases, so encode 'em. - if (strpos($label, ',') !== FALSE || strpos($label, '"') !== FALSE) { - $typed_tags[] = '"' . str_replace('"', '""', $label) . '"'; - } - else { - $typed_tags[] = $label; - } - } - } } return implode(', ', $typed_tags); }