diff --git a/core/modules/views/src/Plugin/views/HandlerBase.php b/core/modules/views/src/Plugin/views/HandlerBase.php index 5b66530..e277ac2 100644 --- a/core/modules/views/src/Plugin/views/HandlerBase.php +++ b/core/modules/views/src/Plugin/views/HandlerBase.php @@ -709,7 +709,9 @@ public function getEntityType() { // If the user has configured a relationship on the handler take that into // account. if (!empty($this->options['relationship']) && $this->options['relationship'] != 'none') { - $views_data = $this->getViewsData()->get($this->view->relationship->table); + $relationship = $this->displayHandler->getOption('relationships')[$this->options['relationship']]; + $table_data = $this->getViewsData()->get($relationship['table']); + $views_data = $this->getViewsData()->get($table_data[$relationship['field']]['relationship']['base']); } else { $views_data = $this->getViewsData()->get($this->view->storage->get('base_table')); diff --git a/core/modules/views/src/Tests/Handler/HandlerTest.php b/core/modules/views/src/Tests/Handler/HandlerTest.php index f5f81b5..f08acc2 100644 --- a/core/modules/views/src/Tests/Handler/HandlerTest.php +++ b/core/modules/views/src/Tests/Handler/HandlerTest.php @@ -7,6 +7,7 @@ namespace Drupal\views\Tests\Handler; +use Drupal\views\Entity\View; use Drupal\views\ViewExecutable; use Drupal\views\Tests\ViewTestBase; use Drupal\views\Plugin\views\HandlerBase; @@ -265,7 +266,20 @@ public function testRelationshipUI() { // Remove the relationship and make sure no relationship option appears. $this->drupalPostForm('admin/structure/views/nojs/handler/test_handler_relationships/default/relationship/nid', array(), t('Remove')); $this->drupalGet($handler_options_path); - $this->assertNoFieldByName($relationship_name, 'Make sure that no relationship option is available'); + $this->assertNoFieldByName($relationship_name, NULL, 'Make sure that no relationship option is available'); + + // Create a view of comments with node relationship. + View::create(['base_table' => 'comment', 'id' => 'test_get_entity_type'])->save(); + $this->drupalPostForm('admin/structure/views/nojs/add-handler/test_get_entity_type/default/relationship', ['name[comment_field_data.node]' => 'comment_field_data.node'], t('Add and configure relationships')); + $this->drupalPostForm(NULL, [], t('Apply')); + // Add a content type filter. + $this->drupalPostForm('admin/structure/views/nojs/add-handler/test_get_entity_type/default/filter', ['name[node_field_data.type]' => 'node_field_data.type'], t('Add and configure filter criteria')); + $this->assertOptionSelected('edit-options-relationship', 'node'); + $this->drupalPostForm(NULL, ['options[value][page]' => 'page'], t('Apply')); + // Check content type filter options. + $this->drupalGet('admin/structure/views/nojs/handler/test_get_entity_type/default/filter/type'); + $this->assertOptionSelected('edit-options-relationship', 'node'); + $this->assertFieldChecked('edit-options-value-page'); } /** diff --git a/core/modules/views_ui/src/Form/Ajax/ConfigHandler.php b/core/modules/views_ui/src/Form/Ajax/ConfigHandler.php index 3f0ee62..2e0e8c2 100644 --- a/core/modules/views_ui/src/Form/Ajax/ConfigHandler.php +++ b/core/modules/views_ui/src/Form/Ajax/ConfigHandler.php @@ -54,6 +54,7 @@ public function getFormId() { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) { + /** @var \Drupal\views\Entity\View $view */ $view = $form_state->get('view'); $display_id = $form_state->get('display_id'); $type = $form_state->get('type'); @@ -130,6 +131,9 @@ public function buildForm(array $form, FormStateInterface $form_state, Request $ // skips submitting the form. $executable->setHandlerOption($display_id, $type, $id, 'relationship', $rel); $save_ui_cache = TRUE; + // Re-initialize with new relationship. + $item['relationship'] = $rel; + $handler->init($executable, $executable->display_handler, $item); } $form['options']['relationship'] = array(