Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
views.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Anonymous (not verified)
Created:
2 Mar 2014 at 15:49 UTC
Updated:
9 Mar 2022 at 12:26 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
dawehnerHow do you "embed" a view on your site?
Comment #2
Anonymous (not verified) commentedhttps://api.drupal.org/api/drupal/core%21modules%21views%21views.module/...
Comment #3
dawehnerEnsure that you at least provide the php code you use and other stuff.
Just imagine that we don't know what you are doing.
Comment #4
Anonymous (not verified) commentedThere is nothing wrong with the PHP code. It worked in previous alpha releases and stopped working in A9. There were no changes made to the php code or the view itself.
Tomorrow I'll try to create other views and embed them so see what will happen.
Comment #5
dawehnerThank you for sharing so many information: the view itself, the php code and thank you for not using the git version.
Comment #6
Anonymous (not verified) commentedSo I have created a completly new View that would display a node. I've added a NID contextual filter and again, it works in the preview mode on the Views form but not when embeded via views_embed_view.
Comment #7
Anonymous (not verified) commentedThis will display "no results" text.
This will actually display the view with results.
The views_embed_view function is:
I would tihnk that the issue lies with the access but then the function would return nothing.
Comment #8
longwaveI noticed in #2208893: Remove unused functions from Views that views_embed_view() is never used in core, and doesn't currently have any test coverage, so it's not really surprising if it's accidentally been broken at some point.
Comment #9
Anonymous (not verified) commentedSo I have found out that the issue lies with the arguments themselves.
If
\Drupal\views\ViewExecutable::preview()receives arguments asarray(0 => 1)it will display my view properly, but if it receives arguments like thisarray(2 => 1)then the "no results" text will show up.The
1is the argument I am providing to the view. The array key is2becauseviews_embed_view()takes function arguments viafunc_get_args()and unsets keys0and1which are View name and display id and hands them over to thepreviewmethod.I havent looked yet but it seems the issue can originate from
\Drupal\views\ViewExecutable::_buildArguments.On the other hand this can be easily fixed by add ing
$args = array_values($args);to theviews_embed_viewfunction.Comment #10
dawehner@ivanjaros. I wonder whether the same should be applied on a lower level, like on ViewExecutable::setArguments. Do you have any opinion about that?
Comment #11
Anonymous (not verified) commentedI'm sure
_buildArguments()has it's reason why it works with arguments in such way and to answer your question @dawehner yes, I tihnksetArgumentswould be a good place to fix this but first we'd need to see if any code that uses it does not depend on the arguments array keys(which I don't think so). Testt should quickly find this out though.Comment #12
Anonymous (not verified) commentedLets see if it'll pass through tests.
Comment #13
dawehner.
Comment #15
Anonymous (not verified) commentedComment #16
Anonymous (not verified) commentedComment #17
dawehnerIt would be great to have some dedicated test coverage here as well.
Comment #18
dawehner@ivanjaros
Can you please explain me why views_embed_view for itself works pretty fine? I asked you multiple ****** times to show the code.
Well, at least we now have views_embed_view test coverage.
Comment #19
Anonymous (not verified) commentedIt's working on back-end because in Views edit form the \Drupal\views\ViewExecutable::preview() is called directly whereas on the front-end the views_embed_view is used. And that is the place where the argument keys get messed up.
Comment #20
Anonymous (not verified) commentedAs you can see https://api.drupal.org/api/views/views.module/function/views_embed_view/7
previously the array_shift() was used to remove view name and display id which reset the keys. That is the core of the problem.
Comment #21
dawehnerComment #22
matslats commentedYes quick solution is, in views_embed_view()
- return $view->preview($display_id, $args);
+ return $view->preview($display_id, array_values($args));
Comment #23
polI can also confirm that the patch fixes the problem.
I hope this get committed soon, this bug prevent my new D8 module to work properly.
See: http://cgit.drupalcode.org/views_field_formatter/tree/src/Plugin/Field/F...
Module: https://www.drupal.org/project/views_field_formatter
Comment #24
dawehner...
Comment #25
polUpdated patch for d8 head.
If you want to see the problem, insert a
print_r($args);in thesetArgumentsmethod then run the test with drush:drush test-run 'Drupal\views\Tests\ModuleTest' --full.Comment #27
polThe patch applies correctly on my instance...
Any idea ?
Comment #30
berdirComment #33
polNew patch.
Comment #34
polFirst attempt to create a .FAIL patch.
Comment #35
polComment #37
polComment #40
polAnd the patch.
Comment #41
webflo commentedThat's not necessary, we convert the array in setArguments() anyway.
Comment #42
polIt's up to @dawehner now...
Comment #43
dawehnerSeems to be a crosspost
Comment #44
dawehnerYeah there is no reason to stop the patch based upon that.
Comment #45
alexpottCommitted c55ac96 and pushed to 8.0.x. Thanks!
I removed this unnecessary change on commit.
Comment #48
alexpottLol well doing that broke HEAD.
This patch should also fix up the expectations of executeView by doing something like:
Comment #49
polDamn, sorry Alex.
Here's the new patch including your recommandations.
Comment #50
polHere's the interdiff.
Comment #51
alexpottThanks for addressing the concerns outlined in #48. This looked good before it was rtbc and it does again now.
Comment #52
berdirThis doesn't look like an argument to me but a display id, which is not supposed to be passed in like this?
That should be done with $view->setDisplay('embed_1') first, and then no argument to executeView()
Also, issue title and summary could really use an update to describe the actual bug, which is only documented in one of the comments above.
Comment #53
dawehnerTrue, this never worked and also the fix can't work properly :)
Comment #54
lauriiiComment #57
wizonesolutionsworking on a re-roll
Comment #58
wizonesolutionsI talked with @Pol about this on IRC and tried digging in myself, but it's hopeless. I can't figure out the best way to debug the test View because it assumes that the
views_test_datatable has data in it. But this is only populated in the context of the test. Not sure how to debug the View via the UI. Seems to have properties that aren't defined in the configuration schema, and the testing system doesn't like this.The entity reference test is fixed though, so this is what I have so far. Not including interdiff because it's the same other than not having the EntityReference test changes.
Comment #59
dawehner.
Comment #61
polHere's the updated patch with the view fixed.
Comment #62
lauriiiComment #64
polUpdated patch.
Comment #65
polSorry wrong patch, here's the good one.
Comment #68
polComment #69
polIncomplete patch, forget it.
Comment #70
dawehnerThank you!
Comment #71
polSorry for the previous comment, the patch is incomplete. This patch is ok.
Comment #72
polComment #73
dawehnerRe-RTBC
Comment #75
polOn IRC Alexpott raised that the
\Drupal\views\ViewExecutable:preview()method is not tested and asked me to rephrase the comment in the\Drupal\views\ViewExecutable:setArguments()method.Let's follow the workflow of
views_embed_view()function:As the arguments number is variable,
views_embed_view()will usefunc_get_args()to extract them, it will also remove thenameanddisplay_id, the two first arguments of the function.Before calling the
$view->preview()method, if we do aprint_ron the$argsvariable, we get this:Then we call
$view->preview().There, the
$argsvariable is untouched and passed toViewExecutable->preview(), let's see what happens there:The
ViewExecutable->setArguments()method is:My patch change these line in:
So, we are sure that the resulting array has the correct keys, like this:
The method
$view->preview()method is also fixed using this patch.As comment for
setArguments(), I'm proposing this comment:Comment #76
polFinally,
Here's a much better version of the patch with updated tests.
Let me know what you think.
Comment #77
polHere's a new patch with an updated comment in the
\Drupal\views\ViewExecutable:setArguments()method.I also added a patch containing only the tests.
Comment #78
polAdd method namespace in comment.
Comment #80
polComment #81
polComment #82
dawehnerLooks great for me!
Comment #87
polThe patch has failed because of the test bot.
Putting this patch back to RTBC.
Comment #88
alexpottThis issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 40d6c14 and pushed to 8.0.x. Thanks!
Comment #90
Anonymous (not verified) commentedFinally.