Skip to content
Snippets Groups Projects
Commit 575cf36e authored by catch's avatar catch
Browse files

Issue #2652538 by Lendude, dawehner, matslats, alexpott: views Combine filter validation

parent 9b650e91
No related branches found
No related tags found
No related merge requests found
......@@ -99,22 +99,27 @@ public function query() {
*/
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;
}
elseif (!$fields[$id]->clickSortable()) {
// Combined field filter only works with simple fields. If the field is
// not click sortable we can assume it is not a simple field.
// @todo change this check to isComputed. See
// https://www.drupal.org/node/2349465
$errors[] = $this->t('Field %field set in %filter is not usable for this filter type. Combined field filter only works for simple fields.', array('%field' => $fields[$id]->adminLabel(), '%filter' => $this->adminLabel()));
if ($this->displayHandler->usesFields()) {
$fields = $this->displayHandler->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 display %display.', array('%field' => $id, '%filter' => $this->adminLabel(), '%display' => $this->displayHandler->display['display_title']));
break;
}
elseif (!$fields[$id]->clickSortable()) {
// Combined field filter only works with simple fields. If the field
// is not click sortable we can assume it is not a simple field.
// @todo change this check to isComputed. See
// https://www.drupal.org/node/2349465
$errors[] = $this->t('Field %field set in %filter is not usable for this filter type. Combined field filter only works for simple fields.', array('%field' => $fields[$id]->adminLabel(), '%filter' => $this->adminLabel()));
}
}
}
else {
$errors[] = $this->t('%display: %filter can only be used on displays that use fields. Set the style or row format for that display to one using fields to use the combine field filter.', array('%display' => $this->displayHandler->display['display_title'], '%filter' => $this->adminLabel()));
}
return $errors;
}
......
......@@ -12,12 +12,17 @@
*/
class FilterCombineTest extends ViewsKernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('entity_test');
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view');
public static $testViews = array('test_view', 'entity_test_fields');
/**
* Map column names.
......@@ -29,6 +34,15 @@ class FilterCombineTest extends ViewsKernelTestBase {
'views_test_data_job' => 'job',
);
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->installEntitySchema('entity_test');
}
public function testFilterCombineContains() {
$view = Views::getView('test_view');
$view->setDisplay();
......@@ -126,7 +140,42 @@ public function testFilterCombineContainsFieldsOverwritten() {
$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')));
$this->assertEquals(t('Field %field set in %filter is not set in display %display.', array('%field' => 'dummy', '%filter' => 'Global: Combine fields filter', '%display' => 'Master')), reset($errors['default']));
}
/**
* Tests that the combine field filter is not valid on displays that don't use
* fields.
*/
public function testNonFieldsRow() {
$view = Views::getView('entity_test_fields');
$view->setDisplay();
// Set the rows to a plugin type that doesn't support fields.
$view->displayHandlers->get('default')->overrideOption('row', array(
'type' => 'entity:entity_test',
'options' => array(
'view_mode' => 'teaser',
),
));
// Change the filtering.
$view->displayHandlers->get('default')->overrideOption('filters', array(
'name' => array(
'id' => 'combine',
'table' => 'views',
'field' => 'combine',
'relationship' => 'none',
'operator' => 'contains',
'fields' => array(
'name',
),
'value' => 'ing',
),
));
$this->executeView($view);
$errors = $view->validate();
// Check that the right error is shown.
$this->assertEquals(t('%display: %filter can only be used on displays that use fields. Set the style or row format for that display to one using fields to use the combine field filter.', array('%filter' => 'Global: Combine fields filter', '%display' => 'Master')), reset($errors['default']));
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment