- Issue was unassigned.
- 🇬🇧United Kingdom nlisgo
I can't find where needs-data is used at all. It adds zero value currently to add this property. It's not surfaced in any UI unless some contrib is picking it up?
The case could be made to just strip out. We survived a long time without.
If we decided that we want to improve the experience for developers and merely setting this property will perform the requisite checks for the presence of a data of the declared type then we need to replace the invokeAll in token > generate() with an invokeAllWith and call the corresponding info for each hook_token and optionally call the hook_token based upon the data being present.
It would be interesting to know if there is any precedent for this type of check for other hooks in drupal.
- 🇨🇭Switzerland berdir Switzerland
> Expect no implementations of hook_tokens to be called with $type === 'node'
It's just a hook. We have no knowledge of which types a certain hook_tokens() provides, anything can add tokens for everything. We have no metadata about this.
The needs-data is used by token module, where you tell the UI component which data types you have and as a result, you see only corresponding (and global) tokens.
So no, we shouldn't remove it, but in it's current form, this is impossible to change. We'd need a completely different API where we know which thing provides tokens for which type. There are some proposals, but I'm not convinced by using a plugin system for this for example.
I think this should be closed as won't fix, or maybe a documentation issue to clarify it.
- 🇦🇺Australia acbramley
Agree with @Berdir, since types aren't tied to any one module (a module can implement multiple types) and they don't have to match the module name, there's no way we can short circuit a hook_tokens call for missing data.