views/includes/plugins.inc describes an 'embed' display whose handler is 'views_plugin_display_embed'. However, this class is not defined anywhere.

This is causing slightly more trouble than one would expect, since it breaks the embed_views module (which also describes an embed display that actually works).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

seddonym’s picture

See my comment here for how it affects the embed_views module, and a workaround.

dawehner’s picture

Assigned: Unassigned » dawehner

Oh i forgot to add this file to views, hopefully i can find it on one of my last harddiscs.

I'm sorry for that

grndlvl’s picture

Any news on this? Due to naming conventions(I didn't prefix the display name) this currently breaks embed_views' embed displays #1454426: Not working with Views 3.2+. I am hoping that with this being in views core, people may just be able to uninstall the embed_views module and it should "just work" with the exception of some of the additional features such as exposed filters to block and embed exposed filters separate from view.

seddonym’s picture

emcniece’s picture

ended up using panels instead.

trigdog’s picture

@dawehner,
any progress on this?

dawehner’s picture

I searched for quite a while, though i couldn't find it, so i will try to rewrite the file.

I'm really sorry for that.

joachim’s picture

Status: Active » Needs work
FileSize
792 bytes

I tried having a go at this as I didn't think it could be that complicated.

Yet this is not showing any output when I try and preview and embed display. I'm not sure what I've missed off as I based this on the block display class, but without the block-related methods....

Hopefully someone else can spot the obvious mistake! ;)

DanChadwick’s picture

Status: Needs work » Needs review
FileSize
1.48 KB

@joachim- you are very close. You are missing the theme.

I used the block display code since it contains the title. The definition of the plug-in also needs a theme (same theme as page, block, etc ... views_view. Also note that when calling views_embed_view that the display name you pass is NOT the human name seen in the views ui. Instead, edit the display and look at the URL. They are of the form embed_X, starting with embed_1.

The attached patch simply adds a nearly-trivial display plug-in and adds the missing theme specification.

DanChadwick’s picture

Ooops. Missed one 'block -> embed' change in a comment.

usmith’s picture

Thanks so much for this patch! It works great from a Rules action! And a node's Body field using PHP format.

dawehner’s picture

Status: Needs review » Needs work
+++ b/plugins/views_plugin_display_embed.incundefined
@@ -0,0 +1,28 @@
+  function execute() {
+    // Prior to this being called, the $view should already be set to this
+    // display, and arguments should be set on the view.
+    $info['theme'] = 'views_view';
+    $info['content'] = $this->view->render();
+    $info['subject'] = filter_xss_admin($this->view->get_title());
+    if (!empty($this->view->result) || $this->get_option('empty') || !empty($this->view->style_plugin->definition['even empty'])) {
+      return $info;

I don't really get why this should return a block like structure ...

DanChadwick’s picture

@dawehner: Why should it not return something with a title and the contents? The UI allows the specification of a title for the display. Are you saying that it should just return the view without any title? If someone doesn't want a title, they can make it blank, no?

dawehner’s picture

Well it is an embed display so you should know what you want to do with the title. From my perspective all you should do is to render out the actual content.

DanChadwick’s picture

How about if the title is empty, return just the rendered data; if it isn't, return the block? Best of both worlds, and hardly any more code.

If you like this, I'll tweak the patch and repost it.

If not, I'll code it your way and post it, but I won't be able to use it myself.

dawehner’s picture

In general i would go with the route of views embed display module, which really just returns the rendered view.

I'm not sure but how does the current patch works, doesn't this return an array instead of a string? This is really confusing for me :)
If the developer wants to have the title he can use the $view object anyway.

DanChadwick’s picture

The current patch returns a render array, which is rendered by the theme function.

dawehner’s picture

Ups, what about adding an option whether to add a title or not and default to FALSE?

joachim’s picture

Having an embedded view output a title doesn't always make sense. But if it doesn't make sense, just set the title blank: I would say that is the equivalent of 'whether to output the title or not'.

On the other hand, there are lots of times when you DO want a title on your embedded view. Having to output the title yourself means that you can't have it stored in the view's settings.

DanChadwick’s picture

Status: Needs work » Active

Hmm. Views is quite a bit more complicated that I thought. It turns out that the display execute method is not called via views_embed_view. Instead it calls the theme function (which must be defined) and the general views theme template does the work. I'm not sure in what situations execute is actually called.

So I could remove the execute and resubmit the patch, which would be just the theme => 'views_view' and an empty class declaration. Seems silly and possibly incomplete.

So for my application, I've just used the 'default' display. You can only have one, but maybe someone more knowledgeable than I about the views hierarchy can submit a patch for what should (or should not) be in the embed display.

joachim’s picture

Status: Active » Needs work

Should still be 'needs work' as there's a patch here. Thanks for your work on getting it this far! :)

joachim’s picture

Status: Needs work » Needs review
FileSize
992 bytes

AFAICT execute() is a bit of a funny one. Displays execute, but so does the whole view... execute() by the looks of it is where things like setting the page title happen, so it's meant for displays that have some sort of interaction with the rest of Drupal.

At any rate, what gets called by views_embed_view() is preview() then render().

However, this won't work right:

    $info['theme'] = 'views_view';
    $info['content'] = $this->view->render();
    $info['subject'] = filter_xss_admin($this->view->get_title());

Firstly, we can't just say our theme function is views_view -- we have to respect the hierarchy of theme functions that you get from $this->theme_functions().

Second, we can't return a build array -- views_embed_view() returns HTML and so we render() must do so too.

Third, we can't force the view to show its title at this point, because template_preprocess_views_view() will override what we do here:

  $vars['title'] = !empty($view->views_ui_context) ? filter_xss_admin($view->get_title()) : '';

And if you try to force it by setting $view->views_ui_context, you get output that is intended for the Views admin UI: it says 'title' and 'content' in huge headings -- so no good here.

Which kind of decides the question of whether to include the title or not, too. The docs for that say:

> Note that this function does NOT display the title of the view. If you want to do that, you will need to do what this function does manually, by loading the view, getting the preview and then getting $view->get_title().

So we really can't change that, because then we'd have a DX WTF where some display types return a title and some don't.

Therefore I think the right thing for this plugin is to do nothing.

And if we want to be able to retrieve an embed display WITH its title, we need a new function like views_embed_view(). And it's possibly up to http://drupal.org/project/embed_views to provide that :)

Patch attached :)

grndlvl’s picture

Status: Needs review » Reviewed & tested by the community

Agreed.

Tested and works as advertised. Templates work as well.

Added a new issue for the title over @ embed_views if you have additional input on the topic post to the issue #1685360: Add a helper function similar to views_embed_view() that adds views title.

dawehner’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the hard work and sorry for this stupid mistake of myself again.

Committed to 7.x-3.x and 8.x-3.x

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.