Commit d38bf13d authored by catch's avatar catch

Issue #2469553 by Lendude, geertvd, oenie: Views filtering on boolean fields...

Issue #2469553 by Lendude, geertvd, oenie: Views filtering on boolean fields doesn't use right formatter
parent 8e4fe5c0
......@@ -7,6 +7,8 @@
namespace Drupal\field\Tests\Views;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\views\Views;
/**
......@@ -112,4 +114,32 @@ public function testHandlerUIAggregation() {
$this->assertEqual($options, array('format', 'value'), 'The expected sort field options were found.');
}
/**
* Tests adding a boolean field filter handler.
*/
public function testBooleanFilterHandler() {
// Create a boolean field.
$field_name = 'field_boolean';
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'node',
'type' => 'boolean',
]);
$field_storage->save();
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'page',
]);
$field->save();
$url = "admin/structure/views/nojs/add-handler/test_view_fieldapi/default/filter";
$this->drupalPostForm($url, ['name[node__' . $field_name . '.' . $field_name . '_value]' => TRUE], t('Add and configure @handler', array('@handler' => t('filter criteria'))));
$this->assertResponse(200);
// Verify that using a boolean field as a filter also results in using the
// boolean plugin.
$option = $this->xpath('//label[@for="edit-options-value-1"]');
$this->assertEqual(t('True'), (string) $option[0]);
$option = $this->xpath('//label[@for="edit-options-value-0"]');
$this->assertEqual(t('False'), (string) $option[0]);
}
}
......@@ -501,6 +501,9 @@ function views_field_default_views_data(FieldStorageConfigInterface $field_stora
$filter = 'numeric';
$argument = 'numeric';
$sort = 'standard';
if ($field_storage->getType() == 'boolean') {
$filter = 'boolean';
}
break;
case 'text':
case 'blob':
......
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