Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Currently, views does pretty much everything in views_preprocess_view_view(). This is not ideal when we want to deal with render arrays more for caching etc..
By this time we are dealing with pretty much rendered strings too.
Proposed resolution
Move most of this building logic into a pre render function.
Make view properties (header, footer, etc..) proper theme properties
Try to return render arrays where possible from handlers/plugins (where is feasible, i.e. Not Feeds currently)
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#53 | interdiff-2221433-53.txt | 3.22 KB | damiankloip |
#53 | 2221433-53.patch | 37.28 KB | damiankloip |
Comments
Comment #1
damiankloip CreditAttribution: damiankloip commentedRough initial patch ^^
Comment #2
damiankloip CreditAttribution: damiankloip commentedComment #3
dawehnerIt would be kinda neat to at least have the #cache element generation in an extra method, just because it will probably contain more bits in the future with the cache plugin?
what about using elementPreRender, to distinct it from the preRender parts in views itself?
Yeah that is not used anymore but kinda out of scope tbh. I kinda like the semantic of this variable ...
Comment #4
damiankloip CreditAttribution: damiankloip commentedLet's not do anything with #cache in this patch. Added some more moving of stuffs with the views forms from preprocess too.
Comment #6
Wim Leers#4: that probably makes more sense, yes :)
Drupal\views\ViewExecutable::$row_index
now being undefined is responsible for pretty much all exceptions, and possibly also quite a few fails.Comment #7
dawehnerShould't we just call ViewsForm::create($container) instead?
This is just a little bit nicer to maintain
Comment #8
Wim LeersComment #9
damiankloip CreditAttribution: damiankloip commentedNot sure style rendering can live in #pre_render? :(
Comment #11
Wim LeersIs #9 a straight reroll?
Comment #12
dawehnerLet's see ...
Comment #14
dawehnermeh.
Comment #16
dawehnerReplacing $view->row_index with ResultRow->index, which is much nicer in general.
Comment #17
dawehnerCertain additional issue, which is needed: #1849822: Convert (HTML) view rendering to a render array
Comment #19
dawehnerDid some work though this is blocked by another issue.
Comment #20
dawehnermuh
Comment #22
dawehnerCurrently blocked on #2273277: Figure out a solution for the problematic interaction between the render system and the theme system when using #pre_render
Comment #23
Wim LeersComment #24
Wim LeersComment #25
Wim LeersComment #26
dawehnerLet's make it clear #2273277: Figure out a solution for the problematic interaction between the render system and the theme system when using #pre_render
Comment #28
damiankloip CreditAttribution: damiankloip commentedSo that issue is in now, let's see what happens.
Comment #30
damiankloip CreditAttribution: damiankloip commentedLet's start with a reroll. Then see what's going on.
Comment #32
Wim Leersdrupal_render_collect_attached()
doesn't exist anymore. I don't think you still want this change. That should help solve the 2 fails :)Comment #33
damiankloip CreditAttribution: damiankloip commentedYes, the fatals in the test output point to that too :) :
Comment #34
Wim LeersOh, hah, sorry! Silly me :) Just trying to help, but being useless :P
Comment #35
damiankloip CreditAttribution: damiankloip commentedNp. It was totally right though! :)
Comment #36
dawehnerAre we sue we want to do it that way instead of attaching it to some render array?
Comment #37
dawehnerI really like the status of the patch.
@damiankloip
The IS looks really nice and clean!
Comment #38
damiankloip CreditAttribution: damiankloip commentedYes, Ideally we don't use that. But the current way this is done is pretty pointless also. Looks like some find and replace change, doing something like :
Just seems wrong. $build is being created at that point...
So, anyway, let's just add these calls to the view element attached data. Then I *think* we all win.
Comment #39
dawehnerSo much better and not actually braindead!
What about Html::cleanCssIdentifier directly?
Comment #40
moshe weitzman CreditAttribution: moshe weitzman commentedCode looks good to me too. Can we get an issue summary please? I'll set back to RTBC afterwards.
Comment #42
damiankloip CreditAttribution: damiankloip commentedMade those changes from Daniel, updated IS quickly.
Comment #44
damiankloip CreditAttribution: damiankloip commentedHmm, that's a legit fail. Seems our attached array is not populated after the changes I made in #42.
Comment #45
dawehnerThe reason why this doesn't work at the moment is that DisplayPluginBase::attachDisplays works on a clone of the view, see
$this->displayHandlers->get($id)->attachTo($cloned_view, $this->current_display);
I wonder whether we considered setting the main render array to the cloned view temporarily.Comment #46
damiankloip CreditAttribution: damiankloip commentedComment #47
Wim LeersComment #48
dawehnerAs talked in IRC, can we do something like the following?
Comment #50
damiankloip CreditAttribution: damiankloip commentedYes, that's it! Let's try and fix it to pass.
Comment #51
dawehnerAwesome, I really like it. So who can we force to RTBC that patch?
@Wim Leers @tim.plunkett?
Comment #52
Wim LeersOne important thing, a few minor maintainability/grokkability things and a bunch of nitpicks. This is close.
Shouldn't the order of this be the other way around?
Only when
drupal_render()
has run, the#attached
CSS and JS from the child, grandchild etc. levels will be available at the parent (root) level.I suspect the existing test coverage doesn't have any attached CSS/JS at levels beyond the root level, which would explain why this passes tests.
Docblock should be updated?
Missing trailing period.
Please document why this needs to be assigned by reference.
I think we generally write "#pre_render callback", not "Pre render callback".
Incomplete docblock. (I know… silly, but that's the rule.)
Typehint to
array
.s/added/attached/
Elegant! :)
s/
$count
/$index
/?
$count
makes little sense to me.Comment #53
damiankloip CreditAttribution: damiankloip commentedThanks for the review. Fixed those points and rerolled for now, except the first... So this is just for the items that get collected from the $view->element data, and added to #attached in render(), historically not for anything else really. Do we want to make this change and support this? Probably, I guess. How is this handled in other places?
Comment #54
Wim LeersAh, right, that makes sense!
I'd say so, yes. But it's probably wiser to defer that to a follow-up issue. That's really a new feature (or a bug fix, depending on how you look at it), so I'd rather not do it here if that turns out to open a new can of worms.
Comment #55
damiankloip CreditAttribution: damiankloip commentedYes. That sounds like a very sensible idea. Thanks Wim!
Comment #56
alexpottCommitted 7ea1cd9 and pushed to 8.0.x. Thanks!
Could just use $variables['css_name'] - also not sure why the two classes below are not using this? Perhaps file a follow up for this.
Fixed the above on commit.
Comment #59
XanoThis issue caused #2350551: Views fields that have attached assets are lost when Views output caching is enabled.
Comment #60
Wim LeersThis causes a notice when the Views output cache is being used: #2378815: DisplayPluginBase::elementPreRender() and View::preRenderViewElement() are called even when the Views output cache is being used, causing notice.
Comment #61
damiankloip CreditAttribution: damiankloip commentedThe actual place this is coming from is #1849822: Convert (HTML) view rendering to a render array But they are both contributing to the notice.