You are here

public function RulesRuleUI::form in Rules 7.2

Implements RulesPluginUIInterface::form().

Overrides RulesActionContainerUI::form

1 call to RulesRuleUI::form()
RulesReactionRuleUI::form in ui/ui.plugins.inc
Implements RulesPluginUIInterface::form().
1 method overrides RulesRuleUI::form()
RulesReactionRuleUI::form in ui/ui.plugins.inc
Implements RulesPluginUIInterface::form().

File

ui/ui.plugins.inc, line 27
Contains UI for diverse plugins provided by Rules.

Class

RulesRuleUI
Rule specific UI.

Code

public function form(&$form, &$form_state, $options = array(), $iterator = NULL) {
  $form_state['rules_element'] = $this->rule;
  $label = $this->element
    ->label();

  // Automatically add a counter to unlabelled rules.
  if ($label == t('unlabeled') && !$this->element
    ->isRoot() && !empty($options['init'])) {
    $parent = $this->element
      ->parentElement();
    $label .= ' ' . count($parent
      ->getIterator());
  }

  // Components have already a label. If used inside a rule-set add a label
  // though. It's called 'Name' in the UI though.
  if (!$this->element
    ->isRoot()) {
    $form['label'] = array(
      '#type' => 'textfield',
      '#title' => t('Name'),
      '#default_value' => empty($options['init']) ? $label : '',
      '#required' => TRUE,
      '#weight' => 5,
      '#description' => t('A human-readable name shortly describing the rule.'),
    );
  }
  $form += array(
    'conditions' => array(
      '#weight' => -5,
      '#tree' => TRUE,
    ),
  );
  $this->conditions
    ->form($form['conditions'], $form_state);
  unset($form['conditions']['negate']);

  // Add actions form.
  $iterator = new RecursiveIteratorIterator($this->rule
    ->actions(), RecursiveIteratorIterator::SELF_FIRST);
  parent::form($form, $form_state, $options, $iterator);

  // Hide nested elements during creation.
  $form['elements']['#access'] = empty($options['init']);
  $form['conditions']['elements']['#access'] = empty($options['init']);
  $form_state['redirect'] = RulesPluginUI::path($this->element
    ->root()->name, 'edit', $this->element);
  if (!empty($options['button'])) {
    $form['submit']['#value'] = t('Save changes');
  }
}