Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
0c24732c
Commit
0c24732c
authored
8 years ago
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2711973
by Berdir: buildRenderable() does not work with display plugin embed
parent
ef6c84db
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/modules/views/src/Plugin/views/display/Embed.php
+8
-1
8 additions, 1 deletion
core/modules/views/src/Plugin/views/display/Embed.php
core/modules/views/src/Tests/ViewElementTest.php
+13
-32
13 additions, 32 deletions
core/modules/views/src/Tests/ViewElementTest.php
with
21 additions
and
33 deletions
core/modules/views/src/Plugin/views/display/Embed.php
+
8
−
1
View file @
0c24732c
...
...
@@ -20,6 +20,13 @@
*/
class
Embed
extends
DisplayPluginBase
{
// This display plugin does nothing apart from exist.
/**
* {@inheritdoc}
*/
public
function
buildRenderable
(
array
$args
=
[],
$cache
=
TRUE
)
{
$build
=
parent
::
buildRenderable
(
$args
,
$cache
);
$build
[
'#embed'
]
=
TRUE
;
return
$build
;
}
}
This diff is collapsed.
Click to expand it.
core/modules/views/src/Tests/ViewElementTest.php
+
13
−
32
View file @
0c24732c
...
...
@@ -18,29 +18,10 @@ class ViewElementTest extends ViewTestBase {
*/
public
static
$testViews
=
array
(
'test_view_embed'
);
/**
* The raw render data array to use in tests.
*
* @var array
*/
protected
$render
;
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
enableViewsTestModule
();
// Set up a render array to use. We need to copy this as drupal_render
// passes by reference.
$this
->
render
=
array
(
'view'
=>
array
(
'#type'
=>
'view'
,
'#name'
=>
'test_view_embed'
,
'#display_id'
=>
'default'
,
'#arguments'
=>
array
(
25
),
'#embed'
=>
FALSE
,
),
);
}
/**
...
...
@@ -50,10 +31,11 @@ public function testViewElement() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer
=
$this
->
container
->
get
(
'renderer'
);
$view
=
Views
::
getView
(
'test_view_embed'
);
$view
->
setDisplay
();
// Set the content as our rendered array.
$render
=
$this
->
render
;
// Get the render array, #embed must be FALSE since this is the default
// display.
$render
=
$view
->
buildRenderable
();
$this
->
assertEqual
(
$render
[
'#embed'
],
FALSE
);
$this
->
setRawContent
(
$renderer
->
renderRoot
(
$render
));
$xpath
=
$this
->
xpath
(
'//div[@class="views-element-container"]'
);
...
...
@@ -98,7 +80,8 @@ public function testViewElement() {
$view
->
save
();
// Test the render array again.
$render
=
$this
->
render
;
$view
=
Views
::
getView
(
'test_view_embed'
);
$render
=
$view
->
buildRenderable
(
NULL
,
[
25
]);
$this
->
setRawContent
(
$renderer
->
renderRoot
(
$render
));
// There should be 1 row in the results, 'John' arg 25.
$xpath
=
$this
->
xpath
(
'//div[@class="view-content"]/div'
);
...
...
@@ -118,11 +101,10 @@ public function testViewElementEmbed() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer
=
$this
->
container
->
get
(
'renderer'
);
$view
=
Views
::
getView
(
'test_view_embed'
);
$view
->
setDisplay
(
'embed_1'
);
//
S
et the
content as our rendered arr
ay.
$render
=
$
this
->
render
;
$
render
[
'view'
]
[
'#embed'
]
=
TRUE
;
//
G
et the
render array, #embed must be TRUE since this is an embed displ
ay.
$render
=
$
view
->
buildRenderable
(
'embed_1'
)
;
$
this
->
assertEqual
(
$render
[
'#embed'
]
,
TRUE
)
;
$this
->
setRawContent
(
$renderer
->
renderRoot
(
$render
));
$xpath
=
$this
->
xpath
(
'//div[@class="views-element-container"]'
);
...
...
@@ -167,8 +149,8 @@ public function testViewElementEmbed() {
$view
->
save
();
// Test the render array again.
$
render
=
$this
->
render
;
$render
[
'view'
][
'#embed'
]
=
TRUE
;
$
view
=
Views
::
getView
(
'test_view_embed'
)
;
$render
=
$view
->
buildRenderable
(
'embed_1'
,
[
25
])
;
$this
->
setRawContent
(
$renderer
->
renderRoot
(
$render
));
// There should be 1 row in the results, 'John' arg 25.
$xpath
=
$this
->
xpath
(
'//div[@class="view-content"]/div'
);
...
...
@@ -180,9 +162,8 @@ public function testViewElementEmbed() {
$this
->
assertEqual
(
count
(
$xpath
),
1
);
// Tests the render array with an exposed filter.
$render
=
$this
->
render
;
$render
[
'view'
][
'#display_id'
]
=
'embed_2'
;
$render
[
'view'
][
'#embed'
]
=
TRUE
;
$view
=
Views
::
getView
(
'test_view_embed'
);
$render
=
$view
->
buildRenderable
(
'embed_2'
);
$this
->
setRawContent
(
$renderer
->
renderRoot
(
$render
));
// Ensure that the exposed form is rendered.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment