- π§πͺBelgium BramDriesen Belgium π§πͺ
Triaging a bit. Will rework this for 2.0.x
- π§πͺBelgium BramDriesen Belgium π§πͺ
My brain is failing me at the moment why the replacements are not working. π€―
- π¨πSwitzerland berdir Switzerland
A few inputs:
* The implementation here clearly dates back to D7, when polls where just a special node type and probably inherited the default node tokens like title.
* token API is in core, what you are currently doing very likely doesn't actually need the token module.
* BUT: token.module provides generic tokens for every entity type as long as that entity type doesn't provide any tokens on its own, this is awkward and that decision was made to avoid conflicts and duplicate/similarly named tokens as hardcoded tokens often don't match field names and are structured differently.
* That means you either need to define all tokens yourself, including things like token title/question, or rely on token module to define the token type for you, but then you do require token module for tokens to work. See token_token_info_alter() and _field_token_info_alter(). Compare defining and not defining a token type on admin/help/token.
* test dependencies is no longer needed, require-dev is sufficient. test_dependencies is from before require-dev was used for this.
* in hook_tokens() make sure you only run logic/calculations when required. For example, it currently seems to load all votes and calculates things, but the tokens for that might not actually be used. Even then, that logic seems extremely expensive (looping over all votes twice?)
* several winner-* tokens are implemented but not defined? - π§πͺBelgium BramDriesen Belgium π§πͺ
Thanks @berdir!
in hook_tokens() make sure you only run logic/calculations when required. For example, it currently seems to load all votes and calculates things, but the tokens for that might not actually be used. Even then, that logic seems extremely expensive (looping over all votes twice?)
Also noticed that. But wanted to get the tests in place before I started changing stuff logic wise :-).
I have no clue whatsoever why the poll.tokens.inc file is not being recognised. Moving the code into .module works.
- π¨πSwitzerland berdir Switzerland
> I have no clue whatsoever why the poll.tokens.inc file is not being recognised. Moving the code into .module works.
Strange, but tokens.inc will eventually go away anyway: π Deprecate hook_hook_info() Active .