You are here

function patterns_execute_action in Patterns 6.2

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

Execute an action

2 calls to patterns_execute_action()
drush_patterns_import in ./
Imports the specified patterns file
patterns_implement_action in ./patterns.module
Setup and run an action


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


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_tables = array_merge(module_invoke_all('flush_caches'), $core);
  foreach ($cache_tables as $table) {
    cache_clear_all('*', $table, TRUE);
  $args = array(
  if (is_array($params)) {
    $args = array_merge($args, $params);

  // 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);


  // drupal_execute fails to keep $form_state in-sync through the
  // whole FAPI process. Issue

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

  // Fix some parts of the #post values based on the original form

  // 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);

  // Some forms don't have a default submit.
  // Hopefully, the first submit button will do.
  // TODO: allow pattern author to select button?
  if (empty($form['#submit'])) {
    foreach ($form as $input) {
      if ($input['#type'] == 'submit' && !empty($input['#submit'])) {
        $form['#submit'] = $input['#submit'];

  // 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:
  // 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);
  $batch = $batch_clone;