diff --git a/core/config/schema/core.entity.schema.yml b/core/config/schema/core.entity.schema.yml index 2d1b7dc..ee3d5d7 100644 --- a/core/config/schema/core.entity.schema.yml +++ b/core/config/schema/core.entity.schema.yml @@ -222,6 +222,19 @@ field.widget.settings.checkbox: type: boolean label: 'Use field label instead of the "On value" as label' +field.formatter.settings.boolean: + type: mapping + mapping: + format: + type: string + label: 'Output format' + format_custom_false: + type: string + label: 'Custom output for FALSE' + format_custom_true: + type: string + label: 'Custom output for TRUE' + field.formatter.settings.string: type: mapping mapping: diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php index 6860dee..2be5d1d 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php @@ -9,6 +9,7 @@ use Drupal\Core\Field\FormatterBase; use Drupal\Core\Field\FieldItemListInterface; +use Drupal\Core\Form\FormStateInterface; /** * Plugin implementation of the 'boolean' formatter. @@ -26,11 +27,98 @@ class BooleanFormatter extends FormatterBase { /** * {@inheritdoc} */ + public static function defaultSettings() { + $settings = []; + + // Fallback to field settings by default. + $settings['format'] = 'default'; + $settings['format_custom_false'] = ''; + $settings['format_custom_true'] = ''; + + return $settings; + } + + /** + * Gets the available format options. + * + * @return array + * A list of output formats. Each entry is keyed by the machine name of the + * format. The value is an array, of which the first item is the result for + * boolean TRUE, the second is for boolean FALSE. + */ + protected function getOutputFormats() { + $formats = [ + 'default' => [$this->getFieldSetting('on_label'), $this->getFieldSetting('off_label')], + 'yes-no' => [$this->t('Yes'), $this->t('No')], + 'true-false' => [$this->t('True'), $this->t('False')], + 'on-off' => [$this->t('On'), $this->t('Off')], + 'enabled-disabled' => [$this->t('Enabled'), $this->t('Disabled')], + 'boolean' => [1, 0], + 'unicode-yes-no' => ['✔', '✖'], + 'custom' => [$this->t('Custom')], + ]; + + return $formats; + } + + /** + * {@inheritdoc} + */ + public function settingsForm(array $form, FormStateInterface $form_state) { + $form = parent::settingsForm($form, $form_state); + + $formats = []; + foreach ($this->getOutputFormats() as $format_name => $format) { + $formats[$format_name] = implode(' / ', $format); + } + + $form['format'] = [ + '#type' => 'select', + '#title' => $this->t('Output format'), + '#default_value' => $this->getSetting('format'), + '#options' => $formats, + ]; + $form['format_custom_true'] = [ + '#type' => 'textfield', + '#title' => $this->t('Custom output for TRUE'), + '#default_value' => $this->getSetting('format_custom_true'), + '#states' => [ + 'visible' => [ + 'select[name="fields[field_boolean][settings_edit_form][settings][format]"]' => ['value' => 'custom'], + ], + ], + ]; + $form['format_custom_false'] = [ + '#type' => 'textfield', + '#title' => $this->t('Custom output for FALSE'), + '#default_value' => $this->getSetting('format_custom_false'), + '#states' => [ + 'visible' => [ + 'select[name="fields[field_boolean][settings_edit_form][settings][format]"]' => ['value' => 'custom'], + ], + ], + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ public function viewElements(FieldItemListInterface $items) { - $elements = array(); + $elements = []; + + $formats = $this->getOutputFormats(); foreach ($items as $delta => $item) { - $elements[$delta] = array('#markup' => $item->value ? $this->getFieldSetting('on_label') : $this->getFieldSetting('off_label')); + $format = $this->getSetting('format'); + + if ($format == 'custom') { + $elements[$delta] = ['#markup' => $item->value ? $this->getSetting('format_custom_true') : $this->getSetting('format_custom_false')]; + } + else { + $elements[$delta] = ['#markup' => $item->value ? $formats[$format][0] : $formats[$format][1]]; + } } return $elements; diff --git a/core/modules/action/src/Tests/ActionUninstallTest.php b/core/modules/action/src/Tests/ActionUninstallTest.php index bec61d1..2735d6e 100644 --- a/core/modules/action/src/Tests/ActionUninstallTest.php +++ b/core/modules/action/src/Tests/ActionUninstallTest.php @@ -22,7 +22,7 @@ class ActionUninstallTest extends WebTestBase { * * @var array */ - public static $modules = array('views', 'action'); + public static $modules = array('field', 'views', 'action'); /** * Tests Action uninstall. diff --git a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rest.yml b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rest.yml index bd04a83..acd28b9 100644 --- a/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rest.yml +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_rest.yml @@ -385,4 +385,3 @@ display: name: alias: '' raw_output: true - display_extenders: { } diff --git a/core/modules/field/config/schema/field.views.schema.yml b/core/modules/field/config/schema/field.views.schema.yml index aaf0697..b1a39cc 100644 --- a/core/modules/field/config/schema/field.views.schema.yml +++ b/core/modules/field/config/schema/field.views.schema.yml @@ -16,53 +16,6 @@ views.argument.field_list_string: type: boolean label: 'Display list value as human readable' -views.field.field: - type: views_field - label: 'Views entity field handler' - mapping: - click_sort_column: - type: string - label: 'Column used for click sorting' - type: - type: string - label: 'Formatter' - settings: - label: 'Settings' - type: field.formatter.settings.[%parent.type] - group_column: - type: string - label: 'Group by column' - group_columns: - type: sequence - label: 'Group by columns' - sequence: - - type: string - label: 'Column' - group_rows: - type: boolean - label: 'Display all values in the same row' - delta_limit: - type: string - label: 'Field' - delta_offset: - type: string - label: 'Offset' - delta_reversed: - type: boolean - label: 'Reversed' - delta_first_last: - type: boolean - label: 'First and last only' - multi_type: - type: string - label: 'Display type' - separator: - type: label - label: 'Separator' - field_api_classes: - type: boolean - label: 'Use field template' - views.filter.field_list: type: views.filter.many_to_one label: 'List field' diff --git a/core/modules/field/src/Tests/Boolean/BooleanFormatterTest.php b/core/modules/field/src/Tests/Boolean/BooleanFormatterTest.php new file mode 100644 index 0000000..5663a58 --- /dev/null +++ b/core/modules/field/src/Tests/Boolean/BooleanFormatterTest.php @@ -0,0 +1,144 @@ +installConfig(['field']); + $this->installEntitySchema('entity_test'); + + $this->entityType = 'entity_test'; + $this->bundle = $this->entityType; + $this->fieldName = Unicode::strtolower($this->randomMachineName()); + + $field_storage = FieldStorageConfig::create([ + 'field_name' => $this->fieldName, + 'entity_type' => $this->entityType, + 'type' => 'boolean', + ]); + $field_storage->save(); + + $instance = FieldConfig::create([ + 'field_storage' => $field_storage, + 'bundle' => $this->bundle, + 'label' => $this->randomMachineName(), + ]); + $instance->save(); + + $this->display = entity_get_display($this->entityType, $this->bundle, 'default') + ->setComponent($this->fieldName, [ + 'type' => 'boolean', + 'settings' => [], + ]); + $this->display->save(); + } + + /** + * Renders fields of a given entity with a given display. + * + * @param \Drupal\Core\Entity\FieldableEntityInterface $entity + * The entity object with attached fields to render. + * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display + * The display to render the fields in. + * + * @return string + * The rendered entity fields. + */ + protected function renderEntityFields(FieldableEntityInterface $entity, EntityViewDisplayInterface $display) { + $content = $display->build($entity); + $content = $this->render($content); + return $content; + } + + /** + * Tests boolean formatter output. + */ + public function testBooleanFormatter() { + $data = []; + $data[] = [0, [], 'Off']; + $data[] = [1, [], 'On']; + + $format = ['format' => 'enabled-disabled']; + $data[] = [0, $format, 'Disabled']; + $data[] = [1, $format, 'Enabled']; + + $format = ['format' => 'unicode-yes-no']; + $data[] = [1, $format, '✔']; + $data[] = [0, $format, '✖']; + + $format = [ + 'format' => 'custom', + 'format_custom_false' => 'FALSE', + 'format_custom_true' => 'TRUE' + ]; + $data[] = [0, $format, 'FALSE']; + $data[] = [1, $format, 'TRUE']; + + foreach ($data as $test_data) { + list($value, $settings, $expected) = $test_data; + + $component = $this->display->getComponent($this->fieldName); + $component['settings'] = $settings; + $this->display->setComponent($this->fieldName, $component); + + $entity = EntityTest::create([]); + $entity->{$this->fieldName}->value = $value; + + // Verify that all HTML is escaped and newlines are retained. + $this->renderEntityFields($entity, $this->display); + $this->assertRaw($expected); + } + } + +} \ No newline at end of file diff --git a/core/modules/node/config/install/views.view.content.yml b/core/modules/node/config/install/views.view.content.yml index 2a44101..95a511d 100644 --- a/core/modules/node/config/install/views.view.content.yml +++ b/core/modules/node/config/install/views.view.content.yml @@ -163,10 +163,12 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - link_to_node: true - plugin_id: node entity_type: node entity_field: title + type: string + settings: + link_to_entity: true + plugin_id: field type: id: type table: node_field_data @@ -222,11 +224,12 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - type: published-notpublished - type_custom_true: '' - type_custom_false: '' - not: '' - plugin_id: boolean + type: boolean + settings: + format: custom + format_custom_true: 'Published' + format_custom_false: 'Unpublished' + plugin_id: field entity_type: node entity_field: status changed: diff --git a/core/modules/node/config/install/views.view.content_recent.yml b/core/modules/node/config/install/views.view.content_recent.yml index 9456436..cec60cd 100644 --- a/core/modules/node/config/install/views.view.content_recent.yml +++ b/core/modules/node/config/install/views.view.content_recent.yml @@ -155,8 +155,10 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - link_to_node: true - plugin_id: node + type: string + settings: + link_to_entity: true + plugin_id: field entity_type: node entity_field: title name: diff --git a/core/modules/node/src/NodeViewsData.php b/core/modules/node/src/NodeViewsData.php index ca2bb26..82dcd3f 100644 --- a/core/modules/node/src/NodeViewsData.php +++ b/core/modules/node/src/NodeViewsData.php @@ -33,7 +33,12 @@ public function getViewsData() { 'validate type' => 'nid', ]; - $data['node_field_data']['title']['field']['id'] = 'node'; + // @fixme Move this into the generic views data. + $data['node_field_data']['title']['field']['id'] = 'field'; + $data['node_field_data']['title']['field']['field_name'] = 'title'; + $data['node_field_data']['title']['field']['entity_tables'] = ['node' => 'node', 'node_field_data' => 'node']; + $data['node_field_data']['title']['field']['default_formatter_settings'] = ['entity_link' => TRUE]; + $data['node_field_data']['title']['field']['link_to_node default'] = TRUE; $data['node_field_data']['type']['field']['id'] = 'node_type'; diff --git a/core/modules/node/src/Plugin/views/wizard/Node.php b/core/modules/node/src/Plugin/views/wizard/Node.php index b9c66e0..400c6d1 100644 --- a/core/modules/node/src/Plugin/views/wizard/Node.php +++ b/core/modules/node/src/Plugin/views/wizard/Node.php @@ -88,6 +88,7 @@ protected function defaultDisplayOptions() { $display_options['fields']['title']['table'] = 'node_field_data'; $display_options['fields']['title']['field'] = 'title'; $display_options['fields']['title']['entity_type'] = 'node'; + $display_options['fields']['title']['entity_type'] = 'node'; $display_options['fields']['title']['entity_field'] = 'title'; $display_options['fields']['title']['label'] = ''; $display_options['fields']['title']['alter']['alter_text'] = 0; @@ -100,8 +101,8 @@ protected function defaultDisplayOptions() { $display_options['fields']['title']['alter']['html'] = 0; $display_options['fields']['title']['hide_empty'] = 0; $display_options['fields']['title']['empty_zero'] = 0; - $display_options['fields']['title']['link_to_node'] = 1; - $display_options['fields']['title']['plugin_id'] = 'node'; + $display_options['fields']['title']['settings']['link_to_entity'] = 1; + $display_options['fields']['title']['plugin_id'] = 'field'; return $display_options; } @@ -176,8 +177,8 @@ protected function display_options_row(&$display_options, $row_plugin, $row_opt $display_options['fields']['title']['id'] = 'title'; $display_options['fields']['title']['table'] = 'node_field_data'; $display_options['fields']['title']['field'] = 'title'; - $display_options['fields']['title']['link_to_node'] = ($row_plugin == 'titles_linked'); - $display_options['fields']['title']['plugin_id'] = 'node'; + $display_options['fields']['title']['settings']['link_to_entity'] = $row_plugin === 'titles_linked'; + $display_options['fields']['title']['plugin_id'] = 'field'; break; } } diff --git a/core/modules/tracker/src/Tests/Views/TrackerUserUidTest.php b/core/modules/tracker/src/Tests/Views/TrackerUserUidTest.php index 7c9be32..ce5bbab 100644 --- a/core/modules/tracker/src/Tests/Views/TrackerUserUidTest.php +++ b/core/modules/tracker/src/Tests/Views/TrackerUserUidTest.php @@ -29,13 +29,11 @@ class TrackerUserUidTest extends TrackerTestBase { public function testUserUid() { $map = array( 'nid' => 'nid', - 'node_field_data_title' => 'title', ); $expected = array( array( 'nid' => $this->node->id(), - 'title' => $this->node->label(), ) ); diff --git a/core/modules/user/config/install/views.view.user_admin_people.yml b/core/modules/user/config/install/views.view.user_admin_people.yml index ff62509..55f0353 100644 --- a/core/modules/user/config/install/views.view.user_admin_people.yml +++ b/core/modules/user/config/install/views.view.user_admin_people.yml @@ -292,11 +292,12 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - type: active-blocked - type_custom_true: '' - type_custom_false: '' - not: '0' - plugin_id: boolean + plugin_id: field + type: boolean + settings: + format: custom + format_custom_true: 'Active' + format_custom_false: 'False' entity_type: user entity_field: status roles_target_id: diff --git a/core/modules/user/user.info.yml b/core/modules/user/user.info.yml index 45a421a..c4ae5bc 100644 --- a/core/modules/user/user.info.yml +++ b/core/modules/user/user.info.yml @@ -6,3 +6,5 @@ version: VERSION core: 8.x required: true configure: user.admin_index +dependencies: + - field \ No newline at end of file diff --git a/core/modules/views/config/schema/views.field.schema.yml b/core/modules/views/config/schema/views.field.schema.yml index c515361..78dcf2f 100644 --- a/core/modules/views/config/schema/views.field.schema.yml +++ b/core/modules/views/config/schema/views.field.schema.yml @@ -178,3 +178,51 @@ views.field.xss: views.field.language: type: views_field label: 'Language' + +views.field.field: + type: views_field + label: 'Views entity field handler' + mapping: + click_sort_column: + type: string + label: 'Column used for click sorting' + type: + type: string + label: 'Formatter' + settings: + label: 'Settings' + type: field.formatter.settings.[%parent.type] + group_column: + type: string + label: 'Group by column' + group_columns: + type: sequence + label: 'Group by columns' + sequence: + - type: string + label: 'Column' + group_rows: + type: boolean + label: 'Display all values in the same row' + delta_limit: + type: string + label: 'Field' + delta_offset: + type: string + label: 'Offset' + delta_reversed: + type: boolean + label: 'Reversed' + delta_first_last: + type: boolean + label: 'First and last only' + multi_type: + type: string + label: 'Display type' + separator: + type: label + label: 'Separator' + field_api_classes: + type: boolean + label: 'Use field template' + diff --git a/core/modules/views/src/EntityViewsData.php b/core/modules/views/src/EntityViewsData.php index cb30422..e735f1d 100644 --- a/core/modules/views/src/EntityViewsData.php +++ b/core/modules/views/src/EntityViewsData.php @@ -300,21 +300,21 @@ protected function mapSingleFieldViewsData($table, $field_name, $field_type, $co break; case 'language': - $views_field['field']['id'] = 'language'; + $views_field['field']['id'] = 'field'; $views_field['argument']['id'] = 'language'; $views_field['filter']['id'] = 'language'; $views_field['sort']['id'] = 'standard'; break; case 'boolean': - $views_field['field']['id'] = 'boolean'; + $views_field['field']['id'] = 'field'; $views_field['argument']['id'] = 'numeric'; $views_field['filter']['id'] = 'boolean'; $views_field['sort']['id'] = 'standard'; break; case 'uri': - $views_field['field']['id'] = 'url'; + $views_field['field']['id'] = 'field'; $views_field['argument']['id'] = 'string'; $views_field['filter']['id'] = 'string'; $views_field['sort']['id'] = 'standard'; @@ -339,7 +339,7 @@ protected function mapSingleFieldViewsData($table, $field_name, $field_type, $co case 'float': case 'double': case 'decimal': - $views_field['field']['id'] = 'numeric'; + $views_field['field']['id'] = 'field'; $views_field['argument']['id'] = 'numeric'; $views_field['filter']['id'] = 'numeric'; $views_field['sort']['id'] = 'standard'; @@ -352,14 +352,14 @@ protected function mapSingleFieldViewsData($table, $field_name, $field_type, $co case 'text': case 'mediumtext': case 'longtext': - $views_field['field']['id'] = 'standard'; + $views_field['field']['id'] = 'field'; $views_field['argument']['id'] = 'string'; $views_field['filter']['id'] = 'string'; $views_field['sort']['id'] = 'standard'; break; default: - $views_field['field']['id'] = 'standard'; + $views_field['field']['id'] = 'field'; $views_field['argument']['id'] = 'standard'; $views_field['filter']['id'] = 'standard'; $views_field['sort']['id'] = 'standard'; @@ -430,13 +430,13 @@ protected function processViewsDataForEntityReference($table, FieldDefinitionInt 'title' => $entity_type->getLabel(), 'id' => 'standard', ]; - $views_field['field']['id'] = 'numeric'; + $views_field['field']['id'] = 'field'; $views_field['argument']['id'] = 'numeric'; $views_field['filter']['id'] = 'numeric'; $views_field['sort']['id'] = 'standard'; } else { - $views_field['field']['id'] = 'standard'; + $views_field['field']['id'] = 'field'; $views_field['argument']['id'] = 'string'; $views_field['filter']['id'] = 'string'; $views_field['sort']['id'] = 'standard'; @@ -466,7 +466,7 @@ protected function processViewsDataForTextLong($table, FieldDefinitionInterface // Connect the text field to its formatter. if ($field_column_name == 'value') { $views_field['field']['format'] = $field_definition->getName() . '__format'; - $views_field['field']['id'] = 'markup'; + $views_field['field']['id'] = 'field'; } } diff --git a/core/modules/views/src/Tests/GroupRowsTest.php b/core/modules/views/src/Tests/GroupRowsTest.php new file mode 100644 index 0000000..bb484a9 --- /dev/null +++ b/core/modules/views/src/Tests/GroupRowsTest.php @@ -0,0 +1,98 @@ +node_type = $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); + + // Create the unlimited text field. + $this->field_name = 'field_views_testing_group_rows'; + $this->field_storage = entity_create('field_storage_config', array( + 'field_name' => $this->field_name, + 'entity_type' => 'node', + 'type' => 'text', + 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, + )); + $this->field_storage->save(); + + // Create an instance of the text field on the content type. + $this->field = array( + 'field_storage' => $this->field_storage, + 'bundle' => $this->node_type->type, + ); + entity_create('field_config', $this->field)->save(); + + + $edit = array( + 'title' => $this->randomMachineName(), + $this->field_name => array('a', 'b', 'c'), + ); + $this->drupalCreateNode($edit); + } + + /** + * Testing when "Display all values in the same row" is checked. + */ + function testGroupRows() { + $this->drupalGet('test-group-rows'); + $result = $this->xpath('//div[contains(@class, "views-field-field-views-testing-group-")]/div'); + + $rendered_value = array(); + foreach ($result as $row) { + $rendered_value[] = (string) $row[0]; + } + $this->assertEqual(array('a, b, c'), $rendered_value); + } + + /** + * Testing when "Display all values in the same row" is unchecked. + */ + function testUngroupedRows() { + $this->drupalGet('test-ungroup-rows'); + $result = $this->xpath('//div[contains(@class, "views-field-field-views-testing-group-")]/div'); + $rendered_value = array(); + foreach ($result as $row) { + $rendered_value[] = (string) $row[0]; + } + $this->assertEqual(array('a', 'b', 'c'), $rendered_value); + } +} diff --git a/core/modules/views/src/Tests/ModuleTest.php b/core/modules/views/src/Tests/ModuleTest.php index 1f52a19..e801a09 100644 --- a/core/modules/views/src/Tests/ModuleTest.php +++ b/core/modules/views/src/Tests/ModuleTest.php @@ -30,7 +30,7 @@ class ModuleTest extends ViewUnitTestBase { * * @var array */ - public static $modules = array('user', 'block'); + public static $modules = ['field', 'user', 'block']; /** * Stores the last triggered error, for example via debug(). @@ -142,8 +142,8 @@ public function customErrorHandler($error_level, $message, $filename, $line, $co * Tests the load wrapper/helper functions. */ public function testLoadFunctions() { - $this->enableModules(array('node')); - $this->installConfig(array('node')); + $this->enableModules(['text', 'node']); + $this->installConfig(['node']); $storage = $this->container->get('entity.manager')->getStorage('view'); // Test views_view_is_enabled/disabled. diff --git a/core/modules/views/src/Tests/Plugin/BlockDependenciesTest.php b/core/modules/views/src/Tests/Plugin/BlockDependenciesTest.php index 37c71e7..b1f34e6 100644 --- a/core/modules/views/src/Tests/Plugin/BlockDependenciesTest.php +++ b/core/modules/views/src/Tests/Plugin/BlockDependenciesTest.php @@ -28,7 +28,7 @@ class BlockDependenciesTest extends ViewUnitTestBase { * * @var array */ - public static $modules = array('node', 'block', 'user'); + public static $modules = array('node', 'block', 'user', 'field'); /** * Tests that exposed filter blocks have the correct dependencies. diff --git a/core/modules/views/src/Tests/Wizard/ItemsPerPageTest.php b/core/modules/views/src/Tests/Wizard/ItemsPerPageTest.php index 946b3c9..054369a 100644 --- a/core/modules/views/src/Tests/Wizard/ItemsPerPageTest.php +++ b/core/modules/views/src/Tests/Wizard/ItemsPerPageTest.php @@ -7,6 +7,8 @@ namespace Drupal\views\Tests\Wizard; +use Drupal\views\Entity\View; + /** * Tests the ability of the views wizard to specify the number of items per * page. diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_dropbutton.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_dropbutton.yml index 3439017..040ba67 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_dropbutton.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_dropbutton.yml @@ -92,7 +92,7 @@ display: id: title table: node_field_data field: title - plugin_id: node + plugin_id: field label: '' alter: alter_text: false @@ -105,7 +105,9 @@ display: html: false hide_empty: false empty_zero: false - link_to_node: true + type: string + settings: + link_to_entity: false entity_type: node entity_field: title nothing: diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_group_rows.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_group_rows.yml index 588bc71..c5f17f0 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_group_rows.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_group_rows.yml @@ -4,6 +4,12 @@ dependencies: module: - field - node + config: + - field.storage.node.field_views_testing_group_rows + module: + - field + - node + - user id: test_group_rows label: test_group_rows module: views @@ -40,6 +46,17 @@ display: id: field_group_rows table: node__field_group_rows field: field_group_rows + title: + id: title + table: node_field_data + field: title + entity_type: node + entity_field: title + plugin_id: node + field_views_testing_group_: + id: field_views_testing_group_rows + table: node__field_views_testing_group_rows + field: field_views_testing_group_rows relationship: none group_type: group admin_label: '' @@ -102,3 +119,13 @@ display: field_langcode: '***LANGUAGE_language_content***' field_langcode_add_to_query: null display_extenders: { } + page_1: + display_options: + path: test-group-rows + field_langcode: '***LANGUAGE_language_content***' + field_langcode_add_to_query: null + display_extenders: { } + display_plugin: page + display_title: 'Page display' + id: page_1 + position: 1 diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_search.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_search.yml index a7729b1..02ac10a 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_search.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_search.yml @@ -73,7 +73,6 @@ display: html: false hide_empty: false empty_zero: false - link_to_node: true relationship: none group_type: group admin_label: '' @@ -89,9 +88,12 @@ display: element_default_classes: true empty: '' hide_alter_empty: true - plugin_id: node entity_type: node entity_field: title + plugin_id: field + type: string + settings: + link_to_entity: true filters: status: value: true diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tag_cache.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tag_cache.yml index 802f06f..e07eb18 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tag_cache.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tag_cache.yml @@ -53,10 +53,54 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - link_to_node: true - plugin_id: node + plugin_id: field entity_type: node entity_field: title + type: string + settings: + link_to_entity: true + plugin_id: field + filters: + type: + id: type + table: node_field_data + field: type + relationship: none + group_type: group + admin_label: '' + operator: in + value: + page: page + 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 + entity_type: node + entity_field: type group_by: true pager: type: some diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_group_rows.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_ungroup_rows.yml similarity index 73% copy from core/modules/views/tests/modules/views_test_config/test_views/views.view.test_group_rows.yml copy to core/modules/views/tests/modules/views_test_config/test_views/views.view.test_ungroup_rows.yml index 588bc71..cdb7303 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_group_rows.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_ungroup_rows.yml @@ -1,11 +1,14 @@ langcode: und status: true dependencies: + config: + - field.storage.node.field_views_testing_group_rows module: - field - node -id: test_group_rows -label: test_group_rows + - user +id: test_ungroup_rows +label: test_ungroup_rows module: views description: '' tag: '' @@ -36,10 +39,17 @@ display: row: type: fields fields: - field_group_rows: - id: field_group_rows - table: node__field_group_rows - field: field_group_rows + title: + id: title + table: node_field_data + field: title + entity_type: node + entity_field: title + plugin_id: node + field_views_testing_group_: + id: field_views_testing_group_rows + table: node__field_views_testing_group_rows + field: field_views_testing_group_rows relationship: none group_type: group admin_label: '' @@ -87,10 +97,10 @@ display: click_sort_column: value type: string settings: - link_to_entity: false + link_to_entity: '0' group_column: value group_columns: { } - group_rows: true + group_rows: false delta_limit: all delta_offset: '0' delta_reversed: false @@ -102,3 +112,13 @@ display: field_langcode: '***LANGUAGE_language_content***' field_langcode_add_to_query: null display_extenders: { } + page_1: + display_options: + path: test-ungroup-rows + field_langcode: '***LANGUAGE_language_content***' + field_langcode_add_to_query: null + display_extenders: { } + display_plugin: page + display_title: 'Page display' + id: page_1 + position: 1 diff --git a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php index c1aac0f..8f6fd5d 100644 --- a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php +++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php @@ -633,7 +633,7 @@ protected function assertField($data, $field_name) { * The views data to check. */ protected function assertStringField($data) { - $this->assertEquals('standard', $data['field']['id']); + $this->assertEquals('field', $data['field']['id']); $this->assertEquals('string', $data['filter']['id']); $this->assertEquals('string', $data['argument']['id']); $this->assertEquals('standard', $data['sort']['id']); @@ -646,7 +646,7 @@ protected function assertStringField($data) { * The views data to check. */ protected function assertUriField($data) { - $this->assertEquals('url', $data['field']['id']); + $this->assertEquals('field', $data['field']['id']); $this->assertEquals('string', $data['filter']['id']); $this->assertEquals('string', $data['argument']['id']); $this->assertEquals('standard', $data['sort']['id']); @@ -662,7 +662,7 @@ protected function assertUriField($data) { */ protected function assertLongTextField($data, $field_name) { $value_field = $data[$field_name . '__value']; - $this->assertEquals('markup', $value_field['field']['id']); + $this->assertEquals('field', $value_field['field']['id']); $this->assertEquals($field_name . '__format', $value_field['field']['format']); $this->assertEquals('string', $value_field['filter']['id']); $this->assertEquals('string', $value_field['argument']['id']); @@ -679,7 +679,7 @@ protected function assertLongTextField($data, $field_name) { */ protected function assertUuidField($data) { // @todo Can we provide additional support for UUIDs in views? - $this->assertEquals('standard', $data['field']['id']); + $this->assertEquals('field', $data['field']['id']); $this->assertEquals('string', $data['filter']['id']); $this->assertEquals('string', $data['argument']['id']); $this->assertEquals('standard', $data['sort']['id']); @@ -692,7 +692,7 @@ protected function assertUuidField($data) { * The views data to check. */ protected function assertNumericField($data) { - $this->assertEquals('numeric', $data['field']['id']); + $this->assertEquals('field', $data['field']['id']); $this->assertEquals('numeric', $data['filter']['id']); $this->assertEquals('numeric', $data['argument']['id']); $this->assertEquals('standard', $data['sort']['id']); @@ -705,7 +705,7 @@ protected function assertNumericField($data) { * The views data to check. */ protected function assertLanguageField($data) { - $this->assertEquals('language', $data['field']['id']); + $this->assertEquals('field', $data['field']['id']); $this->assertEquals('language', $data['filter']['id']); $this->assertEquals('language', $data['argument']['id']); $this->assertEquals('standard', $data['sort']['id']); @@ -715,7 +715,7 @@ protected function assertLanguageField($data) { * Tests views data for a entity reference field. */ protected function assertEntityReferenceField($data) { - $this->assertEquals('numeric', $data['field']['id']); + $this->assertEquals('field', $data['field']['id']); $this->assertEquals('numeric', $data['filter']['id']); $this->assertEquals('numeric', $data['argument']['id']); $this->assertEquals('standard', $data['sort']['id']); @@ -725,7 +725,7 @@ protected function assertEntityReferenceField($data) { * Tests views data for a bundle field. */ protected function assertBundleField($data) { - $this->assertEquals('standard', $data['field']['id']); + $this->assertEquals('field', $data['field']['id']); $this->assertEquals('bundle', $data['filter']['id']); $this->assertEquals('string', $data['argument']['id']); $this->assertEquals('standard', $data['sort']['id']); diff --git a/core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php b/core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php index 90ac97c..bf95b78 100644 --- a/core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php @@ -27,18 +27,8 @@ class FieldTest extends UnitTestCase { */ protected $entityManager; - /** - * The mocked formatter plugin manager. - * - * @var \Drupal\Core\Field\FormatterPluginManager|\PHPUnit_Framework_MockObject_MockObject - */ protected $formatterPluginManager; - /** - * The mocked language manager. - * - * @var \Drupal\Core\Language\LanguageManagerInterface|\PHPUnit_Framework_MockObject_MockObject - */ protected $languageManager; /** @@ -49,6 +39,13 @@ class FieldTest extends UnitTestCase { protected $fieldTypePluginManager; /** + * The mocked display plugin. + * + * @var \Drupal\views\Plugin\views\display\DisplayPluginBase|\PHPUnit_Framework_MockObject_MockObject + */ + protected $display; + + /** * The renderer. * * @var \Drupal\Core\Render\RendererInterface|\PHPUnit_Framework_MockObject_MockObject @@ -206,7 +203,7 @@ public function testCalculateDependenciesWithConfiguredField() { } /** - * @covers ::access() + * @covers ::access */ public function testAccess() { $definition = [ @@ -247,7 +244,8 @@ public function testAccess() { $access_control_handler->expects($this->atLeastOnce()) ->method('fieldAccess') - ->with('view', $this->anything(), $account, NULL, FALSE) + // @todo replace the second anything() with FALSE. + ->with('view', $this->anything(), $account, NULL, $this->anything()) ->willReturn(TRUE); $this->assertTrue($handler->access($account)); @@ -258,8 +256,6 @@ public function testAccess() { * * @param string $order * The sort order. - * - * @covers ::clickSort */ public function testClickSortWithOutConfiguredColumn($order) { $definition = [ @@ -280,8 +276,6 @@ public function testClickSortWithOutConfiguredColumn($order) { * * @param string $order * The sort order. - * - * @covers ::clickSort */ public function testClickSortWithBaseField($order) { $definition = [ @@ -340,8 +334,6 @@ public function testClickSortWithBaseField($order) { * * @param string $order * The sort order. - * - * @covers ::clickSort */ public function testClickSortWithConfiguredField($order) { $definition = [ @@ -395,9 +387,6 @@ public function testClickSortWithConfiguredField($order) { $handler->clickSort($order); } - /** - * @covers ::query - */ public function testQueryWithGroupByForBaseField() { $definition = [ 'entity_type' => 'test_entity', @@ -454,9 +443,6 @@ public function testQueryWithGroupByForBaseField() { $handler->query(TRUE); } - /** - * @covers ::query - */ public function testQueryWithGroupByForConfigField() { $definition = [ 'entity_type' => 'test_entity', @@ -514,8 +500,6 @@ public function testQueryWithGroupByForConfigField() { } /** - * Returns a mocked base field storage object. - * * @return \Drupal\Core\Field\FieldStorageDefinitionInterface|\PHPUnit_Framework_MockObject_MockObject */ protected function getBaseFieldStorage() { @@ -533,8 +517,6 @@ protected function getBaseFieldStorage() { } /** - * Returns a mocked configurable field storage object. - * * @return \Drupal\field\FieldStorageConfigInterface|\PHPUnit_Framework_MockObject_MockObject */ protected function getConfigFieldStorage() { @@ -551,11 +533,6 @@ protected function getConfigFieldStorage() { return $title_storage; } - /** - * Provides sort orders for clickSort() test methods. - * - * @return array - */ public function providerSortOrders() { return [ ['asc'], @@ -566,3 +543,4 @@ public function providerSortOrders() { } } +