Commit db72d228 authored by alexpott's avatar alexpott

Issue #2370251 by Lendude, jhedstrom: Removed fields in Views Combined Filter...

Issue #2370251 by Lendude, jhedstrom: Removed fields in Views Combined Filter setting lead to Fatal error
parent 28123e2a
......@@ -61,6 +61,14 @@ public function query() {
$fields = array();
// Only add the fields if they have a proper field and table alias.
foreach ($this->options['fields'] as $id) {
// Overridden fields can lead to fields missing from a display that are
// still set in the non-overridden combined filter.
if (!isset($this->view->field[$id])) {
// If fields are no longer available that are needed to filter by, make
// sure no results are shown to prevent displaying more then intended.
$this->view->build_info['fail'] = TRUE;
continue;
}
$field = $this->view->field[$id];
// Always add the table of the selected fields to be sure a table alias exists.
$field->ensureMyTable();
......@@ -87,6 +95,23 @@ public function query() {
}
}
/**
* {@inheritdoc}
*/
public function validate() {
$errors = parent::validate();
$fields = $this->view->display_handler->getHandlers('field');
foreach ($this->options['fields'] as $id) {
if (!isset($fields[$id])) {
// Combined field filter only works with fields that are in the field
// settings.
$errors[] = $this->t('Field %field set in %filter is not set in this display.', array('%field' => $id, '%filter' => $this->adminLabel()));
break;
}
}
return $errors;
}
// By default things like opEqual uses add_where, that doesn't support
// complex expressions, so override all operators.
......
......@@ -81,6 +81,54 @@ public function testFilterCombineContains() {
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
}
/**
* Tests if the filter can handle removed fields.
*
* Tests the combined filter handler when a field overwrite is done
* and fields set in the combine filter are removed from the display
* but not from the combined filter settings.
*/
public function testFilterCombineContainsFieldsOverwritten() {
$view = Views::getView('test_view');
$view->setDisplay();
$fields = $view->displayHandlers->get('default')->getOption('fields');
$view->displayHandlers->get('default')->overrideOption('fields', $fields + array(
'job' => array(
'id' => 'job',
'table' => 'views_test_data',
'field' => 'job',
'relationship' => 'none',
),
));
// Change the filtering.
$view->displayHandlers->get('default')->overrideOption('filters', array(
'age' => array(
'id' => 'combine',
'table' => 'views',
'field' => 'combine',
'relationship' => 'none',
'operator' => 'contains',
'fields' => array(
'name',
'job',
// Add a dummy field to the combined fields to simulate
// a removed or deleted field.
'dummy',
),
'value' => 'ing',
),
));
$this->executeView($view);
// Make sure this view will not get displayed.
$this->assertTrue($view->build_info['fail'], "View build has been marked as failed.");
// Make sure this view does not pass validation with the right error.
$errors = $view->validate();
$this->assertEqual(reset($errors['default']), t('Field %field set in %filter is not set in this display.', array('%field' => 'dummy', '%filter' => 'Global: Combine fields filter')));
}
/**
* Additional data to test the NULL issue.
*/
......
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