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.

Comments

damien tournoud’s picture

Status: Active » Needs work

Sounds like a smart idea!

+    foreach ($tokens as $name => $original) {
+      $replacements[$original] = url($name);
+    }
+  }
+
+  elseif ($type == 'documentation') {
+    foreach ($tokens as $name => $original) {
+      $replacements[$original] = variable_get('system_external_documentation', 'http://drupal.org/') . $name;
+    }
+  }

Most likely, those need to be check_plain()-ed, right?

miro_dietiker’s picture

Great idea.

How would you treat the difference of e.g. internal help links ... help links to drupal.org manuals ... APIs and even contrib specific sources?
Is your solution only intended to cover drupal.org links?

While i see a good reason to e.g. cover specific documentation on a custom server, i would expect to never see the drupal.org manpages copied/mirrored to a custom location. So if i do mirroring for a specific project, i only want to redirect those links that i mirror.

What kind of separation do you think makes sense (and possibly what kind of extensibility)?

dave reid’s picture

What I can say about this is that this is kinda an abuse of the token system as you wouldn't have any tokens defined in hook_token_info() since it's just [internal:*] and [documentation:*] and there's nothing actually *defined* in the second part of the token - this will break things like token tree display.

dave reid’s picture

Issue tags: +Token system
jose reyero’s picture

StatusFileSize
new6.96 KB

This is a new version of the patch addressing some of the concerns above:

- Adds a token name, tokens now look like: [url:local:admin/modules]

- Some filtering (check_url, check_plain)

jose reyero’s picture

Status: Needs work » Needs review
jhodgdon’s picture

From a help-writing perspective, I'm +1 on the concept, as long as Dave Reid is OK with the Token implementation...

Regarding that, the Token implementation seems a little backwards from the rest of the token system. For instance, if you are doing something with a comment and want a token representing the last login date of the user who created the node being commented on, you do something like (I may have the details wrong, but something like this):
[comment:node:author:last-login:short]
This is a chain that progresses from the starting point (the comment) through different pieces of information, with each part of the token supplying its output as the next item's input, and where the items are from different modules' token types. Also, at each point in the chain, as you are building up a token, something like the Rules UI can list for you all possible next items you can put in the chain, because they are each explicitly listed in a hook_token_info() implementation. (For instance, if you have done comment:node, it knows to then give you the node: tokens supplied by various modules.)

It doesn't seem like this proposal will work with either chaining or with the idea of being able to list all available possibilities, in its present form, and given that the current Token system (I think) doesn't support variable next-item-in-chain.

{As a side note, I just filed #1483662: URLs for drupal.org module help pages need updates because I noticed the URLs for help docs are out of date.}

dave reid’s picture

I still just don't really understand what the benefit is here of using tokens compared to the existing method of putting links in with t(). Also the 'url' token type is kind of already reserved by the Token module to move into core: http://drupalcode.org/project/token.git/blob/8f89f245a332ecf69c6d9d77716...

jose reyero’s picture

@jhodgdon

[comment:node:author:last-login:short]

Really? Where can I read about that?

@Dave Reid

Currently writing help text for modules is painful and one of the reasons is all these variable replacements.

Anyway this should be only the first step because once we have simpler texts (no texts + variable generating code) we can add better handling for them, like making them configurable, or fit into the config files, or simple text files.

Also we'd make the whole system more consistent as I understand token should be the preferred way for replacing text parameters. Plus it will be more flexible as tokens can be altered. For instance, when you have a link to some external documentation (usually drupal.org) you'd like to redirect to some other place.

Related (these would be much easier using tokens and will be updated accordingly):

#1444980: Add renderable / localizable text element - make modules help text readable and flexible - pluggable localization
#517044: Improve text handling, texts in text files (editable, overridable, translatable, etc...)

jhodgdon’s picture

RE [comment:node:author:last-login:short] -- that is what you do when setting up certain Rules in the Rules module... Let's see...
hook_token_info() - this describes the "needs-data" and "type" parts of tokens.

Hm. It doesn't look like the core token_replace() supports this actually... It's possible that this is just something Rules does, and not part of the base Token system, but it seems to key off these needs-data and type parts of tokens from the core system.

Probably Dave Reid would know better than I would. :)

dave reid’s picture

I also think that this is better suited for a filter with using documentation://handbook/... and internal://admin/help rather than using tokens for them. It would be nice if we could run the help text through the filter system rather than tokens.

dave reid’s picture

jhodgdon’s picture

RE #11 -- yes, a filter makes more sense than tokens to me too, since I don't think this fits with the Tokens paradigm. But I also don't see the problem with using t() like we always have, and substituting in URLs. That pattern is all over core, in shorter text pieces, and I don't see why we would want to invent another pattern just for help?

dave reid’s picture

Yeah I don't see why we need to change what we're doing either. I also don't get why you'd want to map *all* d.org links to a different domain either. You'd have to support every single possible link.

dave reid’s picture

If you want to rewrite d.org links, it would be better just to run them through url() so that they could be modified with hook_url_outbound_alter() instead.

jose reyero’s picture

@Dave Reid,

We've just changed all d.org links, which took a big patch. It would have been a one line change if we had this, http://drupalcode.org/project/drupal.git/commitdiff/efc984dfda053550ea6e...

(Plus we'll need to update *all* contrib modules' links to d.org documentation.)

miro_dietiker’s picture

Status: Needs review » Needs work

The last submitted patch, 5: 1445144_parametrized_token_help_02.patch, failed testing.

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.

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +stale-issue-cleanup

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!

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Since there's been no follow up going to close this one out, but if still a valid task in D11 we can always re-open

Thanks!