You are here

function rules_conditional_add_case in Conditional Rules 8

Same name and namespace in other branches
  1. 7 includes/rules_conditional.rules_admin.inc \rules_conditional_add_case()

Provides a variant of rules_ui_add_element() to create a case. @todo Remove when http://drupal.org/node/1676998 is fixed.

1 string reference to 'rules_conditional_add_case'
_rules_conditional_rules_ui_menu_alter in includes/rules_conditional.rules_admin.inc
Provides menu callbacks to extend Rules UI for conditionals.

File

includes/rules_conditional.rules_admin.inc, line 82
Extensions to Rules UI.

Code

function rules_conditional_add_case($form, &$form_state, $rules_config, $plugin_name, RulesContainerPlugin $parent, $base_path) {

  // Build condition form.
  RulesPluginUI::$basePath = $base_path;
  if (!isset($form_state['rules_element'])) {
    RulesPluginUI::formDefaults($form, $form_state);
    $form_state += array(
      'parent_element' => $parent,
      'plugin' => $plugin_name,
    );
    $element = rules_plugin_factory($plugin_name);

    // Always add the new element at the bottom, thus set an appropriate weight.
    $iterator = $parent
      ->getIterator();
    if ($sibling = end($iterator)) {
      $element->weight = $sibling->weight + 1;
    }
    $element
      ->setParent($parent);
    $form_state['rules_element'] = $element;
  }

  // Build element form.
  $form_state['rules_element']
    ->form($form, $form_state, array(
    'button' => TRUE,
    'init' => TRUE,
  ));
  $form['#validate'][] = 'rules_ui_edit_element_validate';
  $form['#submit'][] = 'rules_ui_edit_element_submit';
  return $form;
}