You are here

function drupal_execute_macro in Macro 7

Same name and namespace in other branches
  1. 6 macro.module \drupal_execute_macro()

Attempts to programmatically submit all the forms that have been specified in the $macros collection.

Parameters

array:

  • a list of macros to execute

@return array

  • a list of results based on the macros provided.
1 call to drupal_execute_macro()
macro_import_macro_submit in ./macro.module
Implementation of macro_import_macro hook_submit function.

File

./macro.module, line 402
allow administrators to record (export) form submissions allow administrators to replay (import) form submissions

Code

function drupal_execute_macro($macro) {
  foreach ($macro as $key => $data) {
    $item = menu_get_item($data['path']);
    if ($item && !empty($item['file'])) {
      include_once $item['file'];
    }
  }
  $results = array();
  foreach ($macro as $key => $data) {
    $param = unserialize($data['parameters']);
    $form_values = array(
      'values' => $data['values'],
    );

    // Support for multistep.
    if (isset($data['storage'])) {
      $form_values['storage'] = $data['storage'];
    }
    $args = array(
      $data['form_id'],
      $form_values,
    );
    $args = array_merge($args, $param);
    $results[] = call_user_func_array('drupal_execute', $args);
    if (form_get_errors()) {
      drupal_set_message(t("An error has occured with macro #%macro_number , form_id %form_id. Please check the errors displayed for more details.", array(
        '%macro_number' => $key,
        '%form_id' => $data['form_id'],
      )));
    }
  }
  return $results;
}