Problem/Motivation
- Create a view with an "Embed" display.
- Attempt to render the embedded view using the following code:
$variables['my_embedded_view'] = array( '#type' => 'view', '#name' => 'example_view', '#display_id' => 'embed_display', '#arguments' => array(), );
This leads to a fatal error: Unsupported operand types in core/modules/views/src/Element/View.php (line 63). This error is caused by ViewsExecutable::executeDisplay(), which returns NULL for Embed display plugins.
Now, the View render element already defines an #embed variable, which looks like it is supposed to render the view via preview() instead of execute().
So it looks like this should work:
$variables['my_embedded_view'] = array(
'#type' => 'view',
'#name' => 'example_view',
'#display_id' => 'embed_display',
'#arguments' => array(),
'#embed' => TRUE,
);
Unfortunately, this does not work either, because the code which is supposed to detect whether #embed is not empty references embed instead.
The following works, but produces the following user error: "embed" is an invalid render array key.
$variables['my_embedded_view'] = array(
'#type' => 'view',
'#name' => 'example_view',
'#display_id' => 'embed_display',
'#arguments' => array(),
'embed' => TRUE,
);
Proposed resolution
- Make the '#embed' variable work.
Remaining tasks
[todo]
User interface changes
None.
API changes
None.
Beta phase evaluation
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | views_render_element-2389275-15.patch | 8.93 KB | bforchhammer |
Comments
Comment #1
bforchhammer commentedComment #2
bforchhammer commentedComment #3
dawehnerOOOH, this fix is absolute right. In general though I think #embed should be TRUE by default.
Comment #4
bforchhammer commentedEasily changed. Works for me :)
Comment #5
dawehnerWell, I guess that we might have to change some of the usecases of the existing #type view?
ViewElementTest ... that one should afaik used once with and once without #embed?
ViewsTestDataElementForm probably needs to switch
Comment #6
bforchhammer commentedIn core
#embedis only used once inDisplayPluginBaseat the moment. Tests don't reference it, and apparently we currently don't check for the differences betweenpreview()andexecuteDisplay(), so tests are still green.I have duplicated the
ViewElementTestfor both cases, i.e. the default display and#embed = FALSE, as well as an embed display and$embed = TRUE.Comment #7
bforchhammer commentedHm, here we go.
Comment #9
bforchhammer commentedLet's try this again...
Comment #11
bforchhammer commentedAnd again...
Comment #13
bforchhammer commentedComment #14
dawehner@bforchhammer
Can you reroll the latest patch against HEAD and not some arbitrary commit :)
Comment #15
bforchhammer commentedWhoops, my bad. ;-)
Comment #16
dawehnerAlright, perfect!
Comment #17
alexpottThis issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 1c61006 and pushed to 8.0.x. Thanks!