diff -u b/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php --- b/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/field/FieldPluginBase.php @@ -405,7 +405,10 @@ $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()) { + if (!isset($this->view->style_plugin)) { + $this->view->initStyle(); + } + if ($this->view->style_plugin->defaultFieldLabels()) { $options['label']['default'] = $this->definition['title']; } $options['exclude'] = array('default' => FALSE, 'bool' => TRUE); only in patch2: unchanged: --- a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php @@ -89,8 +89,9 @@ public function __construct(array $configuration, $plugin_id, DiscoveryInterface * based upon the type of handler. */ public function init(ViewExecutable $view, &$options) { + $this->view = $view; $this->setOptionDefaults($this->options, $this->defineOptions()); - $this->view = &$view; + $display_id = $this->view->current_display; // Check to see if this handler type is defaulted. Note that // we have to do a lookup because the type is singular but the only in patch2: unchanged: --- a/core/modules/views/lib/Drupal/views/Plugin/views/style/Table.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/style/Table.php @@ -48,6 +48,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 */ only in patch2: unchanged: --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Tests/UI/FieldTest.php @@ -0,0 +1,44 @@ + 'Field UI', + 'description' => 'Tests the UI of field handlers.', + 'group' => 'Views UI', + ); + } + + /** + * 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['human_name'] = $this->randomName(16); + $view['name'] = strtolower($this->randomName(16)); + $view['show[wizard_key]'] = 'node'; + $view['page[create]'] = TRUE; + $view['page[style][style_plugin]'] = 'default'; + $view['page[path]'] = $view['name']; + $this->drupalPost('admin/structure/views/add', $view, t('Save & exit')); + + $view = views_get_view($view['name']); + $view->initHandlers(); + $this->assertEqual($view->field['title']->options['label'], '', 'The field label for normal styles are empty.'); + } +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Tests/UI/StyleTableTest.php @@ -0,0 +1,44 @@ + '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['human_name'] = $this->randomName(16); + $view['name'] = strtolower($this->randomName(16)); + $view['show[wizard_key]'] = 'node'; + $view['page[create]'] = TRUE; + $view['page[style][style_plugin]'] = 'table'; + $view['page[path]'] = $view['name']; + $this->drupalPost('admin/structure/views/add', $view, t('Save & exit')); + + $view = views_get_view($view['name']); + $view->initHandlers(); + $this->assertEqual($view->field['title']->options['label'], 'Title', 'The field label for table styles is not empty.'); + } + +}