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.
I'm not 100% on the best place to post this bug, but as I use ECK to generate entities, and create template files for them, I'm unable to use the without Twig filter. {{ entity|without('field_name') }}
just prints the field last, instead of removing it.
Comment | File | Size | Author |
---|---|---|---|
#13 | interdiff-2646216-11-13.txt | 1.99 KB | akalata |
#13 | 2646216-eck-entity-template-13.patch | 3.53 KB | akalata |
#11 | 2646216-eck-entity-template-11.patch | 4.31 KB | akalata |
#6 | 2646216-eck-entity-template.patch | 4.72 KB | akalata |
#4 | entity without.png | 211.65 KB | akalata |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous at Chapter Three commenteddrewbolles created an issue. See original summary.
Comment #2
legolasboI can confirm this behaviour, but I am also unsure if this is related to ECK and have not been able to track down it's cause yet. Any help is greatly appreciated.
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous at Chapter Three commentedAs I investigate further, without is not working on native node templates either. Seems to a bug with the Twig filter function. I'll look to push the bug to core.I did also notice that Field Groups don't output in the {{ entity }} content array as they do in nodes. I can file a separate bug for that.
Edit: without() works fine with core entities, it just seems ECK entities are where it behaves odd.
Comment #4
akalata CreditAttribution: akalata commentedTrying to figure out what's going on in order to fix it, but I did find a workaround:
Digging down one more layer to #entity, 'without' works. So the workaround is
{{ entity.entity|without('field_name') }}
.I'm currently working w/ @joelpittet at MidCamp trying to figure out how this workaround actually manages to work. But in the meantime...
Comment #5
akalata CreditAttribution: akalata commentedPlanning to work on this today at the MidCamp sprint.
Comment #6
akalata CreditAttribution: akalata commentedIgnore #4, but the attached patch should fix things. Basically, I went through and tried to get the entity rendering to be more like how rendering nodes work. Also added a few default classes for the template.
Comment #9
legolasboThis removes template suggestion granularity and does not help fix the issue. So these lines should be reverted.
Besides that, the patch looks like a clean solution to the problem. I would like to see the tests passing again though ;)
Thanks for your efforts on this!
Comment #10
akalata CreditAttribution: akalata commentedLooking into the tests the morning. :)
The reason I removed the suggestions involving view mode is because ECK entities don't have view mode options -- but doesn't hurt to leave them in I guess!
Comment #11
akalata CreditAttribution: akalata commentedLet's try this. We can't get rid of the default
$build['#{entity_type}']
, because that's what the Entity system wants to use for some of its internal tests, leading to the failures we saw. With some work, we could probably override that if desired (I started down that path but don't know the routing system well enough yet).The preprocessing of
Element::children
into the$content
variable is possibly the only thing that's needed to fix, but I think the change ofentity
toelements
andeck_entity
helps to keep things clear.Comment #12
legolasboI think entity_type is a more descriptive key.
This comment seems incorrect to me. It is not a helpful variable since it is the main variable being printed.
Please use the shorthand notation for arrays as per Drupal's coding standards.
These classes are not set during preprocessing and therefor should not be mentioned in the description of available variables.
Still mentions 'node'
Let's not set all these classes by default.
It would also be nice if the functioning of the |without could be proved with a tests.
Comment #13
akalata CreditAttribution: akalata commentedThanks for the feedback!
The attached patch addresses all points in #12. Re 12.6, I left one class in. I'm torn on that because from one perspective, if a contrib module isn't adding any styles, then it doesn't need classes in its templates. On the other hand, Classy-based themers have opted into informative classes and might be approaching theming from a CSS-first perspective (which is where I started in theming).
Looking into adding the tests now, setting NR for testbot.
Comment #14
akalata CreditAttribution: akalata commentedCreated #2697093: Add tests for eck-entity.html.twig specifically for the tests.
Comment #15
kgoel CreditAttribution: kgoel commentedI am not sure why you have renamed entity to eck_entity.
I have looked into node.html.twig as an example which doesn't have any classes so not sure if you need to have one here.
Comment #16
akalata CreditAttribution: akalata commented15.1 -
#entity
is extremely generic, and I found it confusing while working on this issue. Typically, the build/render arrays for entities name this key as the entity type -- i.e.#node
and#user
. With the code ineck_entity_view_alter()
, we're adding a new copy of the entity under#eck_entity
, so that our template preprocessing, altering, etc. will always have a standard key to work with (since entity types are created dynamically, we can't use the entity key for ECK entities). It made sense to me to namespace #entity to clarify why it's being included at all.15.2 - I mentioned in #13 in response to 12.6, I'm a fan of providing "wayfinding" classes for easier out-of-the-box styling, but I recognize that it's a personal preference. I'm ok with taking it out if the maintainer agrees.
Comment #17
legolasboCommitted and pushed to 8.x-1.x. Thanks!
Comment #20
maikelkoopman CreditAttribution: maikelkoopman as a volunteer and at Open Social for Open Social commentedI still experience this issue in 1.0-alpha3. What happens is that the field of a bundle is (probably first removed and) added as the last field when using the filter, instead of not showing it at all.
Comment #21
joachim CreditAttribution: joachim as a volunteer commented> I still experience this issue in 1.0-alpha3.
This fix did not make it into alpha 3.