You are here

function patterns_execute_action in Patterns 6

Same name and namespace in other branches
  1. 5 patterns.module \patterns_execute_action()
  2. 6.2 patterns.module \patterns_execute_action()
  3. 7.2 includes/core/common.inc \patterns_execute_action()
  4. 7 includes/core/common.inc \patterns_execute_action()

Execute an action

1 call to patterns_execute_action()
patterns_implement_action in ./patterns.module
Setup and run an action

File

./patterns.module, line 1722
Enables extremely simple adding/removing features to your site with minimal to no configuration

Code

function patterns_execute_action($form_id, &$form_state, $params) {

  // Make sure we always have a clear cache for everything.
  // Code taken from drupal_flush_all_caches().
  // Don't clear cache_form - in-progress form submissions may break.
  // Ordered so clearing the page cache will always be the last action.
  $core = array(
    'cache',
    'cache_block',
    'cache_filter',
    'cache_page',
  );
  $cache_tables = array_merge(module_invoke_all('flush_caches'), $core);
  foreach ($cache_tables as $table) {
    cache_clear_all('*', $table, TRUE);
  }
  $args = array(
    $form_id,
    &$form_state,
  );
  if (is_array($params)) {
    $args = array_merge($args, $params);
  }
  patterns_executing(true);

  // If we are in batch mode, trick the form api to think
  // otherwise to avoid potential problems
  $batch =& batch_get();
  $batch_clone = $batch;
  $batch = null;

  //$form = call_user_func_array('drupal_retrieve_form', $args);

  //$form['#post'] = $values;

  //$return = drupal_process_form($form_id, $form);

  //dpm($args);

  // drupal_execute fails to keep $form_state in-sync through the
  // whole FAPI process. Issue http://drupal.org/node/346244

  //$return = call_user_func_array('drupal_execute', $args);

  // Fix some parts of the #post values based on the original form
  patterns_sync_form_values($args);

  // Copy of drupal_execute until above issue is fixed
  $form = call_user_func_array('drupal_retrieve_form', $args);
  $form['#post'] = $form_state['values'];

  // Some modules depend on existence of 'post' array
  $form_state['post'] = $form_state['values'];
  drupal_prepare_form($form_id, $form, $form_state);

  // If you call drupal_validate_form() on the same form more
  // than once per page request, validation is not performed
  // on any but the first call.
  // see issue: http://drupal.org/node/260934
  // drupal_process_form($form_id, $form, $form_state);
  // Until above issue is fixed we use our own implementation
  // of drupal_process_form() and drupal_validate_form().
  _patterns_process_form($form_id, $form, $form_state);
  patterns_executing(false);
  $batch = $batch_clone;
}