diff --git a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php index 28b04cde58a99deecf63ae0a1a82560747847be6..ed93b253f90ad5a435d5495c75093ec16fee3580 100644 --- a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php @@ -68,7 +68,8 @@ function setUp() { 'parent' => '0', ), ), - ) + ), + 'cardinality' => '-1', ); field_create_field($this->field); @@ -77,7 +78,7 @@ function setUp() { 'entity_type' => 'node', 'bundle' => 'page', 'widget' => array( - 'type' => 'options_select', + 'type' => 'taxonomy_autocomplete', ), // Hide on full display but render on teaser. 'display' => array( @@ -90,6 +91,9 @@ function setUp() { ), ); field_create_instance($this->instance); + entity_get_display('node', 'page', 'default') + ->setComponent($this->field_name) + ->save(); } /** @@ -105,7 +109,7 @@ function testPagePreview() { $edit = array(); $edit[$title_key] = $this->randomName(8); $edit[$body_key] = $this->randomName(16); - $edit[$term_key] = $this->term->id(); + $edit[$term_key] = $this->term->label(); $this->drupalPost('node/add/page', $edit, t('Preview')); // Check that the preview is displaying the title, body and term. @@ -119,6 +123,49 @@ function testPagePreview() { $this->assertFieldByName($title_key, $edit[$title_key], 'Title field displayed.'); $this->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.'); $this->assertFieldByName($term_key, $edit[$term_key], 'Term field displayed.'); + + // Save the node. + $this->drupalPost('node/add/page', $edit, t('Save')); + $node = $this->drupalGetNodeByTitle($edit[$title_key]); + + // Check the term was displayed on the saved node. + $this->drupalGet('node/' . $node->nid); + $this->assertText($edit[$term_key], 'Term displayed.'); + + // Check the term appears again on the edit form. + $this->drupalGet('node/' . $node->nid . '/edit'); + $this->assertFieldByName($term_key, $edit[$term_key], 'Term field displayed.'); + + // Check with two new terms on the edit form, additionally to the existing + // one. + $edit = array(); + $newterm1 = $this->randomName(8); + $newterm2 = $this->randomName(8); + $edit[$term_key] = $this->term->label() . ', ' . $newterm1 . ', ' . $newterm2; + $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Preview')); + $this->assertRaw('>' . $newterm1 . '<', 'First new term displayed.'); + $this->assertRaw('>' . $newterm2 . '<', 'Second new term displayed.'); + // The first term should be displayed as link, the others not. + $this->assertLink($this->term->label()); + $this->assertNoLink($newterm1); + $this->assertNoLink($newterm2); + + $this->drupalPost('node/add/page', $edit, t('Save')); + + // Check with one more new term, keeping old terms, removing the existing + // one. + $edit = array(); + $newterm3 = $this->randomName(8); + $edit[$term_key] = $newterm1 . ', ' . $newterm3 . ', ' . $newterm2; + $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Preview')); + $this->assertRaw('>' . $newterm1 . '<', 'First existing term displayed.'); + $this->assertRaw('>' . $newterm2 . '<', 'Second existing term displayed.'); + $this->assertRaw('>' . $newterm3 . '<', 'Third new term displayed.'); + $this->assertNoText($this->term->label()); + $this->assertNoLink($newterm1); + $this->assertNoLink($newterm2); + $this->assertNoLink($newterm3); + $this->drupalPost('node/add/page', $edit, t('Save')); } /** diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/EntityReferenceTaxonomyTermRssFormatter.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/EntityReferenceTaxonomyTermRssFormatter.php index a21a7ce22c338b30a04510029038117aa45b355a..c4cb3cf30404750323893a60d215ee75a848a3ff 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/EntityReferenceTaxonomyTermRssFormatter.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/EntityReferenceTaxonomyTermRssFormatter.php @@ -38,9 +38,9 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { foreach ($items as $delta => $item) { $entity->rss_elements[] = array( 'key' => 'category', - 'value' => $item['target_id'] != 'autocreate' ? $item['entity']->label() : $item['label'], + 'value' => $item['entity']->label(), 'attributes' => array( - 'domain' => $item['target_id'] != 'autocreate' ? url('taxonomy/term/' . $item['target_id'], array('absolute' => TRUE)) : '', + 'domain' => $item['target_id'] ? url('taxonomy/term/' . $item['target_id'], array('absolute' => TRUE)) : '', ), ); } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/LinkFormatter.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/LinkFormatter.php index 10d566ea8a1dd7bcd44a742bf23c37bfcb9ad4f5..7f92a88f53e6c79314dcbd498e0459a8048803d4 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/LinkFormatter.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/LinkFormatter.php @@ -33,12 +33,11 @@ class LinkFormatter extends TaxonomyFormatterBase { public function viewElements(EntityInterface $entity, $langcode, array $items) { $elements = array(); - // Terms whose tid is 'autocreate' do not exist yet and $item['entity'] is - // not set. Theme such terms as just their name. + // Terms without tid do not exist yet, theme such terms as just their name. foreach ($items as $delta => $item) { - if ($item['tid'] == 'autocreate') { + if (!$item['tid']) { $elements[$delta] = array( - '#markup' => check_plain($item['name']), + '#markup' => check_plain($item['entity']->label()), ); } else { diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/PlainFormatter.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/PlainFormatter.php index 33eeffcc585fc1a9995e3aa8951e3f77f02a9816..7e61c9cee4d9bf2d20dbd92257506ae80bb253ca 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/PlainFormatter.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/PlainFormatter.php @@ -33,12 +33,9 @@ class PlainFormatter extends TaxonomyFormatterBase { public function viewElements(EntityInterface $entity, $langcode, array $items) { $elements = array(); - // Terms whose tid is 'autocreate' do not exist yet and $item['entity'] is - // not set. Theme such terms as just their name. foreach ($items as $delta => $item) { - $name = ($item['tid'] != 'autocreate' ? $item['entity']->label() : $item['name']); $elements[$delta] = array( - '#markup' => check_plain($name), + '#markup' => check_plain($item['entity']->label()), ); } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/RSSCategoryFormatter.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/RSSCategoryFormatter.php index 7b7e6e44b17bd45a7213bcb852dddec1f3e5274e..5a96d537e2e5c0572e0d3848c782ba3e38c78e2e 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/RSSCategoryFormatter.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/RSSCategoryFormatter.php @@ -34,7 +34,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { // Terms whose tid is 'autocreate' do not exist yet and $item['entity'] is // not set. Theme such terms as just their name. foreach ($items as $item) { - if ($item['tid'] != 'autocreate') { + if ($item['tid']) { $value = $item['entity']->label(); $uri = $item['entity']->uri(); @@ -42,7 +42,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { $domain = url($uri['path'], $uri['options']); } else { - $value = $item['name']; + $value = $item['entity']->label(); $domain = ''; } $entity->rss_elements[] = array( diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/TaxonomyFormatterBase.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/TaxonomyFormatterBase.php index e743350b5e32898b86bfbb54019b6ee6a279b5c4..f5071375618c5302959d0ad1116c95f9236f9783 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/TaxonomyFormatterBase.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/TaxonomyFormatterBase.php @@ -30,7 +30,7 @@ public function prepareView(array $entities, $langcode, array &$items) { foreach ($entities as $id => $entity) { foreach ($items[$id] as $delta => $item) { // Force the array key to prevent duplicates. - if ($item['tid'] != 'autocreate' && $item['tid'] !== FALSE) { + if ($item['tid'] !== FALSE) { $tids[$item['tid']] = $item['tid']; } } @@ -51,7 +51,7 @@ public function prepareView(array $entities, $langcode, array &$items) { $items[$id][$delta]['entity'] = $terms[$item['tid']]; } // Terms to be created are not in $terms, but are still legitimate. - elseif ($item['tid'] == 'autocreate') { + elseif ($item['tid'] === FALSE && isset($item['entity'])) { // Leave the item in place. } // Otherwise, unset the instance value, since the term does not exist. 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 9624d43361b57548f916625545081dee8e519c2f..7ceb3509536634ded5910fc12ccee22eaf65c92a 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 @@ -86,7 +86,7 @@ public function massageFormValues(array $values, array $form, array &$form_state // Translate term names into actual terms. foreach($values as $value) { // See if the term exists in the chosen vocabulary and return the tid; - // otherwise, create a new 'autocreate' term for insert/update. + // otherwise, create a new term. if ($possibilities = entity_load_multiple_by_properties('taxonomy_term', array('name' => trim($value), 'vid' => array_keys($vocabularies)))) { $term = array_pop($possibilities); $item = array('tid' => $term->id());