You are here

function rules_admin_form_add in Rules 6

Returns the form for the add operation This handles adding conditions and actions

Parameters

$type Either 'action' or 'condition' or 'op':

$parent_id The id of the the element where the condition / action is to be added:

1 call to rules_admin_form_add()
rules_admin_form_edit in rules_admin/rules_admin.rule_forms.inc
Returns the form for the edit operation This handles editing conditions and actions
1 string reference to 'rules_admin_form_add'
rules_admin_menu in rules_admin/rules_admin.module
Implementation of hook_menu().

File

rules_admin/rules_admin.rule_forms.inc, line 241

Code

function rules_admin_form_add(&$form_state, $proxy, $type, $parent_id = NULL) {
  $form_state['proxy'] =& $proxy;
  $rule = $proxy
    ->get_rule();
  _rules_element_defaults($rule);
  if (in_array($type, array(
    'action',
    'condition',
    'op',
  ))) {
    if (!isset($form_state['element'])) {

      //initial step!
      $form_state += array(
        'element' => array(
          '#type' => $type,
        ),
        'step' => 0,
      );
    }
    $element =& $form_state['element'];
    $element += array(
      '#id' => NULL,
      '#settings' => array(),
    );

    // Due to adding storage during the form build, the form will be rebuilt
    // immediately. So be sure to increase the step only out of a #submit callback.
    // Also see http://drupal.org/node/302240.
    if ($form_state['step'] == 0) {
      if (isset($parent_id) && is_array($parent = $proxy
        ->get_element(intval($parent_id)))) {
        if (function_exists($function = 'rules_admin_form_add_' . $element['#type'])) {
          $form_state['parent_id'] = intval($parent_id);
          _rules_element_defaults($parent);
          $form = $function($form_state, $element, $parent);
          return rules_admin_form_pack_storage($form, $form_state);
        }
      }
    }
    else {
      if (function_exists($function = 'rules_admin_form_edit_' . $type)) {
        $form = $function($form_state, $element);
        return rules_admin_form_pack_storage($form, $form_state);
      }
    }
  }
  drupal_not_found();
  exit;
}