You are here

function patterns_execute_action in Patterns 7.2

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

Execute an action.

Parameters

mixed $form_id The name of function to call.:

array $form_state The form_state object.:

array $params Extra parameters to be passed to the form function.:

1 call to patterns_execute_action()
patterns_implement_action in includes/core/common.inc
Setup and run an action.

File

includes/core/common.inc, line 244
The common functions used by the Batch and PHP running modes.

Code

function patterns_execute_action($form_id, &$form_state, $params) {
  patterns_executing(TRUE);

  //$args = is_array($params) ? array_merge(array($form_state), $params)

  //													: array($form_state);
  // We don't know here whether we are executing a callback
  // or building a form

  //$result = call_user_func_array($form_id, $args);

  //$result1 = $form_id($form_state, $params);
  $result = drupal_retrieve_form($form_id, $form_state, $params);

  // Check whether it is callback or a form submission
  if (_patterns_is_patterns_results($result)) {

    // Callback: nothing to do anymore
    if (isset($result['msg'])) {
      drupal_set_message($result['msg']);
    }
  }
  else {

    // Form: we just built it, and not we need to submit it
    // 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);
    }

    // This is the old way of executing the form: it is slower
    // because it needs to rebuilds it

    //////////////////////////////////////////////////////////////

    //$args = array_unshift($args, $form_id);

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

    ///////////////////////////////////////////////////////////////
    $form = $result;

    // Merge in default values.
    $form_state += form_state_defaults();
    $form_state['input'] = $form_state['values'];
    $form_state['programmed'] = TRUE;

    // Programmed forms are always submitted.
    $form_state['submitted'] = TRUE;

    // Reset form validation.
    $form_state['must_validate'] = TRUE;
    form_clear_error();
    drupal_prepare_form($form_id, $form, $form_state);
    drupal_process_form($form_id, $form, $form_state);
  }
  patterns_executing(FALSE);
}