Commit 4a9c76ab authored by alexpott's avatar alexpott

Issue #2399263 by SpadXIII: Table format combine fields into single column shows only one field

parent 211db405
......@@ -77,4 +77,36 @@ public function testAccessibilitySettings() {
$this->assertFalse(count($result), 'Ensure that the description disappears.');
}
/**
* Test table fields in columns.
*/
public function testFieldInColumns() {
$this->drupalGet('test-table');
// Ensure that both columns are in separate tds.
// Check for class " views-field-job ", because just "views-field-job" won't
// do: "views-field-job-1" would also contain "views-field-job".
// @see Drupal\system\Tests\Form\ElementTest::testButtonClasses().
$result = $this->xpath('//tbody/tr/td[contains(concat(" ", @class, " "), " views-field-job ")]');
$this->assertTrue(count($result), 'Ensure there is a td with the class views-field-job');
$result = $this->xpath('//tbody/tr/td[contains(concat(" ", @class, " "), " views-field-job-1 ")]');
$this->assertTrue(count($result), 'Ensure there is a td with the class views-field-job-1');
// Combine the second job-column with the first one, with ', ' as separator.
$view = entity_load('view', 'test_table');
$display = &$view->getDisplay('default');
$display['display_options']['style']['options']['columns']['job_1'] = 'job';
$display['display_options']['style']['options']['info']['job']['separator'] = ', ';
$view->save();
// Ensure that both columns are properly combined.
$this->drupalGet('test-table');
$result = $this->xpath('//tbody/tr/td[contains(concat(" ", @class, " "), " views-field-job views-field-job-1 ")]');
$this->assertTrue(count($result), 'Ensure that the job column class names are joined into a single column');
$result = $this->xpath('//tbody/tr/td[contains(., "Drummer, Drummer")]');
$this->assertTrue(count($result), 'Ensure the job column values are joined into a single column');
}
}
......@@ -35,6 +35,18 @@ display:
relationship: none
table: views_test_data
plugin_id: string
job:
field: job
id: job
relationship: none
table: views_test_data
plugin_id: string
job_1:
field: job
id: job_1
relationship: none
table: views_test_data
plugin_id: string
pager:
options:
offset: 0
......@@ -60,6 +72,8 @@ display:
age: age
id: id
name: name
job: job
job_1: job_1
info:
age:
sortable: false
......@@ -82,6 +96,20 @@ display:
separator: ''
empty_column: false
responsive: ''
job:
sortable: true
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
job_1:
sortable: true
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
default: id
empty_table: true
caption: caption-text
......
......@@ -545,7 +545,9 @@ function template_preprocess_views_view_table(&$variables) {
$column_reference =& $variables['rows'][$num]['columns'][$column];
// Add field classes.
$column_reference['attributes'] = array();
if (!isset($column_reference['attributes'])) {
$column_reference['attributes'] = array();
}
if ($fields[$field]->options['element_default_classes']) {
$column_reference['attributes']['class'][] = 'views-field';
$column_reference['attributes']['class'][] = 'views-field-' . $variables['fields'][$field];
......@@ -573,7 +575,7 @@ function template_preprocess_views_view_table(&$variables) {
}
// Only bother with separators and stuff if the field shows up.
if (!empty($field_output) && empty($column_reference['content'])) {
if (!empty($field_output)) {
// Place the field into the column, along with an optional separator.
if (!empty($column_reference['content'])) {
if (!empty($options['info'][$column]['separator'])) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment