You are here

public function ViewsConditionalHandler::options_form in Views Conditional 7

Views form elements.

Overrides views_handler_field::options_form

File

includes/views/handlers/views_conditional_handler.inc, line 45
Handles conditionals in Views. IF xxx THEN yyy...

Class

ViewsConditionalHandler
@file Handles conditionals in Views. IF xxx THEN yyy...

Code

public function options_form(&$form, &$form_state) {
  parent::options_form($form, $form_state);
  $form['relationship']['#access'] = FALSE;

  // Display all labels weighted less than the current label.
  $fields = array(
    0 => '- ' . t('no field selected') . ' -',
  );
  foreach ($this->view->display_handler
    ->get_handlers('field') as $field => $handler) {

    // We only use fields up to (not including) this one.
    if ($field == $this->options['id']) {
      break;
    }
    $title = $handler
      ->ui_name();
    $fields[$field] = "[{$field}] == {$title}";
  }
  $form['if'] = array(
    '#type' => 'select',
    '#title' => t('If this field...'),
    '#options' => $fields,
    '#default_value' => $this->options['if'],
  );
  $form['condition'] = array(
    '#type' => 'select',
    '#title' => t('Is...'),
    '#options' => $this->conditions,
    '#default_value' => $this->options['condition'],
  );
  $form['equalto'] = array(
    '#type' => 'textfield',
    '#title' => t('This value'),
    '#description' => t('Input a value to compare the field against.  Replacement variables may be used'),
    '#default_value' => $this->options['equalto'],
  );
  $form['then'] = array(
    '#type' => 'textarea',
    '#title' => t('Then output this...'),
    '#description' => t('Input what should be output.  Replacement variables may be used.'),
    '#default_value' => $this->options['then'],
  );
  $form['or'] = array(
    '#type' => 'textarea',
    '#title' => t('Otherwise, output this...'),
    '#description' => t('Input what should be output if the above conditions do NOT evaluate to true.'),
    '#default_value' => $this->options['or'],
  );
  $form['strip_tags'] = array(
    '#type' => 'checkbox',
    '#title' => t('Strip html tags from the output'),
    '#default_value' => $this->options['strip_tags'],
  );
  $form['replacements'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Replacement Variables'),
  );
  $form['replacements']['notice'] = array(
    '#markup' => 'You may use any of these replacement variables in the "equals" or the "output" text fields.  If you wish to use brackets ([ or ]), replace them with %5D or %5E.',
    '#prefix' => '<p>',
    '#suffix' => '</p>',
  );
  $items = array(
    'DATE_UNIX => Current date / time, in UNIX timestamp format (' . REQUEST_TIME . ')',
    'DATE_STAMP => Current date / time, in standard format (' . format_date(REQUEST_TIME) . ')',
  );
  foreach ($this->view->display_handler
    ->get_handlers('field') as $field => $handler) {

    // We only use fields up to (not including) this one.
    if ($field == $this->options['id']) {
      break;
    }
    $title = $handler
      ->ui_name();
    $items[] = "[{$field}] == {$title}";
  }
  $form['replacements']['variables'] = array(
    '#markup' => theme('item_list', array(
      'items' => $items,
    )),
  );
}