You are here

public function ViewsRulesLoopUI::form in Views Rules 7

Implements RulesPluginUIInterface::form().

Overrides RulesActionContainerUI::form

File

rules/views_rules.ui.inc, line 16
Rules UI implementation for Views Rules plugins.

Class

ViewsRulesLoopUI
Views loop administrative UI.

Code

public function form(&$form, &$form_state, $options = array(), $iterator = NULL) {
  $baseCount = count(explode('/', RulesPluginUI::$basePath));
  $op = arg($baseCount + 2);
  if ($op == 'add') {

    // Redirect to extended path.
    $pathAddView = RulesPluginUI::path($this->element
      ->root()->name, 'add-view-loop', $this->element
      ->parentElement());
    drupal_goto($pathAddView);
  }

  // Build form with "Save" button.
  $options['init'] = FALSE;
  parent::form($form, $form_state, $options, $iterator);

  // Add row variable form.
  if ($display = $this->element
    ->getViewIterator()) {
    $settings = $this->element->settings;
    foreach ($display
      ->get_rules_variable_info() as $var_name => $var_info) {
      $form['views_row'][$var_name] = array(
        '#type' => 'fieldset',
        '#title' => check_plain($var_info['label']),
        '#description' => filter_xss(isset($var_info['description']) ? $var_info['description'] : ''),
      );
      $form['views_row'][$var_name]['label'] = array(
        '#type' => 'textfield',
        '#title' => t('Variable label'),
        '#default_value' => isset($settings[$var_name . ':label']) ? $settings[$var_name . ':label'] : $var_info['label'],
        '#required' => TRUE,
      );
      $form['views_row'][$var_name]['var'] = array(
        '#type' => 'textfield',
        '#title' => t('Variable name'),
        '#default_value' => isset($settings[$var_name . ':var']) ? $settings[$var_name . ':var'] : $var_name,
        '#description' => t('The variable name must contain only lowercase letters, numbers, and underscores and must be unique in the current scope.'),
        '#element_validate' => array(
          'rules_ui_element_machine_name_validate',
        ),
        '#required' => TRUE,
      );
    }
    if (element_children($form['views_row'])) {
      $help = '<div class="description">' . t('Adjust the names and labels of row variables (from the view) available in each iteration of the view loop, but note that renaming of already utilizied variables invalidates the existing uses.') . '</div>';
      $form['views_row'] += array(
        '#tree' => TRUE,
        '#prefix' => '<h4 class="rules-form-heading">' . t('Row variables') . '</h4>' . $help,
      );
    }
  }
}