I'm running Drupal 8.03 with PHP module added. Other PHP works.

I'm trying to call a view (this is simplified) like this:

===============================
print views_embed_view('view_name', 'embed_1');
===============================

The result? I get a page that says "array" but nothing else. Certainly not the view.

Some version of this worked fine in Drupal 6. Based on other articles, this should work in Drupal 8. What am I doing wrong?

Novice task

Fix the documentation for views_embed_view() so that it contains a @return tag similar/identical to the one in ViewExecutable::preview()

See
https://api.drupal.org/api/drupal/core!modules!views!src!ViewExecutable....

CommentFileSizeAuthor
#5 views_embed_view_does-2670726-5.patch675 bytesborisson_

Comments

jnimchuk created an issue. See original summary.

swentel’s picture

Category: Bug report » Support request
veerasekar89’s picture

Assigned: Unassigned » veerasekar89
Issue tags: +Drupalcon Asia 2016
jhodgdon’s picture

Title: views_embed_view() not working » views_embed_view() does not document return value
Category: Support request » Bug report
Issue summary: View changes
Issue tags: +Novice

Unfortunately, the views_embed_view() function doesn't have good documentation, as it does not tell what the return value is.

If you look at what the function does, however, you'll see that it creates a ViewExecutable object, and then calls the preview() method on it
https://api.drupal.org/api/drupal/core!modules!views!src!ViewExecutable....

This method returns a render array, not a string. So you'll need to render it.

I'm changing this to a novice documentation bug issue, and adding a note to the issue summary about what we need to do to fix the docs.

Meanwhile... If you need further programming support, please note that although you can create issues in Drupal Core and mark the category as "support request", we don't really handle support requests in the Drupal Core issue queue as a regular practice (that option is mostly there for filing support issues for contributed modules and themes).

There are several support options listed if you click on "Support" at the top of Drupal.org, which will take you to:
http://drupal.org/support

There you can find out about the Drupal IRC channels, and the Forums, which are our two main support mechanisms in the Drupal community. You might also try http://drupal.stackexchange.com/

Good luck with your issue!

borisson_’s picture

Status: Active » Needs review
StatusFileSize
new675 bytes

I added the same @return as the one in ViewExecutable::preview.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Perfect, thanks!

dimaro’s picture

@jhodgdon When I apply PHPDoc to autogenerate the comments in views_embed_view(), it shows me three possible values as return values.

array|null|void

We need to include void as return value?

alexpott’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

This is a kind of duplicate of #2649352: views_embed_view() should use a render array so metadata can bubble up. That patch is changing the render array returned by this function and should add the @return too...

Can someone merge the patches and update #2649352: views_embed_view() should use a render array so metadata can bubble up