Provide a Twig extrafield type

Created on 27 June 2019, over 5 years ago
Updated 6 September 2024, 3 months ago

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

✨ Feature request
Status

RTBC

Version

2.1

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany geek-merlin Freiburg, Germany

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica
  • Status changed to Active 4 months ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Here's a valid use-case: ✨ Provide a token "Link" type Needs work

    Twig would be super handy for cases where you need more complex markup, for example a button. 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! 🦾🦸

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica
  • First commit to issue fork.
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

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

  • Status changed to Needs review 4 months ago
  • πŸ‡©πŸ‡ͺGermany Grevil

    All done, please review! I'll do some manual testing, while this can get reviewed already! πŸ‘

  • Status changed to Needs work 4 months ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    GREAT work @Grevil! I left some comments :)

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

  • πŸ‡ΊπŸ‡ΈUnited States droath

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

  • Status changed to Needs review 4 months ago
  • πŸ‡©πŸ‡ͺGermany Grevil
  • πŸ‡©πŸ‡ͺGermany Grevil

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

  • Status changed to Needs work 4 months ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    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.

  • Status changed to Needs review 4 months ago
  • πŸ‡©πŸ‡ͺGermany Grevil
  • πŸ‡©πŸ‡ͺGermany Grevil

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

  • Status changed to RTBC 4 months ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    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!

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

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

Production build 0.71.5 2024