Verified Commit 0b548bb6 authored by Jess's avatar Jess
Browse files

Issue #3180227 by danflanagan8, robertom, xjm, Lendude, quietone: Notice:...

Issue #3180227 by danflanagan8, robertom, xjm, Lendude, quietone: Notice: Trying to access array offset on value of type null in Drupal\views\Plugin\views\display\EntityReference->query()

(cherry picked from commit 0f6101a7)
parent 43004a38
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -160,7 +160,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'])) {
+17 −0
Original line number Diff line number Diff line
@@ -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');
  }

}