Problem/Motivation
As started on #1811828: Use #attached to find the css/js of a view the goal is to proper support element level caching for a view.
In order to achieve this it was experimented to convert a normal view to a render element, but due to different problems like block titles / page titles this got deferred.
Most of the problems are caused by the fact that we HAVE (!!!!!) to support to not only return render arrays but also for example proper response objects (or, currently, plain strings). This is necessary because Views supports not only rendering to HTML, but also to RSS and other formats (think REST/serializer), while render arrays only support HTML!
Proposed resolution
- Move most of the views rendering into a view element and its #pre_render functionality
- In order to use a pre_render approach we have to move the contextual links adding into pre_render as well
- Allow to specify whether a display returns a render array (like blocks) or should return a response object (like feed).
In case you return a response object call executeDisplay, otherwise call buildRenderable
Comment | File | Size | Author |
---|---|---|---|
#46 | interdiff.txt | 3.7 KB | dawehner |
#46 | 1849822-46.patch | 18.32 KB | dawehner |
#46 | 1849822-46.patch | 18.3 KB | dawehner |
#44 | interdiff.txt | 710 bytes | dawehner |
#44 | views-1849822-44.patch | 18.83 KB | dawehner |
Comments
Comment #1
dawehnerI know that I implemented exactly that once before, maybe in another issue or just as an experiment, though no idea where, so here is one.
Comment #3
dawehnerNot really have the motivation to work on it but here is at least one less bug to fix.
Most of the problems is caused by the fact that we HAVE (!!!!!) to support to not only return render arrays
but also for example proper response objects, given that for example a rss output is not handled via the render component
but via the rest/serializer code path.
Comment #5
dawehnerLet's see.
Comment #7
dawehnerI just hate phpunit failures!
Comment #9
Wim LeersUpdated issue summary, particularly to include the info in #3.
Comment #10
Wim LeersComment #11
dawehnerThank you for the great pointer. I guess this patch could be green with this already.
Comment #13
dawehnerHa, I am glad that we do have such a good test coverage.
Comment #14
Wim LeersAWESOME! :)
Shouldn't this then be called
returns_response
?And s/the plugin/the views display plugin/?
This reads a bit bizarre :P
Why assign to a variable first if you're just going to return it anyway?
Seems like this comment could use some polish.
We usually call the building of a render array
build()
. This is true for block rendering, entity rendering, etc. HencebuildDisplay()
would be a more consistent name, if that would still make sense within Views land?Should this still happen in this patch, or…?
… and this would then be called
build()
.80 cols.
WOOT! This changes it so that contextual links are added in the
#pre_render
stage rather than in the theme preprocess stage, which is much cleaner!Comment #15
dawehnerThank you for the fast review!
True
Just like render arrays itself ;)
Maybe you know an answer. One reason are debugging purposes
This comment could be more specific.
Decided to go directly with buildRender to be more in sync with the method on the display.
Nope, this is a general todo. You will find similar code snippets in various places in views.
Can we PLEASE stop the business of make it hard for people to think out loud in code? A todo itself is a fine thing and having one
is 100times MUCH better than be silent about it. Having a follow up just adds a bit on top of it.
fixed.
Comment #16
Wim LeersI know! I agree!
But at the same time, you can't blame reviewers for not knowing what the scope of a
@todo
is: it can be either meant as a reminder for something that should happen in a next reroll of the patch, or it could be meant to be committed.Why not just build()?
buildRender()
is confusing because it's two consecutive verbs. If you want to stick with what you have,buildRenderable()
would be easier to understand.Plus one final nitpick:
s/does not contain yet/does not yet contain/
Comment #17
dawehnerSure, there is overriding by arguments in programming languages like C++, but I haven't seen an example of overriding by intention. ViewExecutable::build() already exists out there.
Good point.
Fixed the nitpick.
Comment #18
Wim LeersGood point. Missed that, sorry.
I still think
::buildRenderable()
would be better though. I think you might've missed that?Comment #19
dawehnerYeah I pretty much ignored that bit totally
Comment #20
Wim LeersHehe :)
No more complaints!
Comment #21
dawehnerCool, thank you.
Comment #22
effulgentsia CreditAttribution: effulgentsia commentedIf needed for performance (caching), should be Major priority.
Comment #23
Dries CreditAttribution: Dries commentedThis patch needs a quick re-roll because some test files where moved around. Otherwise this looks good to me.
Comment #24
moshe weitzman CreditAttribution: moshe weitzman commentedFor the record, the most recent patch did not apply cleanly but it would have applied cleanly as a git merge (or rebase). I posted the details to www.mosheweitzman.me/post/96720635168/improve-drupal-org-code-workflow-w...
Comment #25
dawehnerMerge, rebase whatever.
Comment #26
alexpottIt'd be great if the summary can be updated with the actual resolution.
Comment #27
alexpottMeant to set to needs work to get the issue summary updated.
Comment #28
dawehnerRerolled.
Comment #29
Wim LeersGreat that this was set to NR so testbot picks this up, but back to NW per #26/#27.
Comment #30
dawehnerMeh.
Comment #32
dawehnerI am so glad that we have at least some basic level of test coverage.
Comment #34
dawehnerLet's fix them.
Comment #35
dawehnerNo, I don't want to get rid of tests.
Comment #38
dawehnerOr that?
Comment #40
dawehneror that?
Comment #42
dawehnermeh.
Comment #44
dawehnerThe remaining two failures are maybe impossible to understand.
Comment #46
dawehnerThere we go, how annoying is that ... Fixed it.
Comment #48
Wim LeersHurray, #2318377: Determine whether a view is cacheable and its required contexts, store this i/t config entity is in! This still/again looks great, so: RTBC!
Comment #49
catchCommitted/pushed to 8.0.x, thanks!