Problem/Motivation
This looks great! Let's add a Twig-extrafield plugin and i can hardly imagine what else we want then...
The inline twig template should of course also allow using tokens!
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork entity_extra_field-3064638
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
droath commentedCan you provide an example or use case for this feature request?
Comment #3
droath commentedComment #4
murzAt now we have only Tokens for display data from entity in fields, but Twig language will be much powerful to display entity data in field! So I also vote for see this feature in
Entity Extra Fieldmodule! Example of twig field we can lookup in Display Suite module at/admin/structure/ds/fields/manage_twig, and in Twig field module.Comment #5
anybodyComment #6
anybodyHere's a valid use-case: #3467207: Provide a token "Link" type
Twig would be super handy for cases where you need more complex markup, for example a link / button with translatable text and token-based URL. If you finally need to be able to translate parts of the labels, then the textarea solution isn't flexible enough anymore. So I totally agree with the others here, a Twig type would be super powerful! 🦾🦸
Comment #7
anybodyComment #9
anybody@Grevil: Rendering can simply be done using https://www.drupal.org/node/2311123
What I'm not yet sure about is, which variables we should add to the twig
#context(is the entity available here, where the field is added on?) and if we should run the result through token replacement (maybe as option?) We should then add a note that token replacement happens after twig rendering.In result this means that tokens can't replace twig variables functionally. Best would be to have both so.
Comment #10
grevil commentedAll done, please review! I'll do some manual testing, while this can get reviewed already! 👍
Comment #12
anybodyGREAT work @Grevil! I left some comments :)
@droath would you be fine with that, once it's finished? What do the others here think?
Comment #13
droath commented@Grevil! Much appreciated, I've been waiting to implement this feature for a while! :)
@Anybody Yes, once those issues are resolved and marked as reviewed by the community, I'll merge this into the dev release.
Comment #15
grevil commentedComment #16
grevil commented@Anybody and I discussed the token support internally, and we agree, that the twig context variables are the better approach, making the token support obsolete.
We inject a few global variables and the entity itself as context from the get-go and if the user needs even more context variables, he can easily implement "hook_entity_extra_field_twig_context_alter" to provide even further context variables!
Furthermore, the UX doesn't suffer from having no states available for the token tree.
In the end, @droath should decide! :)
Note, that if we want to merge the old implementation WITH token support some few more additions need to be made to that branch (e.g. schema).
Comment #17
anybodyGreat work @Grevil, just left some final comments. I agree we should leave out tokens here for now and use Twig context, which is even more powerful. If tokens will ever be needed, someone can take the alternative MR and revive it as follow-up. We shouldn't do this for unsure benefit.
Comment #18
grevil commentedComment #20
anybodyGREAT! RTBC!
@droath would you mind having a look and merge this? Maybe tag a new release afterwards? Would be great to have this GA!
Comment #21
anybody@droath any chance to merge this and tag a new release? :)
Comment #23
droath commentedSorry this has taken so long to get merged in; much appreciated.
Comment #24
droath commentedComment #25
anybodyThank you very much @droath! :) Great to see this fixed!
Comment #26
grevil commentedNo worries! Thanks for the merge! 👍