computed_token_field
Synopsis
This module provides computed fields whose values are calculated based on a token value. The computed field acts like a normal field of the same type (currently supported: Text, Date, and Entity reference fields), but doesn't accept a value directly. Instead, the field instance is configured with a Token which the field renders in order to populate a value for the field. Typical use-cases include "mirroring" fields from other parts of your data model, or concatenating values from multiple fields into a single value.
For example, if you have an embedded Entity/Paragraph attached to a Node, and you need to display a field value from the sub-Entity in a View. Usually a Relationship will suffice here, but sometimes adding lots of Relationships can introduce complexity and duplicate rows in the view. Instead, you can use Computed Token Field to essentially "cache" a copy of the sub-Entity field's value directly on the Node, and then add the computed field to your view without the need for an extra relationship.
This can all be done using Computed Field, but this module allows us to provide simple computed values via a Token without the site builder needing to write a function.
Roadmap
For the moment, the module is feature-complete as required by the project that sponsored it. There are a couple key things that we'd like to see added, but no immediate plans to do so. If you're interested in expanding this module's capacities, patches are welcome!
- #3436910: Support more field types
- #3436909: Handle multi-value fields correctly.
- Test coverage
- Consider implementing other field types in Computed Field, and extending them here (rather than extend the core plugins directly)
Known problems
- Doesn't handle multi-value fields
- Limited field type support (Text, Date, Entity reference)
Similar projects and how they are different
Field Token Value is very similar, but provides only a single text field type, so it can't act like a field of a specific type (Date, Entity reference). This means it can't be used as a Filter on a view, for example.
Beyond that, Computed Field is obviously very capable here, providing a lot of facility in terms of cacheability to manage performance, but requires the site-builder to write a PHP function to provide the value. This module instead allows a site-build to provide a simple Token.
Dependencies
- Computed Field module
- Token module (core)