Some tokens use underscores, some use hyphens. How do I know which one to use? Can we standardize on the syntax for token names throughout core so contrib can follow?

CommentFileSizeAuthor
tokens.png205.14 KBjenlampton

Comments

dave reid’s picture

The standard for tokens that are hard-coded (tokens that we can define explicity) is to use dashes. But the ones that use underscores are dynamic and actual field machine names (provided by Token module). We will have the same debate with #1173706: Date tokens do not handle all date types. While it would be nice to always use dashes, I don't think it is a good idea to modify machine names, especially with regards to code complexity to have to convert the tokens back when replacing.

So in summary: core provides a sane standard of using dashes only because it is able to define all of its tokens and it doesn't have to handle dynamic tokens.

dave reid’s picture

We also have a similar problem in core: we use an entity type 'taxonomy_term' but (in)conveniently used the token type 'term'. We're going to run into this problem with other entity types as well but at least those are easier to support.

jenlampton’s picture

Wouldn't it be easier to standardize on underscores? (and fix the taxonomy token so it is called taxonomy_term)

jenlampton’s picture

tagging for learnability.

dave reid’s picture

The problem here is that core has already standardized on the usage of dashes, but things like machine names use underscores. Dashes look nicer. Either way something has to 'transform' for the sake of unity. Contrib should be using dashes wherever possible as set by the core standard.

greggles’s picture

Version: 7.x-dev » 8.x-dev

I agree hyphens are better than underscores. Seems like this will require changing machine names to hyphens.

Either way it's a string change which means 8.x first (and 7.x second, if ever).

jenlampton’s picture

Title: Standardize on use of underscore vs hyphen » Standardize on use of underscore vs hyphen in tokens

See #1353064: Standardize on use of underscore vs hyphen in machine names for standardizing on machine name syntax.

killes@www.drop.org’s picture

Issue summary: View changes

make image less large

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

larowlan’s picture

Issue summary: View changes
amber himes matz’s picture

Status: Active » Closed (won't fix)
Issue tags: +Bug Smash Initiative
Related issues: +#1353064: Standardize on use of underscore vs hyphen in machine names

This issue appears to be a duplicate of #1353064: Standardize on use of underscore vs hyphen in machine names (which is closed). However, in that issue, there are a few comments that point out that the Menu system still uses hyphens (and not underscores) and thus argue that the issue should be re-opened. This was addressed outside of the Drupal issue queue in the following Drupal StackExchange, where @berdir points out in the top-rated comment:

Menu has an inconsistent pattern for machine names with most other parts of the system, that was simply not unified when converted to use the config system.

There is no reason, but it also can't be changed now as existing menus would then be invalid.

So for that reason, I'm closing this as "Closed (won't fix)".

FYI, the relevant file where the menu form provides the exception to the default underscores replacement rule is:

core/modules/menu_ui/src/MenuForm.php, line 122.

And the default behavior for machine names (in which token names are derived from I believe) is:

core/lib/Drupal/Core/Render/Element/MachineName.php, lines 248-250.

Thanks to @daravanen in the Drupal Slack #contribute channel for pointing this issue out.