diff --git a/core/modules/views/src/Plugin/views/display/EntityReference.php b/core/modules/views/src/Plugin/views/display/EntityReference.php index 47c372bc37d0657be2944c184a9da319ecd26463..3cfce3e34b3a3d7e473d15672847c4f5f213eaae 100644 --- a/core/modules/views/src/Plugin/views/display/EntityReference.php +++ b/core/modules/views/src/Plugin/views/display/EntityReference.php @@ -155,7 +155,18 @@ public function query() { $id_table = $this->view->storage->get('base_table'); $this->id_field_alias = $this->view->query->addField($id_table, $id_field); - $options = $this->getOption('entity_reference_options'); + $options = $this->getOption('entity_reference_options') ?? []; + // The entity_reference_options are typically set during a call to + // Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection::initializeView(). + // If any entity_reference_options are not yet set, we apply the same + // default values that would typically be added by that method. + $default_options = [ + 'match' => NULL, + 'match_operator' => 'CONTAINS', + 'limit' => 0, + 'ids' => NULL, + ]; + $options += $default_options; // Restrict the autocomplete options based on what's been typed already. if (isset($options['match'])) { diff --git a/core/modules/views/tests/src/Functional/Plugin/DisplayEntityReferenceTest.php b/core/modules/views/tests/src/Functional/Plugin/DisplayEntityReferenceTest.php index ebacfc5c279442723b1b1853ad3addc760fa093a..f6639dce1ac29521999ff206c131545d2e360434 100644 --- a/core/modules/views/tests/src/Functional/Plugin/DisplayEntityReferenceTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayEntityReferenceTest.php @@ -275,6 +275,23 @@ public function testEntityReferenceDisplay() { $view->setDisplay('entity_reference_1'); $render = $view->display_handler->render(); $this->assertSame([], $render, 'Render returned empty array'); + + // Execute the View without setting the 'entity_reference_options'. + // This is equivalent to using the following as entity_reference_options. + // @code + // $options = [ + // 'match' => NULL, + // 'match_operator' => 'CONTAINS', + // 'limit' => 0, + // 'ids' => NULL, + // ]; + // @endcode + // Assert that this view returns a row for each test entity. + $view->destroy(); + $view = Views::getView('test_display_entity_reference'); + $view->setDisplay('entity_reference_1'); + $this->executeView($view); + $this->assertCount(13, $view->result, 'Search returned thirteen rows'); } }