summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-01-26 13:11:30 (GMT)
committerAlex Pott2015-01-26 13:11:30 (GMT)
commit6ab60f77c3ef1d5d29fd39897c7af2a4cf0bd0cc (patch)
tree1f5a1421f2175252070d31c6a22320039eedb42b
parentfcb679d878a8302fe227b9ff6165563b6696f88e (diff)
Issue #2012130 by smiletrl, dawehner, damiankloip, larowlan, webflo, pcambra, dashaforbes, mgifford, effulgentsia: Regression: Views integration for "list" field types is broken
-rw-r--r--core/modules/field/src/Views/FieldAPIHandlerTrait.php79
-rw-r--r--core/modules/options/config/schema/options.schema.yml41
-rw-r--r--core/modules/options/options.views.inc43
-rw-r--r--core/modules/options/src/Plugin/views/argument/NumberListField.php91
-rw-r--r--core/modules/options/src/Plugin/views/argument/StringListField.php91
-rw-r--r--core/modules/options/src/Plugin/views/filter/ListField.php37
-rw-r--r--core/modules/options/src/Tests/Views/OptionsListArgumentTest.php54
-rw-r--r--core/modules/options/src/Tests/Views/OptionsListFilterTest.php43
-rw-r--r--core/modules/options/src/Tests/Views/OptionsTestBase.php125
-rw-r--r--core/modules/options/tests/options_test_views/options_test_views.info.yml9
-rw-r--r--core/modules/options/tests/options_test_views/test_views/views.view.test_options_list_argument_numeric.yml205
-rw-r--r--core/modules/options/tests/options_test_views/test_views/views.view.test_options_list_argument_string.yml204
-rw-r--r--core/modules/options/tests/options_test_views/test_views/views.view.test_options_list_filter.yml209
-rw-r--r--core/modules/views/src/Plugin/views/field/Field.php48
-rw-r--r--core/modules/views/src/Plugin/views/filter/InOperator.php2
-rw-r--r--core/modules/views/views.views.inc23
16 files changed, 1235 insertions, 69 deletions
diff --git a/core/modules/field/src/Views/FieldAPIHandlerTrait.php b/core/modules/field/src/Views/FieldAPIHandlerTrait.php
new file mode 100644
index 0000000..da551cb
--- /dev/null
+++ b/core/modules/field/src/Views/FieldAPIHandlerTrait.php
@@ -0,0 +1,79 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\field\Views\FieldAPIHandlerTrait.
+ */
+
+namespace Drupal\field\Views;
+
+use Drupal\Core\Field\BaseFieldDefinition;
+
+/**
+ * A trait containing helper methods for field definitions.
+ */
+trait FieldAPIHandlerTrait {
+
+ /**
+ * The field definition.
+ *
+ * @var \Drupal\Core\Field\FieldDefinitionInterface
+ */
+ protected $fieldDefinition;
+
+ /**
+ * The field storage definition.
+ *
+ * @var \Drupal\field\FieldStorageConfigInterface
+ */
+ protected $fieldStorageDefinition;
+
+ /**
+ * Gets the field definition.
+ *
+ * A View works on an entity type across bundles, and thus only has access to
+ * field storage definitions. In order to be able to use widgets and
+ * formatters, we create a generic field definition out of that storage
+ * definition.
+ *
+ * @see BaseFieldDefinition::createFromFieldStorageDefinition()
+ *
+ * @return \Drupal\Core\Field\FieldDefinitionInterface
+ * The field definition used by this handler.
+ */
+ protected function getFieldDefinition() {
+ if (!$this->fieldDefinition) {
+ $field_storage_config = $this->getFieldStorageDefinition();
+ $this->fieldDefinition = BaseFieldDefinition::createFromFieldStorageDefinition($field_storage_config);
+ }
+ return $this->fieldDefinition;
+ }
+
+ /**
+ * Gets the field storage configuration.
+ *
+ * @return \Drupal\field\FieldStorageConfigInterface
+ * The field storage definition used by this handler
+ */
+ protected function getFieldStorageDefinition() {
+ if (!$this->fieldStorageDefinition) {
+ $field_storage_definitions = $this->getEntityManager()->getFieldStorageDefinitions($this->definition['entity_type']);
+ $this->fieldStorageDefinition = $field_storage_definitions[$this->definition['field_name']];
+ }
+ return $this->fieldStorageDefinition;
+ }
+
+ /**
+ * Returns the entity manager.
+ *
+ * @return \Drupal\Core\Entity\EntityManagerInterface
+ * The entity manager service.
+ */
+ protected function getEntityManager() {
+ if (!isset($this->entityManager)) {
+ $this->entityManager = \Drupal::entityManager();
+ }
+ return $this->entityManager;
+ }
+
+}
diff --git a/core/modules/options/config/schema/options.schema.yml b/core/modules/options/config/schema/options.schema.yml
index 9ccc7a4..7bd7547 100644
--- a/core/modules/options/config/schema/options.schema.yml
+++ b/core/modules/options/config/schema/options.schema.yml
@@ -114,3 +114,44 @@ field.widget.settings.options_buttons:
field.widget.settings.options_select:
type: mapping
label: 'Select list format settings'
+
+views.argument.number_list_field:
+ type: views.argument.numeric
+ mapping:
+ summary:
+ type: mapping
+ label: 'Display a summary'
+ mapping:
+ sort_order:
+ type: string
+ label: 'Sort order'
+ number_of_records:
+ type: integer
+ label: 'Sort by'
+ format:
+ type: string
+ label: 'Format'
+ human:
+ type: boolean
+
+views.argument.string_list_field:
+ type: views.argument.string
+ mapping:
+ summary:
+ type: mapping
+ label: 'Display a summary'
+ mapping:
+ sort_order:
+ type: string
+ label: 'Sort order'
+ number_of_records:
+ type: integer
+ label: 'Sort by'
+ format:
+ type: string
+ label: 'Format'
+ human:
+ type: boolean
+
+views.filter.list_field:
+ type: views.filter.many_to_one
diff --git a/core/modules/options/options.views.inc b/core/modules/options/options.views.inc
new file mode 100644
index 0000000..95b8474
--- /dev/null
+++ b/core/modules/options/options.views.inc
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * @file
+ * Provide Views data for options.module.
+ *
+ * @ingroup views_module_handlers
+ */
+
+/**
+ * Implements hook_field_views_data().
+ *
+ * Views integration for list fields. Have a different filter handler and
+ * argument handlers for list fields. This should allow to select values of
+ * the list.
+ */
+function options_field_views_data($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') {
+ $data[$table_name][$field_name]['filter']['id'] = 'list_field';
+ }
+ if (isset($field_data['argument']) && $field_name != 'delta') {
+ if ($field->type == 'list_string') {
+ $data[$table_name][$field_name]['argument']['id'] = 'string_list_field';
+ }
+ else {
+ $data[$table_name][$field_name]['argument']['id'] = 'number_list_field';
+ }
+ }
+ }
+ }
+
+ return $data;
+}
diff --git a/core/modules/options/src/Plugin/views/argument/NumberListField.php b/core/modules/options/src/Plugin/views/argument/NumberListField.php
new file mode 100644
index 0000000..9a3f9d3
--- /dev/null
+++ b/core/modules/options/src/Plugin/views/argument/NumberListField.php
@@ -0,0 +1,91 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\options\Plugin\views\argument\NumberListField.
+ */
+
+namespace Drupal\options\Plugin\views\argument;
+
+use Drupal\Component\Utility\String;
+use Drupal\Core\Field\AllowedTagsXssTrait;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\field\Views\FieldAPIHandlerTrait;
+use Drupal\views\ViewExecutable;
+use Drupal\views\Plugin\views\display\DisplayPluginBase;
+use Drupal\views\Plugin\views\argument\Numeric;
+
+/**
+ * Argument handler for list field to show the human readable name in the
+ * summary.
+ *
+ * @ingroup views_argument_handlers
+ *
+ * @ViewsArgument("number_list_field")
+ */
+class NumberListField extends Numeric {
+
+ use AllowedTagsXssTrait;
+ use FieldAPIHandlerTrait;
+
+ /**
+ * Stores the allowed values of this field.
+ *
+ * @var array
+ */
+ protected $allowedValues = NULL;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
+ parent::init($view, $display, $options);
+
+ $field_storage = $this->getFieldStorageDefinition();
+ $this->allowedValues = options_allowed_values($field_storage);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function defineOptions() {
+ $options = parent::defineOptions();
+ $options['summary']['contains']['human'] = ['default' => FALSE];
+
+ return $options;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
+ parent::buildOptionsForm($form, $form_state);
+
+ $form['summary']['human'] = [
+ '#title' => $this->t('Display list value as human readable'),
+ '#type' => 'checkbox',
+ '#default_value' => $this->options['summary']['human'],
+ '#states' => [
+ 'visible' => [
+ ':input[name="options[default_action]"]' => ['value' => 'summary'],
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function summaryName($data) {
+ $value = $data->{$this->name_alias};
+ // If the list element has a human readable name show it.
+ if (isset($this->allowedValues[$value]) && !empty($this->options['summary']['human'])) {
+ return $this->fieldFilterXss($this->allowedValues[$value]);
+ }
+ // Else, fallback to the key.
+ else {
+ return String::checkPlain($value);
+ }
+ }
+
+}
diff --git a/core/modules/options/src/Plugin/views/argument/StringListField.php b/core/modules/options/src/Plugin/views/argument/StringListField.php
new file mode 100644
index 0000000..1718938
--- /dev/null
+++ b/core/modules/options/src/Plugin/views/argument/StringListField.php
@@ -0,0 +1,91 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\options\Plugin\views\argument\StringListField.
+ */
+
+namespace Drupal\options\Plugin\views\argument;
+
+use Drupal\Core\Field\AllowedTagsXssTrait;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\field\Views\FieldAPIHandlerTrait;
+use Drupal\views\ViewExecutable;
+use Drupal\views\Plugin\views\display\DisplayPluginBase;
+use Drupal\views\Plugin\views\argument\String;
+use Drupal\Component\Utility\String as StringUtility;
+
+/**
+ * Argument handler for list field to show the human readable name in summary.
+ *
+ * @ingroup views_argument_handlers
+ *
+ * @ViewsArgument("string_list_field")
+ */
+class StringListField extends String {
+
+ use AllowedTagsXssTrait;
+ use FieldAPIHandlerTrait;
+
+ /**
+ * Stores the allowed values of this field.
+ *
+ * @var array
+ */
+ protected $allowedValues = NULL;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
+ parent::init($view, $display, $options);
+
+ $field_storage = $this->getFieldStorageDefinition();
+ $this->allowedValues = options_allowed_values($field_storage);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function defineOptions() {
+ $options = parent::defineOptions();
+
+ $options['summary']['contains']['human'] = ['default' => FALSE];
+
+ return $options;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
+ parent::buildOptionsForm($form, $form_state);
+
+ $form['summary']['human'] = [
+ '#title' => $this->t('Display list value as human readable'),
+ '#type' => 'checkbox',
+ '#default_value' => $this->options['summary']['human'],
+ '#states' => [
+ 'visible' => [
+ ':input[name="options[default_action]"]' => ['value' => 'summary'],
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function summaryName($data) {
+ $value = $data->{$this->name_alias};
+ // If the list element has a human readable name show it.
+ if (isset($this->allowedValues[$value]) && !empty($this->options['summary']['human'])) {
+ return $this->caseTransform($this->fieldFilterXss($this->allowedValues[$value]), $this->options['case']);
+ }
+ // Else, fallback to the key.
+ else {
+ return $this->caseTransform(StringUtility::checkPlain($value), $this->options['case']);
+ }
+ }
+
+}
diff --git a/core/modules/options/src/Plugin/views/filter/ListField.php b/core/modules/options/src/Plugin/views/filter/ListField.php
new file mode 100644
index 0000000..25fb290
--- /dev/null
+++ b/core/modules/options/src/Plugin/views/filter/ListField.php
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\field\Plugin\views\filter\ListField.
+ */
+
+namespace Drupal\options\Plugin\views\filter;
+
+use Drupal\field\Views\FieldAPIHandlerTrait;
+use Drupal\views\Plugin\views\display\DisplayPluginBase;
+use Drupal\views\Plugin\views\filter\ManyToOne;
+use Drupal\views\ViewExecutable;
+
+/**
+ * Filter handler which uses list-fields as options.
+ *
+ * @ingroup views_filter_handlers
+ *
+ * @ViewsFilter("list_field")
+ */
+class ListField extends ManyToOne {
+
+ use FieldAPIHandlerTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
+ parent::init($view, $display, $options);
+
+ $field_storage = $this->getFieldStorageDefinition();
+ // Set valueOptions here so getValueOptions() will just return it.
+ $this->valueOptions = options_allowed_values($field_storage);
+ }
+
+}
diff --git a/core/modules/options/src/Tests/Views/OptionsListArgumentTest.php b/core/modules/options/src/Tests/Views/OptionsListArgumentTest.php
new file mode 100644
index 0000000..198ebd1
--- /dev/null
+++ b/core/modules/options/src/Tests/Views/OptionsListArgumentTest.php
@@ -0,0 +1,54 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\options\Tests\Views\OptionsListArgumentTest.
+ */
+
+namespace Drupal\options\Tests\Views;
+
+use Drupal\views\Views;
+
+/**
+ * Tests options list argument for views.
+ *
+ * @see \Drupal\options\Plugin\views\argument\NumberListField.
+ * @group views
+ */
+class OptionsListArgumentTest extends OptionsTestBase {
+
+ /**
+ * Views used by this test.
+ *
+ * @var array
+ */
+ public static $testViews = ['test_options_list_argument_numeric', 'test_options_list_argument_string'];
+
+ /**
+ * Tests the options field argument.
+ */
+ public function testViewsTestOptionsListArgument() {
+ $view = Views::getView('test_options_list_argument_numeric');
+ $this->executeView($view, [1]);
+
+ $resultset = [
+ ['nid' => $this->nodes[0]->nid->value],
+ ['nid' => $this->nodes[1]->nid->value],
+ ];
+
+ $column_map = ['nid' => 'nid'];
+ $this->assertIdenticalResultset($view, $resultset, $column_map);
+
+ $view = Views::getView('test_options_list_argument_string');
+ $this->executeView($view, ['man', 'woman']);
+
+ $resultset = [
+ ['nid' => $this->nodes[0]->nid->value],
+ ['nid' => $this->nodes[1]->nid->value],
+ ];
+
+ $column_map = ['nid' => 'nid'];
+ $this->assertIdenticalResultset($view, $resultset, $column_map);
+ }
+
+}
diff --git a/core/modules/options/src/Tests/Views/OptionsListFilterTest.php b/core/modules/options/src/Tests/Views/OptionsListFilterTest.php
new file mode 100644
index 0000000..164bf15
--- /dev/null
+++ b/core/modules/options/src/Tests/Views/OptionsListFilterTest.php
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\options\Tests\Views\OptionsListFilterTest.
+ */
+
+namespace Drupal\options\Tests\Views;
+
+use Drupal\views\Views;
+
+/**
+ * Tests options list filter for views.
+ *
+ * @see \Drupal\field\Plugin\views\filter\ListField.
+ * @group views
+ */
+class OptionsListFilterTest extends OptionsTestBase {
+
+ /**
+ * Views used by this test.
+ *
+ * @var array
+ */
+ public static $testViews = ['test_options_list_filter'];
+
+ /**
+ * Tests options list field filter.
+ */
+ public function testViewsTestOptionsListFilter() {
+ $view = Views::getView('test_options_list_filter');
+ $this->executeView($view);
+
+ $resultset = [
+ ['nid' => $this->nodes[0]->nid->value],
+ ['nid' => $this->nodes[1]->nid->value],
+ ];
+
+ $column_map = ['nid' => 'nid'];
+ $this->assertIdenticalResultset($view, $resultset, $column_map);
+ }
+
+}
diff --git a/core/modules/options/src/Tests/Views/OptionsTestBase.php b/core/modules/options/src/Tests/Views/OptionsTestBase.php
new file mode 100644
index 0000000..857885a
--- /dev/null
+++ b/core/modules/options/src/Tests/Views/OptionsTestBase.php
@@ -0,0 +1,125 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\options\Tests\Views\OptionsTestBase.
+ */
+
+namespace Drupal\options\Tests\Views;
+
+use Drupal\field\Entity\FieldConfig;
+use Drupal\field\Entity\FieldStorageConfig;
+use Drupal\node\Entity\Node;
+use Drupal\node\Entity\NodeType;
+use Drupal\views\Tests\ViewTestBase;
+use Drupal\views\Tests\ViewTestData;
+use Drupal\views\Tests\ViewUnitTestBase;
+
+/**
+ * Base class for options views tests.
+ */
+abstract class OptionsTestBase extends ViewUnitTestBase {
+
+ /**
+ * Modules to enable.
+ *
+ * @var array
+ */
+ public static $modules = ['options', 'options_test_views', 'node', 'user', 'field'];
+
+ /**
+ * Stores the nodes used for the different tests.
+ *
+ * @var array
+ */
+ protected $nodes = [];
+
+ /**
+ * Stores the field values used for the different tests.
+ *
+ * @var array
+ */
+ protected $fieldValues = [];
+
+ /**
+ * The used field names.
+ *
+ * @var string[]
+ */
+ protected $fieldNames;
+
+ protected function setUp() {
+ parent::setUp();
+ $this->mockStandardInstall();
+
+ ViewTestData::createTestViews(get_class($this), ['options_test_views']);
+
+ $settings = [];
+ $settings['type'] = 'article';
+ $settings['field_test_list_string'][]['value'] = $this->fieldValues[0];
+ $settings['field_test_list_integer'][]['value'] = 0;
+
+ $node = Node::create($settings);
+ $node->save();
+
+ $this->nodes[] = $node;
+ $node = $node->createDuplicate();
+ $node->save();
+ $this->nodes[] = $node;
+ }
+
+ /**
+ * Provides a workaround for the inability to use the standard profile.
+ *
+ * @see http://drupal.org/node/1708692
+ */
+ protected function mockStandardInstall() {
+ $this->installEntitySchema('user');
+ $this->installEntitySchema('node');
+
+ NodeType::create(
+ ['type' => 'article']
+ )->save();
+ $this->fieldValues = [
+ $this->randomMachineName(),
+ $this->randomMachineName(),
+ ];
+
+ $this->fieldNames = ['field_test_list_string', 'field_test_list_integer'];
+
+ // Create two field entities.
+ FieldStorageConfig::create([
+ 'field_name' => $this->fieldNames[0],
+ 'entity_type' => 'node',
+ 'type' => 'list_string',
+ 'cardinality' => 1,
+ 'settings' => [
+ 'allowed_values' => [
+ $this->fieldValues[0] => $this->fieldValues[0],
+ $this->fieldValues[1] => $this->fieldValues[1],
+ ],
+ ],
+ ])->save();
+ FieldStorageConfig::create([
+ 'field_name' => $this->fieldNames[1],
+ 'entity_type' => 'node',
+ 'type' => 'list_integer',
+ 'cardinality' => 1,
+ 'settings' => [
+ 'allowed_values' => [
+ $this->fieldValues[0],
+ $this->fieldValues[1],
+ ],
+ ],
+ ])->save();
+ foreach ($this->fieldNames as $field_name) {
+ FieldConfig::create([
+ 'field_name' => $field_name,
+ 'entity_type' => 'node',
+ 'label' => 'Test options list field',
+ 'bundle' => 'article',
+ ])->save();
+ }
+ }
+
+}
diff --git a/core/modules/options/tests/options_test_views/options_test_views.info.yml b/core/modules/options/tests/options_test_views/options_test_views.info.yml
new file mode 100644
index 0000000..07d1cac
--- /dev/null
+++ b/core/modules/options/tests/options_test_views/options_test_views.info.yml
@@ -0,0 +1,9 @@
+name: 'Options test views'
+type: module
+description: 'Provides default views for views options tests.'
+package: Testing
+version: VERSION
+core: 8.x
+dependencies:
+ - options
+ - views
diff --git a/core/modules/options/tests/options_test_views/test_views/views.view.test_options_list_argument_numeric.yml b/core/modules/options/tests/options_test_views/test_views/views.view.test_options_list_argument_numeric.yml
new file mode 100644
index 0000000..69398b3
--- /dev/null
+++ b/core/modules/options/tests/options_test_views/test_views/views.view.test_options_list_argument_numeric.yml
@@ -0,0 +1,205 @@
+langcode: en
+status: true
+dependencies:
+ config:
+ - node.type.article
+ module:
+ - node
+ - user
+id: test_options_list_argument_numeric
+label: 'test options list argument (numeric)'
+module: views
+description: ''
+tag: ''
+base_table: node
+base_field: nid
+core: 8.x
+display:
+ default:
+ display_plugin: default
+ id: default
+ display_title: Master
+ position: 1
+ display_options:
+ access:
+ type: perm
+ options:
+ perm: 'access content'
+ cache:
+ type: none
+ options: { }
+ query:
+ type: views_query
+ options:
+ disable_sql_rewrite: false
+ distinct: false
+ replica: false
+ query_comment: false
+ query_tags: { }
+ exposed_form:
+ type: basic
+ options:
+ submit_button: Apply
+ reset_button: false
+ reset_button_label: Reset
+ exposed_sorts_label: 'Sort by'
+ expose_sort_order: true
+ sort_asc_label: Asc
+ sort_desc_label: Desc
+ pager:
+ type: some
+ options:
+ items_per_page: 5
+ offset: 0
+ style:
+ type: default
+ row:
+ type: fields
+ fields:
+ title:
+ id: title
+ table: node_field_data
+ field: title
+ label: ''
+ alter:
+ alter_text: false
+ make_link: false
+ absolute: false
+ trim: false
+ word_boundary: false
+ ellipsis: false
+ strip_tags: false
+ html: false
+ hide_empty: false
+ empty_zero: false
+ link_to_node: true
+ relationship: none
+ group_type: group
+ admin_label: ''
+ exclude: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_alter_empty: true
+ plugin_id: node
+ filters:
+ status:
+ value: true
+ table: node_field_data
+ field: status
+ id: status
+ expose:
+ operator: ''
+ group: 1
+ plugin_id: boolean
+ type:
+ id: type
+ table: node_field_data
+ field: type
+ relationship: none
+ group_type: group
+ admin_label: ''
+ operator: in
+ value:
+ article: article
+ group: 1
+ exposed: false
+ expose:
+ operator_id: '0'
+ label: ''
+ description: ''
+ use_operator: false
+ operator: ''
+ identifier: ''
+ required: false
+ remember: false
+ multiple: false
+ remember_roles:
+ authenticated: authenticated
+ reduce: false
+ is_grouped: false
+ group_info:
+ label: ''
+ description: ''
+ identifier: ''
+ optional: true
+ widget: select
+ multiple: false
+ remember: false
+ default_group: All
+ default_group_multiple: { }
+ group_items: { }
+ plugin_id: bundle
+ sorts:
+ nid:
+ id: nid
+ table: nid
+ field: nid
+ order: DESC
+ relationship: none
+ group_type: group
+ admin_label: ''
+ exposed: false
+ expose:
+ label: ''
+ plugin_id: standard
+ title: 'test options list argument'
+ header: { }
+ footer: { }
+ empty: { }
+ relationships: { }
+ arguments:
+ field_test_list_integer_value:
+ id: field_test_list_integer_value
+ table: field_data_field_test_list_integer
+ field: field_test_list_integer_value
+ relationship: none
+ group_type: group
+ admin_label: ''
+ default_action: empty
+ exception:
+ value: all
+ title_enable: false
+ title: All
+ title_enable: false
+ title: ''
+ default_argument_type: fixed
+ default_argument_options:
+ argument: ''
+ default_argument_skip_url: false
+ summary_options:
+ base_path: ''
+ items_per_page: 25
+ count: false
+ override: false
+ summary:
+ sort_order: asc
+ number_of_records: 0
+ format: default_summary
+ human: true
+ specify_validation: false
+ validate:
+ type: none
+ fail: 'not found'
+ validate_options: { }
+ break_phrase: false
+ not: false
+ plugin_id: number_list_field
+ display_extenders: { }
+ field_langcode: '***LANGUAGE_language_content***'
+ field_langcode_add_to_query: null
+ block_1:
+ display_plugin: block
+ id: block_1
+ display_title: Block
+ position: 1
+ display_options:
+ display_extenders: { }
+ field_langcode: '***LANGUAGE_language_content***'
+ field_langcode_add_to_query: null
diff --git a/core/modules/options/tests/options_test_views/test_views/views.view.test_options_list_argument_string.yml b/core/modules/options/tests/options_test_views/test_views/views.view.test_options_list_argument_string.yml
new file mode 100644
index 0000000..ef09354
--- /dev/null
+++ b/core/modules/options/tests/options_test_views/test_views/views.view.test_options_list_argument_string.yml
@@ -0,0 +1,204 @@
+langcode: en
+status: true
+dependencies:
+ config:
+ - node.type.article
+ module:
+ - node
+ - user
+id: test_options_list_argument_string
+label: 'test options list argument (string)'
+module: views
+description: ''
+tag: ''
+base_table: node
+base_field: nid
+core: 8.x
+display:
+ default:
+ display_plugin: default
+ id: default
+ display_title: Master
+ position: 1
+ display_options:
+ access:
+ type: perm
+ options:
+ perm: 'access content'
+ cache:
+ type: none
+ options: { }
+ query:
+ type: views_query
+ options:
+ disable_sql_rewrite: false
+ distinct: false
+ replica: false
+ query_comment: false
+ query_tags: { }
+ exposed_form:
+ type: basic
+ options:
+ submit_button: Apply
+ reset_button: false
+ reset_button_label: Reset
+ exposed_sorts_label: 'Sort by'
+ expose_sort_order: true
+ sort_asc_label: Asc
+ sort_desc_label: Desc
+ pager:
+ type: some
+ options:
+ items_per_page: 5
+ offset: 0
+ style:
+ type: default
+ row:
+ type: fields
+ fields:
+ title:
+ id: title
+ table: node_field_data
+ field: title
+ label: ''
+ alter:
+ alter_text: false
+ make_link: false
+ absolute: false
+ trim: false
+ word_boundary: false
+ ellipsis: false
+ strip_tags: false
+ html: false
+ hide_empty: false
+ empty_zero: false
+ link_to_node: true
+ relationship: none
+ group_type: group
+ admin_label: ''
+ exclude: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_alter_empty: true
+ plugin_id: node
+ filters:
+ status:
+ value: true
+ table: node_field_data
+ field: status
+ id: status
+ expose:
+ operator: ''
+ group: 1
+ plugin_id: boolean
+ type:
+ id: type
+ table: node_field_data
+ field: type
+ relationship: none
+ group_type: group
+ admin_label: ''
+ operator: in
+ value:
+ article: article
+ group: 1
+ exposed: false
+ expose:
+ operator_id: '0'
+ label: ''
+ description: ''
+ use_operator: false
+ operator: ''
+ identifier: ''
+ required: false
+ remember: false
+ multiple: false
+ remember_roles:
+ authenticated: authenticated
+ reduce: false
+ is_grouped: false
+ group_info:
+ label: ''
+ description: ''
+ identifier: ''
+ optional: true
+ widget: select
+ multiple: false
+ remember: false
+ default_group: All
+ default_group_multiple: { }
+ group_items: { }
+ plugin_id: bundle
+ sorts:
+ nid:
+ id: nid
+ table: nid
+ field: nid
+ order: DESC
+ relationship: none
+ group_type: group
+ admin_label: ''
+ exposed: false
+ expose:
+ label: ''
+ plugin_id: standard
+ title: 'test options list argument'
+ header: { }
+ footer: { }
+ empty: { }
+ relationships: { }
+ arguments:
+ field_test_list_string_value:
+ id: field_test_list_string_value
+ table: field_data_field_test_list_string
+ field: field_test_list_string_value
+ relationship: none
+ group_type: group
+ admin_label: ''
+ default_action: empty
+ exception:
+ value: all
+ title_enable: false
+ title: All
+ title_enable: false
+ title: ''
+ default_argument_type: fixed
+ default_argument_options:
+ argument: ''
+ default_argument_skip_url: false
+ summary_options:
+ base_path: ''
+ items_per_page: 25
+ count: false
+ override: false
+ summary:
+ sort_order: asc
+ number_of_records: 0
+ format: default_summary
+ human: true
+ specify_validation: false
+ validate:
+ type: none
+ fail: 'not found'
+ validate_options: { }
+ break_phrase: false
+ plugin_id: string_list_field
+ display_extenders: { }
+ field_langcode: '***LANGUAGE_language_content***'
+ field_langcode_add_to_query: null
+ block_1:
+ display_plugin: block
+ id: block_1
+ display_title: Block
+ position: 1
+ display_options:
+ display_extenders: { }
+ field_langcode: '***LANGUAGE_language_content***'
+ field_langcode_add_to_query: null
diff --git a/core/modules/options/tests/options_test_views/test_views/views.view.test_options_list_filter.yml b/core/modules/options/tests/options_test_views/test_views/views.view.test_options_list_filter.yml
new file mode 100644
index 0000000..4da80ea
--- /dev/null
+++ b/core/modules/options/tests/options_test_views/test_views/views.view.test_options_list_filter.yml
@@ -0,0 +1,209 @@
+langcode: en
+status: true
+dependencies:
+ config:
+ - node.type.article
+ module:
+ - node
+ - user
+id: test_options_list_filter
+label: test_options_list_filter
+module: views
+description: ''
+tag: ''
+base_table: node
+base_field: nid
+core: 8.x
+display:
+ default:
+ display_plugin: default
+ id: default
+ display_title: Master
+ position: 1
+ display_options:
+ access:
+ type: perm
+ options:
+ perm: 'access content'
+ cache:
+ type: none
+ options: { }
+ query:
+ type: views_query
+ options:
+ disable_sql_rewrite: false
+ distinct: false
+ replica: false
+ query_comment: false
+ query_tags: { }
+ exposed_form:
+ type: basic
+ options:
+ submit_button: Apply
+ reset_button: false
+ reset_button_label: Reset
+ exposed_sorts_label: 'Sort by'
+ expose_sort_order: true
+ sort_asc_label: Asc
+ sort_desc_label: Desc
+ pager:
+ type: some
+ options:
+ items_per_page: 5
+ offset: 0
+ style:
+ type: default
+ row:
+ type: fields
+ fields:
+ title:
+ id: title
+ table: node_field_data
+ field: title
+ label: ''
+ alter:
+ alter_text: false
+ make_link: false
+ absolute: false
+ trim: false
+ word_boundary: false
+ ellipsis: false
+ strip_tags: false
+ html: false
+ hide_empty: false
+ empty_zero: false
+ link_to_node: true
+ relationship: none
+ group_type: group
+ admin_label: ''
+ exclude: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_alter_empty: true
+ plugin_id: node
+ filters:
+ status:
+ value: true
+ table: node_field_data
+ field: status
+ id: status
+ expose:
+ operator: ''
+ group: 1
+ plugin_id: boolean
+ field_test_list_string_value:
+ id: field_test_list_string_value
+ table: field_data_field_test_list_string
+ field: field_test_list_string_value
+ relationship: none
+ group_type: group
+ admin_label: ''
+ operator: or
+ value:
+ man: man
+ woman: woman
+ group: 1
+ exposed: false
+ expose:
+ operator_id: ''
+ label: ''
+ description: ''
+ use_operator: false
+ operator: ''
+ identifier: ''
+ required: false
+ remember: false
+ multiple: false
+ remember_roles:
+ authenticated: authenticated
+ reduce: false
+ is_grouped: false
+ group_info:
+ label: ''
+ description: ''
+ identifier: ''
+ optional: true
+ widget: select
+ multiple: false
+ remember: false
+ default_group: All
+ default_group_multiple: { }
+ group_items: { }
+ reduce_duplicates: false
+ plugin_id: list_field
+ type:
+ id: type
+ table: node_field_data
+ field: type
+ relationship: none
+ group_type: group
+ admin_label: ''
+ operator: in
+ value:
+ article: article
+ group: 1
+ exposed: false
+ expose:
+ operator_id: ''
+ label: ''
+ description: ''
+ use_operator: false
+ operator: ''
+ identifier: ''
+ required: false
+ remember: false
+ multiple: false
+ remember_roles:
+ authenticated: authenticated
+ reduce: false
+ is_grouped: false
+ group_info:
+ label: ''
+ description: ''
+ identifier: ''
+ optional: true
+ widget: select
+ multiple: false
+ remember: false
+ default_group: All
+ default_group_multiple: { }
+ group_items: { }
+ plugin_id: bundle
+ sorts:
+ nid:
+ id: nid
+ table: nid
+ field: nid
+ order: DESC
+ relationship: none
+ group_type: group
+ admin_label: ''
+ exposed: false
+ expose:
+ label: ''
+ plugin_id: standard
+ title: test_options_list_filter
+ header: { }
+ footer: { }
+ empty: { }
+ relationships: { }
+ arguments: { }
+ display_extenders: { }
+ field_langcode: '***LANGUAGE_language_content***'
+ field_langcode_add_to_query: null
+ block_1:
+ display_plugin: block
+ id: block_1
+ display_title: Block
+ position: 1
+ display_options:
+ display_extenders: { }
+ field_langcode: '***LANGUAGE_language_content***'
+ field_langcode_add_to_query: null
diff --git a/core/modules/views/src/Plugin/views/field/Field.php b/core/modules/views/src/Plugin/views/field/Field.php
index 05f6335..1be60ce 100644
--- a/core/modules/views/src/Plugin/views/field/Field.php
+++ b/core/modules/views/src/Plugin/views/field/Field.php
@@ -25,6 +25,7 @@ use Drupal\Core\Render\Element;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\field\FieldStorageConfigInterface;
+use Drupal\field\Views\FieldAPIHandlerTrait;
use Drupal\views\Plugin\CacheablePluginInterface;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\field\FieldPluginBase;
@@ -45,6 +46,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class Field extends FieldPluginBase implements CacheablePluginInterface, MultiItemsFieldHandlerInterface {
+ use FieldAPIHandlerTrait;
+
/**
* An array to store field renderable arrays for use by renderItems().
*
@@ -53,24 +56,6 @@ class Field extends FieldPluginBase implements CacheablePluginInterface, MultiIt
public $items = array();
/**
- * The field definition to use.
- *
- * A field storage definition turned into a field definition, so it can be
- * used with widgets and formatters. See
- * BaseFieldDefinition::createFromFieldStorageDefinition().
- *
- * @var \Drupal\Core\Field\FieldDefinitionInterface
- */
- protected $fieldDefinition;
-
- /**
- * The field config.
- *
- * @var \Drupal\field\FieldStorageConfigInterface
- */
- protected $fieldStorageConfig;
-
- /**
* Does the field supports multiple field values.
*
* @var bool
@@ -186,33 +171,6 @@ class Field extends FieldPluginBase implements CacheablePluginInterface, MultiIt
}
/**
- * Gets the field definition.
- *
- * @return \Drupal\Core\Field\FieldDefinitionInterface
- * The field definition used by this handler.
- */
- protected function getFieldDefinition() {
- if (!$this->fieldDefinition) {
- $field_storage_config = $this->getFieldStorageDefinition();
- $this->fieldDefinition = BaseFieldDefinition::createFromFieldStorageDefinition($field_storage_config);
- }
- return $this->fieldDefinition;
- }
-
- /**
- * Gets the field configuration.
- *
- * @return \Drupal\field\FieldStorageConfigInterface
- */
- protected function getFieldStorageConfig() {
- if (!$this->fieldStorageConfig) {
- $field_storage_definitions = \Drupal::entityManager()->getFieldStorageDefinitions($this->definition['entity_type']);
- $this->fieldStorageConfig = $field_storage_definitions[$this->definition['field_name']];
- }
- return $this->fieldStorageConfig;
- }
-
- /**
* Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::init().
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
diff --git a/core/modules/views/src/Plugin/views/filter/InOperator.php b/core/modules/views/src/Plugin/views/filter/InOperator.php
index 82dabe0..5d4865c 100644
--- a/core/modules/views/src/Plugin/views/filter/InOperator.php
+++ b/core/modules/views/src/Plugin/views/filter/InOperator.php
@@ -65,7 +65,7 @@ class InOperator extends FilterPluginBase {
*/
public function getValueOptions() {
if (isset($this->valueOptions)) {
- return;
+ return $this->valueOptions;
}
if (isset($this->definition['options callback']) && is_callable($this->definition['options callback'])) {
diff --git a/core/modules/views/views.views.inc b/core/modules/views/views.views.inc
index 5f86626..1e91727 100644
--- a/core/modules/views/views.views.inc
+++ b/core/modules/views/views.views.inc
@@ -634,26 +634,3 @@ function views_field_default_views_data(FieldStorageConfigInterface $field_stora
return $data;
}
-
-/**
- * Have a different filter handler for lists. This should allow to select values of the list.
- */
-function list_field_views_data(FieldStorageConfigInterface $field_storage) {
- $data = views_field_default_views_data($field_storage);
- foreach ($data as $table_name => $table_data) {
- foreach ($table_data as $field_name => $field_data) {
- if (isset($field_data['filter']) && $field_name != 'delta') {
- $data[$table_name][$field_name]['filter']['id'] = 'field_list';
- }
- if (isset($field_data['argument']) && $field_name != 'delta') {
- if ($field_storage->getType() == 'list_string') {
- $data[$table_name][$field_name]['argument']['id'] = 'field_list_string';
- }
- else {
- $data[$table_name][$field_name]['argument']['id'] = 'field_list';
- }
- }
- }
- }
- return $data;
-}