From a6658cdd8299b2b8d0faa8852dcb7819267476f0 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Sat, 29 Mar 2014 17:59:43 +0100 Subject: [PATCH] Issue #2193237 by czigor, amateescu, barraponto, revagomes, rodrigo panchiniak fernandes: Warning because of empty value at array_flip(). --- .../FieldWidget/TaxonomyAutocompleteWidget.php | 6 ++++-- .../lib/Drupal/taxonomy/Tests/TermFieldTest.php | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldWidget/TaxonomyAutocompleteWidget.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldWidget/TaxonomyAutocompleteWidget.php index 4d7fe8f1150..ae156a48d54 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldWidget/TaxonomyAutocompleteWidget.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldWidget/TaxonomyAutocompleteWidget.php @@ -71,8 +71,10 @@ class TaxonomyAutocompleteWidget extends WidgetBase { */ public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, array &$form_state) { $tags = array(); - foreach ($items as $item) { - $tags[] = isset($item->entity) ? $item->entity : entity_load('taxonomy_term', $item->target_id); + if (!$items->isEmpty()) { + foreach ($items as $item) { + $tags[] = isset($item->entity) ? $item->entity : entity_load('taxonomy_term', $item->target_id); + } } $element += array( '#type' => 'textfield', diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php index 237f9db4dae..1dd0aab8c9d 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php @@ -17,7 +17,7 @@ class TermFieldTest extends TaxonomyTestBase { * * @var array */ - public static $modules = array('entity_test'); + public static $modules = array('entity_test', 'field_ui'); protected $instance; protected $vocabulary; @@ -37,6 +37,7 @@ class TermFieldTest extends TaxonomyTestBase { 'view test entity', 'administer entity_test content', 'administer taxonomy', + 'administer entity_test fields', )); $this->drupalLogin($web_user); $this->vocabulary = $this->createVocabulary(); @@ -128,6 +129,20 @@ class TermFieldTest extends TaxonomyTestBase { $this->assertNoFieldByName($this->field_name, '', 'Widget is not displayed.'); } + /** + * No php error message on the field setting page for autocomplete widget. + */ + function testTaxonomyTermFieldInstanceSettingsAutocompleteWidget() { + entity_get_form_display('entity_test', 'entity_test', 'default') + ->setComponent($this->field_name, array( + 'type' => 'taxonomy_autocomplete', + 'weight' => 1, + )) + ->save(); + $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $this->field_name); + $this->assertNoErrorsLogged(); + } + /** * Tests that vocabulary machine name changes are mirrored in field definitions. */