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

Command icon 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

axel.rutz created an issue. See original summary.

droath’s picture

Can you provide an example or use case for this feature request?

droath’s picture

Status: Active » Postponed (maintainer needs more info)
murz’s picture

At 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.

anybody’s picture

Version: 8.x-1.x-dev » 2.1.x-dev
anybody’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Active

Here'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! 🦾🦸

anybody’s picture

Title: Provide a Twig extrafield type » Provide a Twig extrafield type (with token support)
Issue summary: View changes

grevil made their first commit to this issue’s fork.

anybody’s picture

@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.

grevil’s picture

Status: Active » Needs review

All done, please review! I'll do some manual testing, while this can get reviewed already! 👍

anybody’s picture

Status: Needs review » Needs work

GREAT work @Grevil! I left some comments :)

@droath would you be fine with that, once it's finished? What do the others here think?

droath’s picture

@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.

grevil’s picture

Title: Provide a Twig extrafield type (with token support) » Provide a Twig extrafield type
Status: Needs work » Needs review
grevil’s picture

@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).

anybody’s picture

Status: Needs review » Needs work

Great 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.

grevil’s picture

Status: Needs work » Needs review

grevil changed the visibility of the branch 3064638-provide-a-twig to hidden.

anybody’s picture

Status: Needs review » Reviewed & tested by the community

GREAT! RTBC!

@droath would you mind having a look and merge this? Maybe tag a new release afterwards? Would be great to have this GA!

anybody’s picture

@droath any chance to merge this and tag a new release? :)

  • droath committed 842f1f61 on 2.1.x
    Issue #3064638 by grevil, anybody, droath: Provide a Twig extrafield...
droath’s picture

Sorry this has taken so long to get merged in; much appreciated.

droath’s picture

Status: Reviewed & tested by the community » Fixed
anybody’s picture

Thank you very much @droath! :) Great to see this fixed!

grevil’s picture

No worries! Thanks for the merge! 👍

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.