You are here

function views_ifempty_handler_field::options_form in Views If Empty 7

Same name and namespace in other branches
  1. 6 handlers/views_ifempty_handler_field.inc \views_ifempty_handler_field::options_form()

Add our form elements.

Overrides views_handler_field::options_form

File

includes/views/handlers/views_ifempty_handler_field.inc, line 28
A views handler to output an alterate field when a field is empty.

Class

views_ifempty_handler_field
@file A views handler to output an alterate field when a field is empty.

Code

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

  // Scan all the fields and add them as options for our field selectors.
  $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;
    }
    $fields[$field] = $handler
      ->ui_name();
  }
  $form['emptyfield'] = array(
    '#type' => 'select',
    '#title' => t('If this field is empty'),
    '#description' => t('Check this field to see if is empty. This field will be output normally if not empty.'),
    '#options' => $fields,
    '#default_value' => $this->options['emptyfield'],
  );
  $form['outputfield'] = array(
    '#type' => 'select',
    '#title' => t('Then output this field'),
    '#description' => t('Only output this field when the other field is empty. This field will be hidden if the other field is not empty.'),
    '#options' => $fields,
    '#default_value' => $this->options['outputfield'],
  );
  $form['reverse'] = array(
    '#type' => 'checkbox',
    '#title' => t('Reverse'),
    '#description' => t('Reverse the normal behavior. Show the output field if the other field is <em>not</em> empty. If the other field is empty, output nothing.'),
    '#default_value' => $this->options['reverse'],
  );
}