Description of the need
While working on https://github.com/backdrop/backdrop-issues/issues/2949 I wanted the ability to add field tokens to only the bundles where the fields were used. But AFAICT there is not currently any way to add token info for a specific bundle.
I don't remember this being a problem in Drupal, but I couldn't find any similar issues where this has already been solved.
Proposed solution
In hook_token_info()
:
* Add a new (optional) 'sub_types' key to the types
associative array. This key would define another associative array containing sub types of tokens (bundle names, for example).
* Add a new (optional) 'sub_types' key for each token defined in the associative array of tokens
.
These sub_types can later be used to limit the availability of those tokens, perhaps in the token browser UI.
On the URL Alias Patterns page, we could provide a specific browser for each alias type. The browser for Post
, for example, would include all the tokens for Post fields, but none of the tokens for Page fields. The browser for the general Content
alias type would be the same one we have now (with all the possible options - including some that may not exist).
Content returned from hook_token_info() could look something like this:
function node_token_info() {
$types = array(
'node' => array(
'name' => t('Content'),
'description' => t('Tokens related to individual pieces of content, or "nodes".'),
'needs-data' => 'node',
'sub_types' => array('page', 'post', 'book'),
),
...
);
...
}
function book_token_info() {
$info['tokens']['node']['book'] = array(
'name' => t('Book'),
'description' => t('The book page associated with the node.'),
'type' => 'menu-link',
'sub_types' => array('book'),
);
return $info;
}
Alternatives that have been considered
- ?
Additional information
Draft of feature description for Press Release (1 paragraph at most)
Backdrop now includes subtypes for tokens.
Recent comments
@yorkshirepudding - Thank you! That's just what I needed. In the code, it's actually fontyourface_ui_settings_form (with underscores rather than dashes). Now it's working ... I only have to figure...
Question about hook_form_FORM_ID_alter
Oh the benefits of a new set of eyes.... I don't know how many times I've looked at that css and not spotted that! Mind you, in my defense, my eyes are over 70 years old (and obviously in need of...
How to over-ride grid-flexbox.css
thanks yorkshirepudding, i used the CSS Injector option with this code and it works .views-table caption { font-weight: bold; color: blue; font-size: 26px; }
How to change the format of the Views group title field?