0

I used Bulk Export to export all my Context definitions into my module in a function that implements hook_context_default_contexts(). However, my default context definitions do not appear if I delete the ones in the database.

Does this hook no longer work in Drupal 7?

3

Here's the piece I was missing:

/**
 * Implementation hook_ctools_plugin_api().
 *
 * Makes module compatible with context 3.
 */
function MY_MODULE_ctools_plugin_api($module, $api) {
  if ($module == 'context' && ($api == 'plugins' || $api == 'context')) {
    return array('version' => 3);
  }
}
1

It does work in Drupal 7, here you can see an example of a valid code from export created by Features module:

<?php
/**
 * @file
 * vw_product_search.context.inc
 */

/**
 * Implements hook_context_default_contexts().
 */
function vw_product_search_context_default_contexts() {
  $export = array();

  $context = new stdClass();
  $context->disabled = FALSE; /* Edit this to true to make a default context disabled initially */
  $context->api_version = 3;
  $context->name = 'shop';
  $context->description = '';
  $context->tag = '';
  $context->conditions = array(
    'path' => array(
      'values' => array(
        'shop' => 'shop',
        'search' => 'search',
      ),
    ),
  );
  $context->reactions = array(
    'block' => array(
      'blocks' => array(
        'facetapi-WVeJBMTHZn1PCfPfrIPnjg1v8m19Gkqd' => array(
          'module' => 'facetapi',
          'delta' => 'WVeJBMTHZn1PCfPfrIPnjg1v8m19Gkqd',
          'region' => 'sidemenu_left',
          'weight' => '-10',
        ),
        'facetapi-H24ObDRB0Wq0KpRW1qalIgb7TvlKP7aj' => array(
          'module' => 'facetapi',
          'delta' => 'H24ObDRB0Wq0KpRW1qalIgb7TvlKP7aj',
          'region' => 'sidemenu_left',
          'weight' => '-9',
        ),
        'facetapi-GxgmQn2y5194O1hZ7qJIROIO63v5BKtG' => array(
          'module' => 'facetapi',
          'delta' => 'GxgmQn2y5194O1hZ7qJIROIO63v5BKtG',
          'region' => 'sidemenu_left',
          'weight' => '-8',
        ),
        'facetapi-zNmFD0ELaD0hTUYX9jyfnhkzHkz5GVvQ' => array(
          'module' => 'facetapi',
          'delta' => 'zNmFD0ELaD0hTUYX9jyfnhkzHkz5GVvQ',
          'region' => 'sidemenu_left',
          'weight' => '-7',
        ),
        'facetapi-kSPIS0vKCobobG533MMOWru8Q42SmByu' => array(
          'module' => 'facetapi',
          'delta' => 'kSPIS0vKCobobG533MMOWru8Q42SmByu',
          'region' => 'sidemenu_left',
          'weight' => '-6',
        ),
        'quicktabs-shop_facets' => array(
          'module' => 'quicktabs',
          'delta' => 'shop_facets',
          'region' => 'sidemenu_right',
          'weight' => '-8',
        ),
      ),
    ),
  );
  $context->condition_mode = 0;
  $export['shop'] = $context;

  return $export;
}

Make sure that your module is enabled, that the hook implementation is correct and your caches flushed.

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.