diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php index 25c28a8..6eaa5d4 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php @@ -410,7 +410,16 @@ public function useStringGroupBy() { protected function defineOptions() { $options = parent::defineOptions(); - $options['label'] = array('default' => $this->definition['title'], 'translatable' => TRUE); + $options['label'] = array('default' => '', 'translatable' => TRUE); + // Some styles (for example table) should have field labels enabled by + // default. + if (!isset($this->view->style_plugin)) { + $this->view->initStyle(); + } + + if (isset($this->view->style_plugin) && $this->view->style_plugin->defaultFieldLabels()) { + $options['label']['default'] = $this->definition['title']; + } $options['exclude'] = array('default' => FALSE, 'bool' => TRUE); $options['alter'] = array( 'contains' => array( diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/style/StylePluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/style/StylePluginBase.php index 68cdc5a..f0da4d4 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/style/StylePluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/style/StylePluginBase.php @@ -93,6 +93,13 @@ * @see StylePluginBase::renderGroupingSets() */ protected $groupingTheme = 'views_view_grouping'; + + /** + * Should field labels be enabled by default. + * + * @var bool + */ + protected $defaultFieldLabels = FALSE; /** * Overrides \Drupal\views\Plugin\views\PluginBase::init(). @@ -180,6 +187,15 @@ public function usesTokens() { } /** + * Return TRUE if this style enables field labels by default. + * + * @return bool + */ + public function defaultFieldLabels() { + return $this->defaultFieldLabels; + } + + /** * Return the token replaced row class for the specified row. */ public function getRowClass($row_index) { diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/style/Table.php b/core/modules/views/lib/Drupal/views/Plugin/views/style/Table.php index 121047a..4e326c3 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/style/Table.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/style/Table.php @@ -51,6 +51,13 @@ class Table extends StylePluginBase { protected $usesRowClass = TRUE; /** + * Should field labels be enabled by default. + * + * @var bool + */ + protected $defaultFieldLabels = TRUE; + + /** * Contains the current active sort column. * @var string */ diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php index 6d73636..3d23801 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/FieldWebTest.php @@ -330,6 +330,8 @@ public function testFieldClasses() { $id_field = $view->field['id']; $id_field->options['element_default_classes'] = FALSE; + // Setup some kind of label by default. + $id_field->options['label'] = $this->randomName(); $output = $view->preview(); $output = drupal_render($output); $this->assertFalse($this->xpathContent($output, '//div[contains(@class, :class)]', array(':class' => 'field-content'))); diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTest.php index 13335e6..c5e98be 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTest.php @@ -127,18 +127,21 @@ function _testGrouping($stripped = FALSE) { 'table' => 'views_test_data', 'field' => 'name', 'relationship' => 'none', + 'label' => 'Name', ), 'job' => array( 'id' => 'job', 'table' => 'views_test_data', 'field' => 'job', 'relationship' => 'none', + 'label' => 'Job', ), 'age' => array( 'id' => 'age', 'table' => 'views_test_data', 'field' => 'age', 'relationship' => 'none', + 'label' => 'Age', ), )); @@ -197,6 +200,8 @@ function _testGrouping($stripped = FALSE) { // The newer api passes the value of the grouping as well. $sets_new_rendered = $view->style_plugin->renderGrouping($view->result, $view->style_plugin->options['grouping'], TRUE); + debug($sets_new_rendered); + debug($expected); $this->assertEqual($sets_new_rendered, $expected, 'The style plugins should properly group the results with grouping by the rendered output.'); // Don't test stripped case, because the actual value is not stripped. diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_click_sort.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_click_sort.yml index 2dfc632..9101617 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_click_sort.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_click_sort.yml @@ -10,18 +10,21 @@ display: id: id table: views_test_data field: id + label: ID plugin_id: numeric provider: views_test_data name: id: name table: views_test_data field: name + label: Name plugin_id: string provider: views_test_data created: id: created table: views_test_data field: created + label: created plugin_id: date provider: views_test_data display_options: diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_views_groupby_save.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_views_groupby_save.yml index e17bdf4..400562d 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_views_groupby_save.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_views_groupby_save.yml @@ -14,7 +14,7 @@ display: pager: type: none style: - type: default + type: table row: type: fields fields: diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Tests/FieldUITest.php b/core/modules/views_ui/lib/Drupal/views_ui/Tests/FieldUITest.php index 725ccd9..04bbe40 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Tests/FieldUITest.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Tests/FieldUITest.php @@ -33,16 +33,39 @@ public static function getInfo() { * Tests the UI of field handlers. */ public function testFieldUI() { + $view_name = 'test_view'; // Ensure the field is not marked as hidden on the first run. - $this->drupalGet('admin/structure/views/view/test_view/edit'); - $this->assertText('Views test: Name (Name)'); - $this->assertNoText('Views test: Name (Name) [' . t('hidden') . ']'); + $this->drupalGet('admin/structure/views/view/' . $view_name . '/edit'); + $this->assertText('Views test: Name'); + $this->assertNoText('Views test: Name [' . t('hidden') . ']'); // Hides the field and check whether the hidden label is appended. - $edit_handler_url = 'admin/structure/views/nojs/config-item/test_view/default/field/name'; + $edit_handler_url = 'admin/structure/views/nojs/config-item/' . $view_name . '/default/field/name'; $this->drupalPostForm($edit_handler_url, array('options[exclude]' => TRUE), t('Apply')); - $this->assertText('Views test: Name (Name) [' . t('hidden') . ']'); + $this->assertText('Views test: Name [' . t('hidden') . ']'); + } + + /** + * Tests the field labels. + */ + public function testFieldLabel() { + // Create a view with unformatted style and make sure the fields have no + // labels by default. + $view = array(); + $view['label'] = $this->randomName(16); + $view['id'] = strtolower($this->randomName(16)); + $view['description'] = $this->randomName(16); + $view['show[wizard_key]'] = 'node'; + $view['page[create]'] = TRUE; + $view['page[style][style_plugin]'] = 'default'; + $view['page[title]'] = $this->randomName(16); + $view['page[path]'] = $view['id']; + $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit')); + + $view = views_get_view($view['id']); + $view->initHandlers(); + $this->assertEqual($view->field['title']->options['label'], '', 'The field label for normal styles are empty.'); } } diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Tests/StyleTableTest.php b/core/modules/views_ui/lib/Drupal/views_ui/Tests/StyleTableTest.php new file mode 100644 index 0000000..200be8a --- /dev/null +++ b/core/modules/views_ui/lib/Drupal/views_ui/Tests/StyleTableTest.php @@ -0,0 +1,45 @@ + 'Style: Table UI', + 'description' => 'Tests the UI of views when using the table style.', + 'group' => 'Views UI', + ); + } + + /** + * Tests created a table style view. + */ + public function testWizard() { + // Create a new view and check that the first field has a label. + $view = array(); + $view['label'] = $this->randomName(16); + $view['id'] = strtolower($this->randomName(16)); + $view['show[wizard_key]'] = 'node'; + $view['page[create]'] = TRUE; + $view['page[style][style_plugin]'] = 'table'; + $view['page[title]'] = $this->randomName(16); + $view['page[path]'] = $view['id']; + $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit')); + + $view = views_get_view($view['id']); + $view->initHandlers(); + $this->assertEqual($view->field['title']->options['label'], 'Title', 'The field label for table styles is not empty.'); + } + +}