bset
Scope entity tokens by bundle so the token only gets replaced if the bundle matches. This module gives you entity tokens, such as [node:field_example], scoped by bundle (called content type in the case of nodes) so that you can use a more specific token. The equivalent, targeted token for an article would be [bset-node-article:field_example]. Other than this scoping, it works identically to a regular entity token.
Features
The motivation to build this module came from the need to distinguish between content of different types provided to FillPDF module, which allows PDF fields to be filled from replacing tokens with values sourced from multiple entities— including entities of a different type. In situations where both a household node and a property node were provided, everything worked as expected: Contact fields were filled from the household and some additional context came from the property. Where only the property node was present, contact information for the property incorrectly was filled in where only household information should be. Hence the need to limit the token used for household fields to households only.
This module can also improve people's experience of selecting tokens with Drupal's token browser by restricting field tokens to the ones applicable to a particular bundle, provided they start with "Bundle-scoped Page Nodes [bset-node-page]" or similar instead of "Nodes [node]".
Post-Installation
Enable the module and go to an interface with a token browser to insert your bundle-scoped tokens.
Note: Some
Additional Requirements
Token module only.
Recommended modules/libraries
This module would become even more useful to sitebuilders if token module would pass in some additional information, namely bundle in addition to entity type, that it does not presently support. A module which supports token replacement could, where it calls for the "Available tokens" browser, choose to depend on this module and set the token types solicited to only the applicable bundle or bundles, and not regular node tokens at all.
Similar projects
None known.
Supporting this Module
You can support Agaric's overall contributions to Drupal and a bit beyond by supporting Drutopia at opencollective.com/drutopia. Thanks!!