Created on 9 August 2016, about 8 years ago
Updated 10 October 2024, 12 days ago

Hello,

If I am not mistaken, right now Poll module lacks a few bits of code to get integrated with Token API. You already have poll_token_info() and poll_tokens() hooks implemented, but you lacked reporting a token type of 'poll' (while you did provide meta info on that token type).

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine bucefal91

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    Triaging a bit. Will rework this for 2.0.x

  • Merge request !58feat: Update tokens.inc file β†’ (Open) created by BramDriesen
  • πŸ‡§πŸ‡ͺ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 .

Production build 0.71.5 2024