From 9b75b5807b9d43f9859ab5916fdadfd62b11a209 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Tue, 26 Jan 2021 08:41:56 +0000 Subject: [PATCH] Issue #3167733 by Spokje, vishnukumar, bkosborne, surya.s, kndr, alexpott: PHP 7.4 notice in views node wizard if a taxonomy field widget is hidden --- .../node/src/Plugin/views/wizard/Node.php | 2 +- ...enTaxonomyTermReferenceFieldWizardTest.php | 63 +++++++++++++++++++ .../{ => Wizard}/NodeRevisionWizardTest.php | 2 +- 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 core/modules/node/tests/src/Functional/Views/Wizard/HiddenTaxonomyTermReferenceFieldWizardTest.php rename core/modules/node/tests/src/Functional/Views/{ => Wizard}/NodeRevisionWizardTest.php (98%) diff --git a/core/modules/node/src/Plugin/views/wizard/Node.php b/core/modules/node/src/Plugin/views/wizard/Node.php index 4dbaf8815412..24615eed88bf 100644 --- a/core/modules/node/src/Plugin/views/wizard/Node.php +++ b/core/modules/node/src/Plugin/views/wizard/Node.php @@ -279,7 +279,7 @@ protected function buildFilters(&$form, FormStateInterface $form_state) { $widget = $display->getComponent($field_name); // We define "tag-like" taxonomy fields as ones that use the // "Autocomplete (Tags style)" widget. - if ($widget['type'] == 'entity_reference_autocomplete_tags') { + if (!empty($widget) && $widget['type'] == 'entity_reference_autocomplete_tags') { $tag_fields[$field_name] = $field; } } diff --git a/core/modules/node/tests/src/Functional/Views/Wizard/HiddenTaxonomyTermReferenceFieldWizardTest.php b/core/modules/node/tests/src/Functional/Views/Wizard/HiddenTaxonomyTermReferenceFieldWizardTest.php new file mode 100644 index 000000000000..11880f24f75f --- /dev/null +++ b/core/modules/node/tests/src/Functional/Views/Wizard/HiddenTaxonomyTermReferenceFieldWizardTest.php @@ -0,0 +1,63 @@ +<?php + +namespace Drupal\Tests\node\Functional\Views\Wizard; + +use Drupal\Core\Field\FieldStorageDefinitionInterface; +use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; +use Drupal\Tests\views\Functional\Wizard\WizardTestBase; + +/** + * Tests node wizard and content type with hidden Taxonomy Term Reference field. + * + * @group Views + * @group node + */ +class HiddenTaxonomyTermReferenceFieldWizardTest extends WizardTestBase { + + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'stark'; + + /** + * Modules to enable. + * + * @var array + */ + protected static $modules = ['taxonomy']; + + /** + * Tests content type with a hidden Taxonomy Term Reference field. + */ + public function testHiddenTaxonomyTermReferenceField() { + // Create Article node type. + $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']); + + // Create a taxonomy_term_reference field on the article Content Type. By + // not assigning a widget to that field we make sure it is hidden on the + // Form Display. + $this->fieldName = mb_strtolower($this->randomMachineName()); + FieldStorageConfig::create([ + 'field_name' => $this->fieldName, + 'entity_type' => 'node', + 'type' => 'entity_reference', + 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, + 'settings' => [ + 'target_type' => 'taxonomy_term', + ], + ])->save(); + FieldConfig::create([ + 'field_name' => $this->fieldName, + 'bundle' => 'article', + 'entity_type' => 'node', + 'settings' => [ + 'handler' => 'default', + ], + ])->save(); + + $this->drupalGet('admin/structure/views/add'); + $this->assertSession()->statusCodeEquals(200); + } + +} diff --git a/core/modules/node/tests/src/Functional/Views/NodeRevisionWizardTest.php b/core/modules/node/tests/src/Functional/Views/Wizard/NodeRevisionWizardTest.php similarity index 98% rename from core/modules/node/tests/src/Functional/Views/NodeRevisionWizardTest.php rename to core/modules/node/tests/src/Functional/Views/Wizard/NodeRevisionWizardTest.php index af149dfa570f..bfdb9a61e7af 100644 --- a/core/modules/node/tests/src/Functional/Views/NodeRevisionWizardTest.php +++ b/core/modules/node/tests/src/Functional/Views/Wizard/NodeRevisionWizardTest.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\Tests\node\Functional\Views; +namespace Drupal\Tests\node\Functional\Views\Wizard; use Drupal\Tests\views\Functional\Wizard\WizardTestBase; use Drupal\views\Views; -- GitLab