Commit f51b0290 authored by alexpott's avatar alexpott

Issue #2322457 by olli, adrian.ravis, andypost, pcambra: Error in Views Filter...

Issue #2322457 by olli, adrian.ravis, andypost, pcambra: Error in Views Filter Nodes based on Current user that have term reference same in nodes
parent 97220281
......@@ -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'));
......
......@@ -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');
}
/**
......
......@@ -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(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment