I guess this has something todo with CTools caching.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mrfelton’s picture

Project: Bean (for Drupal 7) » Context
Version: 7.x-1.x-dev » 7.x-3.x-dev
Status: Active » Needs review

I think this is actually the fault of content module, so I'm moving to their issue queue.

The problem is that context only rebuilds its internal block cache when an 'admin' form is submitted. Because the Beans are being treated a little more like content, and the admin path is /block/add/type which does not fall below /admin, context's cache clear is not being triggered when the form is submitted

Context does this:

/**
 * Implementation of hook_form_alter().
 */
function context_form_alter(&$form, $form_state, $form_id) {
  // Prevent this from firing on admin pages... damn form driven apis...
  if (!empty($form['#node_edit_form']) && arg(0) != 'admin') {
    context_node_condition($form['#node'], 'form');
  }
  // Clear out block info cache when an admin area form is submitted.
  if (arg(0) === 'admin' && !empty($form_state['input']) && isset($form_state['method']) && $form_state['method'] === 'post') {
    if ($plugin = context_get_plugin('reaction', 'block')) {
      $plugin->rebuild_needed(TRUE);
    }
  }
}

So it's checking for submitted forms below /admin.

By instead using path_is_admin() to check if the form is an admin form, we can be sure that the cache is cleared out when admin forms that don't live below /admin are submitted:

/**
 * Implementation of hook_form_alter().
 */
function context_form_alter(&$form, $form_state, $form_id) {
  // Prevent this from firing on admin pages... damn form driven apis...
  if (!empty($form['#node_edit_form']) && arg(0) != 'admin') {
    context_node_condition($form['#node'], 'form');
  }
  // If the form is an admin for, flag it so that we can force a rebuild if needed.
  if (path_is_admin($_GET['q'])) {
    $form['#submit'][] = 'context_admin_form_submit';
  }
}

/**
 * Clear out block info cache when an admin area form is submitted.
 */
function context_admin_form_submit(&$form, $form_state) {
  if ($plugin = context_get_plugin('reaction', 'block')) {
    $plugin->rebuild_needed(TRUE);
  }
}

Patch attached.

mrfelton’s picture

febbraro’s picture

Status: Needs review » Closed (fixed)