I have a problem in the Flag module with the [node:flag-vote-count] token. I googled for a solution, but I couldn't find one.

On my content page, the Flag module displays the token name (i.e. [node:flag-vote-count]) on the node creation preview page, instead of a number.

I am putting the token on the Flag -> Edit -> "Flag link text" field. Meaning inside the flag itself. [node:title] is working perfectly fine there.

Someone can help me here?

  • Where are you putting the token exactly? If it's in the content body do you have a filter module installed that converts tokens? – Clive Sep 25 '13 at 16:44
  • I am putting the token on the Flag -> Edit -> "Flag link text" field. Meaning inside the flag itself. The [node:title] token is working perfectly fine there. I edit my question and add this clarification. – EB84 Sep 25 '13 at 17:38

OK , so I solve it.

The [node:flag-vote-count] is really not working. But you can look for another count token for the flag you created, under the TOKEN REPLACEMENT -> nodes.

Good luck :)

|improve this answer|||||

It's works fine:

If i have name variable of flag: 'bookmarks'

I most replace this [node:flag-vote-count] to this [node:flag-bookmarks-count]

If your name variable for example like this: 'bookmarks_this',

you need write toke like so: [node:flag-bookmarks-this-count]

|improve this answer|||||

When a single token is not replace, it means that none of the modules implementing tags gave a value for the token you are using.

Looking at flag.tokens.inc, which contains the code for listing and generating the Flag module tokens, I notice it is using the following code to generate the token you are trying to use.

  // We only provide tokens on entity types if we have token module's helper
  // methods available.
  if (isset($data[$type]) && module_exists('token')) {
    $entity_type = token_get_entity_mapping('token', $type);
    if ($entity_type && in_array($entity_type, flag_get_types())) {
      $flags = flag_get_flags($entity_type);
      $object = $data[$type];
      foreach ($flags as $flag) {
        foreach ($tokens as $name => $original) {
          $flag_count_token = 'flag-' . str_replace('_', '-', $flag->name) . '-count';
          $flag_link_token = 'flag-' . str_replace('_', '-', $flag->name) . '-link';
          if ($name == $flag_count_token) {
            $replacements[$original] = $flag->get_count($flag->get_entity_id($object));
          elseif ($name == $flag_link_token) {
            $replacements[$original] = flag_create_link($flag->name, $flag->get_entity_id($object));

To see that token, you need to have the Token module installed, since flag.info doesn't require it as dependency, if not for executing the tests. You also need to use the correct flag name, which means that if you are using [node:flag-vote-count], but the flag name is bookmarks, you are using the wrong token name, which should instead be [node:flag-bookmarks-count].

I didn't test it, but probably you would get back the token name if the node doesn't have any value for that flag.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.