Build better tokens with parameters (and use them to replace help text)

Created on 18 February 2012, about 13 years ago
Updated 17 March 2025, about 2 months ago

The idea is to build tokens that take a parameter instead of a fixed name and then use them for things as replacing local urls for help texts or links to drupal.org.

Example tokens:

[local:admin/modules] -> will expand to a local url pointing to the module administration page
[documentation:handbook/modules/system] -> will expand to a link to external documentation, which defaults to drupal.org, in this case http://drupal.org/handbook/modules/system

To my surprise we just need to define the token types and it just works adding some minimal logic in hook_tokens(). Though it wouldn't be bad to really support multiple parameters separated by ':' and adding some mapping logic to the token system.

The patch creates these two token types (local, documentation) and uses them for the first few lines of system module help. Also help texts are greatly simplified by this:

// Old help text (note the parameters at the end)
       $output .= '<dd>' . t('The System module allows users with the appropriate permissions to enable and disable modules on the <a href="@modules">Modules administration page</a>. Drupal comes with a number of core modules, and each module provides a discrete set of features and may be enabled or disabled depending on the needs of the site. Many additional modules contributed by members of the Drupal community are available for download at the <a href="@drupal-modules">Drupal.org module page</a>.', array('@modules' => url('admin/modules'), '@drupal-modules' => 'http://drupal.org/project/modules')) . '</dd>';

// New help text (not variables are replaced by tokens)
      $output .= '<dd>' . t('The System module allows users with the appropriate permissions to enable and disable modules on the <a href="[local:admin/modules]">Modules administration page</a>. Drupal comes with a number of core modules, and each module provides a discrete set of features and may be enabled or disabled depending on the needs of the site. Many additional modules contributed by members of the Drupal community are available for download at the <a href="[documentation:project/modules]">Drupal.org module page</a>.') . '</dd>';

Of course we need to run help text through token replacement.

✨ Feature request
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

language system

Created by

πŸ‡ͺπŸ‡ΈSpain Jose Reyero

Live updates comments and jobs are added and updated live.
  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

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

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

    Thank you for sharing your idea for improving Drupal.

    We are working to decide if this proposal meets the Criteria for evaluating proposed changes. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or there is no community support. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024