You are here

function system_patterns_build in Patterns 7

Same name and namespace in other branches
  1. 7.2 patterns_components/components/system.inc \system_patterns_build()

File

patterns_components/components/system.inc, line 347

Code

function system_patterns_build($action, $form_id, &$data = NULL, &$a) {
  $status = PATTERNS_SUCCESS;
  $msg = '';
  $result = NULL;
  if ($form_id == 'set_active_theme') {
    $data['op'] = t('Save configuration');

    // TODO: ??

    //module_load_include('inc', 'system', 'system.admin');

    // $result = $data;
  }
  elseif ($form_id == 'call_php_func_form') {
    $data['type'] = empty($data['type']) ? '' : $data['type'];
    $data['module'] = empty($data['module']) ? '' : $data['module'];
    $data['name'] = empty($data['name']) ? '' : $data['name'];
    $data['filepath'] = empty($data['filepath']) ? '' : $data['filepath'];
    if (empty($data['arguments'])) {
      $data['arguments'] = array();
    }
    elseif (!is_array($data['arguments'])) {
      $data['arguments'] = array(
        $data['arguments'],
      );
    }
    _call_php_func_include_files($data);

    // TODO: this works here?
    if (!is_callable($data['function'])) {
      $status = PATTERNS_ERR;
      $msg = t('The given function %func is not callable', array(
        '%func' => $data['function'],
      ));
    }

    // $result = $data;
  }
  else {

    // Running a user-provided form through tag 'form'.
    $form_state = $data['form_state_extras'];
    unset($data['form_state_extras']);
    unset($data['include']);
    $form_state['values'] = $data;
    $form_state['submitted'] = FALSE;
    if (!isset($form_state['storage'])) {
      $form_state['storage'] = NULL;
    }
    $result = $form_state;
  }
  return patterns_results($status, $msg, $result);
}