From 5538c44ba694f97a0981b28d56c8ea8d6f71eb8e Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 18 Mar 2015 16:20:43 +0000 Subject: [PATCH] Issue #2418155 by jhedstrom, Berdir: options_field_views_data() excludes fields with an allowed_values_function for no reason --- core/modules/options/options.views.inc | 6 -- .../options/src/Tests/Views/ViewsDataTest.php | 66 +++++++++++++++++++ 2 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 core/modules/options/src/Tests/Views/ViewsDataTest.php diff --git a/core/modules/options/options.views.inc b/core/modules/options/options.views.inc index 8eb35c28ab42..28ece79e88f9 100644 --- a/core/modules/options/options.views.inc +++ b/core/modules/options/options.views.inc @@ -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') { diff --git a/core/modules/options/src/Tests/Views/ViewsDataTest.php b/core/modules/options/src/Tests/Views/ViewsDataTest.php new file mode 100644 index 000000000000..b8773a0c17f7 --- /dev/null +++ b/core/modules/options/src/Tests/Views/ViewsDataTest.php @@ -0,0 +1,66 @@ +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.'); + } + +}