Currently we have a page that is generated by a hook menu page callback. The path is structured like menu/%location_name/menu/%parent_category/%child_category. The function requires at least one of the category wildcards to properly work.

In the page callback we then set up our context's condition which is to determine which of the categories we're in. See code below:

  if(empty($term_parent) == FALSE || empty($term_parent) == FALSE) {
    if ($plugin = context_get_plugin('condition', 'ss_menu_core_condition_default')) {
      if(empty($term_parent) == FALSE && empty($term_child) == TRUE) {
        $context_term = $term_parent->tid;
      } elseif(empty($term_parent) == FALSE && empty($term_child) == FALSE) {
        $context_term = $term_child->tid;

Everything up until this point makes a bit of sense to me. And currently it validates fine and I can actually see the context when using context_active_contexts(). Although the gotcha that I must be missing is how do i go about allowing the metatags context module's reaction to use this term for token replacement?

At first the tokens avaliable were pretty generic default site wide things such as current page, current user, date, etc... It wasn't until i found a patch that taxonomy terms ended up showing up as token replacements. But none of them seemed to work as it seemed the context didn't know of what term to use.

This leaves me at a point where I felt like the only solution was to do something hackish and just set my values in the active context as follows:

  $context = context_active_contexts();
  $context['ss_menu_core_menu_sections']->reactions['metatag_context_reaction']['metatags']['und']['description']['value'] = $context_term->description;

This still doesn't feel right at this point since we can't actually use the metatags reaction form to populate the values. If anyone has any ideas that would be amazing.


1 Answer 1


Take a cue from metatag_context_entity_prepare_view() in that patch. You need to stuff your desired term entities into the metatag_context_entities static variable in your page callback like so:

drupal_static('metatag_context_entities', array('taxonomy_term', $terms));
  • Oh wow! How did i manage to miss this? Is there another drupal_static() just for context or is this more of what i want to use?
    – Chad Payne
    Commented Aug 19, 2015 at 22:15
  • I'm not sure I really understand your question, but drupal_static is in no way specific to the context module. And what metatag_context is doing here is not specific to the context module, either. When it processes tokens it has to decide what entities to use to populate the tokens and it's doing that by implementing hook_prepare_view and stuffing those entities into a static variable. Is that the best way for it to do that? It's debatable. But that's how it's doing it, so you need to get your entities into that static var.
    – Aaron
    Commented Aug 19, 2015 at 22:20
  • yeah sorry that was poorly phrased. Anyway that seems like the solution so i'll test it out. Thanks for your help and time. :)
    – Chad Payne
    Commented Aug 19, 2015 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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