I'm using the Metatag Context submodule of Metatag and have found that CTools doesn't believe that the class metatag_context_reaction exists. I can see that metatag_context_context_plugins() has implemented hook_context_plugins() as per API.txt, however the include file for the handler is never loaded. I'm not sure if this is a bug in ctools, a bug in context or just a documentation issue.

I can resolve the issue by declaring the "file" property outside of the "handler" array. For example:

/**
 * Implements hook_context_plugins().
 */
function metatag_context_context_plugins() {
  return array(
    'metatag_context_reaction' => array(
      'handler' => array(
        'path' => drupal_get_path('module', 'metatag_context'),
        'file' => 'metatag_context.context.inc',
        'class' => 'metatag_context_reaction',
        'parent' => 'context_reaction',
      ),
      'file' => 'metatag_context.context.inc',
    ),
  );
}

Is this a bug, or a documentation issue?

Files: 
CommentFileSizeAuthor
#6 1871798-6-clear-cache-on-module-enable.patch537 bytesmstrelan
PASSED: [[SimpleTest]]: [MySQL] 11 pass(es). View
#4 1871798-clear-cache-on-module-enable.patch521 bytesmstrelan
PASSED: [[SimpleTest]]: [MySQL] 11 pass(es). View

Comments

DamienMcKenna’s picture

I was able to get it to work using the following in Metatag:

/**
 * Implements hook_context_plugins().
 */
function metatag_context_context_plugins() {
  return array(
    'metatag_context_reaction' => array(
      'handler' => array(
        'path' => drupal_get_path('module', 'metatag_context'),
        'file' => 'metatag_context.context.inc',
        'class' => 'metatag_context_reaction',
        'parent' => 'context_reaction',
      ),
    ),
  );
}

Clarification: this was written against 7.x-3.0-beta4, I've honestly not tried it with beta5 or beta6 yet.

mstrelan’s picture

Status: Active » Closed (works as designed)

Nevermind, it turns out you need to flush the cache after installing metatag_context if context was already previously installed.

DamienMcKenna’s picture

Project: Context » Metatag
Version: 7.x-3.x-dev » 7.x-1.x-dev
Component: Documentation » Code
Category: support » bug
Status: Closed (works as designed) » Active

@mstrelan: I'm moving this over to the Metatag module to add a cache_clear_all() call during metatag_context_install() that would clear out the context cache, so other developers don't have this problem.

mstrelan’s picture

Title: Documentation of hook_context_plugins() in API.txt does not correctly explain the 'file' property » Context reaction is not available after module installation until the cache is cleared
Status: Active » Needs review
FileSize
521 bytes
PASSED: [[SimpleTest]]: [MySQL] 11 pass(es). View

Patch attached

DamienMcKenna’s picture

Status: Needs review » Needs work

A small request - this should just clear the Context plugins rather than clear everything.

mstrelan’s picture

Status: Needs work » Needs review
FileSize
537 bytes
PASSED: [[SimpleTest]]: [MySQL] 11 pass(es). View

Good call. I spent some time testing for the right cache to flush earlier but didn't see this one. This should do the trick.

DamienMcKenna’s picture

Status: Needs review » Reviewed & tested by the community

It needs some extra comments, given it's a new file, but this is great.

Once #1798294: Can't edit non-current node revisions is resolved I'll commit this.

DamienMcKenna’s picture

Committed.

DamienMcKenna’s picture

Status: Reviewed & tested by the community » Fixed
DamienMcKenna’s picture

Status: Fixed » Closed (fixed)

Now that Metatag v7.x-1.0-beta5 is out am closing this to keep the issue queue clean.