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
The recursive rendering protection of the "Rendered entity" formatter is broken because of render caching and delayed calls to the viewElements()
method through a '#pre_render' callback.
Proposed resolution
Fix it by generating a smarter static render counter which takes into account all relevant information needed in order to work at any time during the rendering process.
Remaining tasks
None.
User interface changes
Nope.
API changes
Nope.
Data model changes
Nope.
Comment | File | Size | Author |
---|---|---|---|
#32 | interdiff.txt | 972 bytes | amateescu |
#32 | 2073753-32.patch | 7.82 KB | amateescu |
#26 | interdiff.txt | 6.87 KB | amateescu |
#26 | 2073753-26.patch | 7.39 KB | amateescu |
#22 | interdiff.txt | 2.12 KB | amateescu |
Comments
Comment #1
SweetchuckComment #2
amitaibuMaybe better change the param to
@target_type
, and also add a space before the(@entity_id)
Comment #3
amateescu CreditAttribution: amateescu commentedThere's no other @target_type occurence in core, so maybe it's better to stick with @entity_type. But I agree that we should have a space between
@entity_type
and(@entity_id)
.Comment #4
SweetchuckSame patch, but a space are between
@entity_type
and(@entity_id)
.Comment #5
amateescu CreditAttribution: amateescu commentedLooks good now, thanks.
Comment #6
webchickThis shows a lack of test coverage; could we add a quick test for this condition?
Comment #7
amitaibu> could we add a quick test for this condition?
Yes.
Comment #8
amitaibuWIP.
In the new test when I try to set the ER field, the value is not saved properly, even though it seems that the reference is correct. Furthermore, if the reference is incorrect I would expect ValidReferenceConstraintValidator to kick in, but it seems it is never called.
What am I missing here?
Comment #9
amitaibuTest is failing due to #2078155: Access protected field items being removed, so waiting for that patch to land first.
Comment #10
mgiffordComment #11
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe RecursiveRenderingException exception class has been removed in #2404021: entity_reference formatters should be in Core, now we simply abort the rendering and log a message when the limit is reached.
Here's a fresh patch with tests and everything :)
Comment #12
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedComment #15
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedRerolled. Any chance for a review? :)
Comment #16
BerdirThat's a strange way to write this:
$variable = ++$variable;
It works but I'm not even sure exactly why and in what order it does what.
Can't we write that as $variable = $variable + 1? That's IMHO a lot easier to understand and basically what you are doing.
or make a proper if/else and assign 1 or do $variable++.
We can make sure that we have at least a certain amount of matches? Or an exact match? This would happily pass if for some reason we wouldn't see the label at all, like when being on the wrong page or so.
Comment #17
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThanks for reviewing!
1. Sure, let's do a proper if.
2. I've no idea why I wrote it like that in the first place, switched to an equality check.
Comment #18
jibranPatch looks ready to me. Just a minor suggestion.
In views_field_view this is a configurable setting. Can we add this as a setting to this formatter?
Comment #19
BerdirI don't think that's useful nor related to this issue, we're just fixing a bug.
Comment #20
dawehnerYeah if you find a usecase for a level of 20, you can also replace the plugin implementation with your own.
There doesn't seem to be a reason to be public.
We could simplify this by using static::$recursiveRenderPath += [$recursive_render_id => 0]; and then skip the if/else
out of scope of this issue: this sounds like a trigger_error for me.
We can extract the value of this using one of the technique like anonymous function binding of some reflection instead.
Comment #21
dawehnerIMHO this should also be a constant, shouldn't it?
Comment #22
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented#20.1, 4, #21: No real preference, changed to a constant if you think it's better.
#20.2: Nope, I tried and that doesn't work :)
#20.3: No opinion here as well.
Comment #23
dawehnerYeah now that it is constant, we don't need it anymore.
Comment #25
alexpottI might be mistaken but I can;t see where in the test that we're testing the static caching of recursive depth by a recursive_render_id. And if we're using all this information to count by is it not useful in the log message?
Comment #26
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe fact that the recursive render limit is taken into account is the one that proves the new static caching by a recursive_render_id is working, otherwise the test-only patch from #11 wouldn't have failed. But it doesn't hurt to expand the test coverage a bit and check with a second entity.
Good point, added the information about the field and bundle name to the log message.
Comment #28
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe feedback from #25 has been addressed, so we should be good for RTBC again? :)
Comment #29
jibranSure.
Comment #30
dawehnerIt would be nice to explain why its an array.
This could be replaced by two lines of code:
static::$recursiveREnderDepth += [$recursive_render_id => 0]; static::$recursiveREnderDepth++
This wont' apply to 8.2.x, so let's ensure to create a patch against that.
Comment #31
catchLooks good to me, but needs a re-roll.
Comment #32
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented#30.1: Done.
#30.2: You mentioned that before in #20, but I tried it and it didn't work.
#30.3: Done as well, this patch now applies cleanly to both 8.1.x and 8.2.x.
Comment #33
alexpottCommitted 95dc914 and pushed to 8.1.x and 8.2.x. Thanks!