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 8d6fe06..a475017 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 @@ -402,7 +402,12 @@ function use_string_group_by() { 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->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 ee8081d..15e8919 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 @@ -80,6 +80,13 @@ protected $usesFields = FALSE; /** + * Should field labels be enabled by default. + * + * @var bool + */ + protected $defaultFieldLabels = FALSE; + + /** * Initialize a style plugin. * * @param $view @@ -172,6 +179,15 @@ function uses_tokens() { } /** + * 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. */ function get_row_class($row_index) { diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/FieldTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/FieldTest.php index 967eae8..995a5fb 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Handler/FieldTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/FieldTest.php @@ -385,6 +385,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(); $this->assertFalse($this->xpathContent($output, '//div[contains(@class, :class)]', array(':class' => 'field-content'))); $this->assertFalse($this->xpathContent($output, '//div[contains(@class, :class)]', array(':class' => 'field-label'))); 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 108e683..d4a4557 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTest.php @@ -87,12 +87,14 @@ function testGroupingLegacy() { 'table' => 'views_test_data', 'field' => 'name', 'relationship' => 'none', + 'label' => 'Name', ), 'job' => array( 'id' => 'job', 'table' => 'views_test_data', 'field' => 'job', 'relationship' => 'none', + 'label' => 'Job', ), )); @@ -186,18 +188,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', ), )); diff --git a/core/modules/views/tests/views_test_data/config/views.view.test_click_sort.yml b/core/modules/views/tests/views_test_data/config/views.view.test_click_sort.yml index 8aa2eb2..f49ce59 100644 --- a/core/modules/views/tests/views_test_data/config/views.view.test_click_sort.yml +++ b/core/modules/views/tests/views_test_data/config/views.view.test_click_sort.yml @@ -11,14 +11,17 @@ display: id: id table: views_test_data field: id + label: ID name: id: name table: views_test_data field: name + label: Name created: id: created table: views_test_data field: created + label: Created display_options: access: type: none