You are here

function patterns_export_actions_from_form in Patterns 7

Same name and namespace in other branches
  1. 7.2 patterns_export/api.inc \patterns_export_actions_from_form()

Constructs patterns actions based on the current state of a form

Parameters

string $form_id The name of the form:

array $args (optional): Extra arguments to be passed to the form

string $tag (optional) : The tag associated with the action

string $action (optional): The pattern action (CREATE / MODIFY / DELETE). Defaults PATTERNS_MODIFY

Return value

array $result The pattern action

3 calls to patterns_export_actions_from_form()
shortcut_patterns_export_all_set in patterns_components/components/shortcut.inc
taxonomy_patterns_export_all_terms in patterns_components/components/taxonomy.inc
taxonomy_patterns_export_all_vocs in patterns_components/components/taxonomy.inc

File

patterns_export/api.inc, line 26
Export the components configuration to a Pattern file.

Code

function patterns_export_actions_from_form($form_id, $args = array(), $tag = NULL, $action = PATTERNS_MODIFY) {
  set_error_handler("patterns_export_error_handler", E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR);

  // Move this inside the Macro module
  // Macro should check that only one user is using that
  $form_state = array();
  $form_state['values'] = array();
  variable_set('patterns_extract_actions', TRUE);
  variable_set('macro_enabled', TRUE);
  variable_set('macro_submissions', array());
  $args = !is_array($args) ? array(
    $args,
  ) : $args;
  $form_state['build_info']['args'] = $args;
  drupal_form_submit($form_id, $form_state);
  $result = macro_get_macro();
  variable_set('macro_enabled', FALSE);
  variable_set('patterns_extract_actions', FALSE);
  if (!empty($result) || !is_null($tag)) {
    $out = array();
    foreach ($result as $entry) {
      $a = $entry['values'];
      $out[] = array(
        $action => array_merge(array(
          'tag' => $tag,
        ), $a),
      );
    }
    $result = $out;
  }
  return $result;
}