Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
561b42ce
Commit
561b42ce
authored
Jan 04, 2016
by
Nathaniel Catchpole
Browse files
Issue
#2302319
by geertvd, Lendude: Missing caption, if view (format table) is grouped by a field
parent
27daa8c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/modules/views/src/Tests/Plugin/StyleTableTest.php
View file @
561b42ce
...
...
@@ -155,4 +155,80 @@ public function testEmptyColumn() {
$this
->
assertEqual
(
count
(
$result
),
0
,
'Ensure the empty table cells are hidden.'
);
}
/**
* Tests grouping by a field.
*/
public
function
testGrouping
()
{
/** @var \Drupal\views\ViewEntityInterface $view */
$view
=
\
Drupal
::
entityTypeManager
()
->
getStorage
(
'view'
)
->
load
(
'test_table'
);
// Get a reference to the display configuration so we can alter some
// specific style options.
$display
=
&
$view
->
getDisplay
(
'default'
);
// Set job as the grouping field.
$display
[
'display_options'
][
'style'
][
'options'
][
'grouping'
][
0
]
=
array
(
'field'
=>
'job'
,
'rendered'
=>
TRUE
,
'rendered_strip'
=>
FALSE
,
);
// Clear the caption text, the rendered job field will be used as a caption.
$display
[
'display_options'
][
'style'
][
'options'
][
'caption'
]
=
''
;
$display
[
'display_options'
][
'style'
][
'options'
][
'summary'
]
=
''
;
$display
[
'display_options'
][
'style'
][
'options'
][
'description'
]
=
''
;
$view
->
save
();
// Add a record containing unsafe markup to be sure it's filtered out.
$unsafe_markup
=
'<script>alert("Rapper");</script>'
;
$unsafe_markup_data
=
array
(
'name'
=>
'Marshall'
,
'age'
=>
42
,
'job'
=>
$unsafe_markup
,
'created'
=>
gmmktime
(
0
,
0
,
0
,
2
,
15
,
2001
),
'status'
=>
1
,
);
$database
=
$this
->
container
->
get
(
'database'
);
$database
->
insert
(
'views_test_data'
)
->
fields
(
array_keys
(
$unsafe_markup_data
))
->
values
(
$unsafe_markup_data
)
->
execute
();
$this
->
drupalGet
(
'test-table'
);
$expected_captions
=
array
(
'Job: Speaker'
,
'Job: Songwriter'
,
'Job: Drummer'
,
'Job: Singer'
,
'Job: '
.
$unsafe_markup
,
);
// Ensure that we don't find the caption containing unsafe markup.
$this
->
assertNoRaw
(
$unsafe_markup
,
"Didn't find caption containing unsafe markup."
);
// Ensure that all expected captions are found.
foreach
(
$expected_captions
as
$raw_caption
)
{
$this
->
assertEscaped
(
$raw_caption
);
}
$display
=
&
$view
->
getDisplay
(
'default'
);
// Remove the label from the grouping field.
$display
[
'display_options'
][
'fields'
][
'job'
][
'label'
]
=
''
;
$view
->
save
();
$this
->
drupalGet
(
'test-table'
);
$expected_captions
=
array
(
'Speaker'
,
'Songwriter'
,
'Drummer'
,
'Singer'
,
$unsafe_markup
,
);
// Ensure that we don't find the caption containing unsafe markup.
$this
->
assertNoRaw
(
$unsafe_markup
,
"Didn't find caption containing unsafe markup."
);
// Ensure that all expected captions are found.
foreach
(
$expected_captions
as
$raw_caption
)
{
$this
->
assertEscaped
(
$raw_caption
);
}
}
}
core/modules/views/views.theme.inc
View file @
561b42ce
...
...
@@ -598,6 +598,10 @@ function template_preprocess_views_view_table(&$variables) {
$variables
[
'caption'
]
=
[
'#markup'
=>
$handler
->
options
[
'caption'
]];
$variables
[
'caption_needed'
]
=
TRUE
;
}
elseif
(
!
empty
(
$variables
[
'title'
]))
{
$variables
[
'caption'
]
=
[
'#markup'
=>
$variables
[
'title'
]];
$variables
[
'caption_needed'
]
=
TRUE
;
}
else
{
$variables
[
'caption'
]
=
''
;
$variables
[
'caption_needed'
]
=
FALSE
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment