Problem/Motivation

Drupal core provides the ability to represent data in tokens. However, it does not magically generate tokens. Tokens and their values must be explicitly defined. That means we would have to manually maintain tokens for each entity provided in our various submodules. We have gotten around the usage of tokens by using Twig whenever possible.

It is starting to seem like we should just make Token an explicit dependency. In the project-base repository we added it in response to various issues and Slack/IRC conversations.

I could see this being used for:

  • Customizing the variation title generation (currently hardcoded to Product Name - Attributes)
  • Customizing the generate order number
  • Most payment gateways support authorization/payment notes, could be used for that

Proposed resolution

Add token as a dependency outright. No initial usage and integration but as a developer and site builder experience helper. No more "wait, where are the product tokens?"

Remaining tasks

  • Link relevant issues which would prove this argument
  • Link issues which could implement the token browser and tokens
  • Get community feedback
CommentFileSizeAuthor
#4 2923854-4-token.patch1.04 KBbojanz
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mglaman created an issue. See original summary.

websiteworkspace’s picture

Thank you for making this important feature set a priority.

bojanz’s picture

Title: Add token as a dependency » Start depending on Token

We are going to proceed with adding a dependency on Token in 2.15.

Token is already one of the most commonly installed D8 contribs, since it is required by pathauto and metatag.
We already have it in both of our project templates (project-base and demo-project), and we require it for commerce_demo.
That means that the majority of our install base should already be ready for this change.
Of course, since updates are handled by Composer, it will download the missing dependency if needed.

This will make our lives easier in #2730131: Add a commerce_number_pattern submodule for sequential (order/invoice) number generation, which requires Token already.

bojanz’s picture

Status: Active » Needs review
FileSize
1.04 KB

Worked fine in manual testing. Let's see what the tests say.

bojanz’s picture

bojanz’s picture

Status: Needs review » Fixed

We're good to go. Brave new world!

  • bojanz committed 574664f on 8.x-2.x
    Issue #2923854 by bojanz, mglaman: Start depending on Token
    
Berdir’s picture

Ping me if you need something in token :)

bojanz’s picture

@Berdir
Thank you!

Status: Fixed » Closed (fixed)

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