Creating a new token needing particular context for block visibility groups

Most important thing to know when developing and testing your token hooks is that you will not see any tokens that are not actually present. So when i expected to see every possible token, and only saw site and date, i thought it was because those other tokens were not defined yet and i’d have to move my hook implementation to occur after they were. No, not at all— i cannot see even the types and tokens i have defined, unless they actually get used on the page i am visiting.

Cannot believe i needed this, i’m sure there’s a better way to list config entities but uh not any that are documented or quickly discoverable.

And i trust what Benji says.

    $groups_config = \Drupal::service('')->listAll('block_visibility_groups.block_visibility_group');


  $groups_config = \Drupal::service('')->listAll('block_visibility_groups.block_visibility_group.');
  $groups = array_map(function($group) { return substr($group, 47); }, $groups_config);
  $evaluator = \Drupal::service('block_visibility_groups.group_evaluator');
  $active_groups = array_filter($groups, function($group_name) use ($evaluator) {
    $group = \Drupal\block_visibility_groups\Entity\BlockVisibilityGroup::load($group_name);
    return $evaluator->evaluateGroup($group);
  // TODO look into using token_render_array or flagging that it should
  // work with this when it lands (but do not token module a dependency):
  $replacements[$original] = implode(',', $active_groups);

Provide array of primitive property values on multivalue field [#3115486] |

Support un-placed blocks [#3303555] |