Issue #2418155 by jhedstrom, Berdir: options_field_views_data() excludes fields with an allowed_values_function for no reason
parent
35966bf27e
commit
5538c44ba6
|
|
@ -19,12 +19,6 @@ use Drupal\field\FieldStorageConfigInterface;
|
|||
function options_field_views_data(FieldStorageConfigInterface $field) {
|
||||
$data = views_field_default_views_data($field);
|
||||
|
||||
$function = $field->getSetting('allowed_values_function');
|
||||
// If this field makes use of dynamic allowed options, we ignore the views
|
||||
// setting.
|
||||
if (!empty($function)) {
|
||||
return $data;
|
||||
}
|
||||
foreach ($data as $table_name => $table_data) {
|
||||
foreach ($table_data as $field_name => $field_data) {
|
||||
if (isset($field_data['filter']) && $field_name != 'delta') {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\options\Tests\Views\ViewsDataTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\options\Tests\Views;
|
||||
|
||||
/**
|
||||
* Test to ensure views data is properly created for the Options module.
|
||||
*
|
||||
* @group views
|
||||
*/
|
||||
class ViewsDataTest extends OptionsTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['options', 'options_test', 'entity_test', 'views'];
|
||||
|
||||
/**
|
||||
* The field storage.
|
||||
*
|
||||
* @var \Drupal\Core\Field\FieldStorageDefinitionInterface
|
||||
*/
|
||||
protected $fieldStorage;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$field_name = 'test_options';
|
||||
$this->fieldStorage = entity_create('field_storage_config', [
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'list_string',
|
||||
'cardinality' => 1,
|
||||
'settings' => [
|
||||
'allowed_values_function' => 'options_test_dynamic_values_callback',
|
||||
],
|
||||
]);
|
||||
$this->fieldStorage->save();
|
||||
|
||||
$this->field = entity_create('field_config', [
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'bundle' => 'entity_test',
|
||||
'required' => TRUE,
|
||||
])->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the option module's implementation of hook_field_views_data().
|
||||
*/
|
||||
public function testOptionsFieldViewsData() {
|
||||
$field_data = \Drupal::service('views.views_data')->get('entity_test__test_options');
|
||||
|
||||
// Check that the options module has properly overridden default views data.
|
||||
$test_options_field = $field_data['test_options_value'];
|
||||
$this->assertEqual($test_options_field['argument']['id'], 'string_list_field', 'Argument handler is properly set for fields with allowed value callbacks.');
|
||||
$this->assertEqual($test_options_field['filter']['id'], 'list_field', 'Filter handler is properly set for fields with allowed value callbacks.');
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue