1 views_handler_field.inc views_handler_field::options_form(&$form, &$form_state)

Default options form that provides the label widget that all fields should have.

Overrides views_handler::options_form

File

core/modules/views/handlers/views_handler_field.inc, line 462
@todo.

Class

views_handler_field
Base field handler that has no options and renders an unformatted field.

Code

function options_form(&$form, &$form_state) {
  parent::options_form($form, $form_state);

  $label = $this->label();
  $form['custom_label'] = array(
    '#type' => 'checkbox',
    '#title' => t('Create a label'),
    '#description' => t('Enable to create a label for this field.'),
    '#default_value' => $label !== '',
    '#weight' => -103,
  );
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Label'),
    '#default_value' => $label,
    '#indentation' => 1,
    '#states' => array(
      'visible' => array(
        ':input[name="options[custom_label]"]' => array('checked' => TRUE),
      ),
    ),

    '#weight' => -102,
  );
  $form['element_label_colon'] = array(
    '#type' => 'checkbox',
    '#title' => t('Place a colon after the label'),
    '#default_value' => $this->options['element_label_colon'],
    '#indentation' => 1,
    '#states' => array(
      'visible' => array(
        ':input[name="options[custom_label]"]' => array('checked' => TRUE),
      ),
    ),
    '#weight' => -101,
  );

  $form['exclude'] = array(
    '#type' => 'checkbox',
    '#title' => t('Exclude from display'),
    '#default_value' => $this->options['exclude'],
    '#description' => t('Enable to load this field as hidden. Often used to group fields, or to use as token in another field.'),
    '#weight' => -100,
  );

  $form['style_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Style settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => 99,
  );

  $form['element_type_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Customize field HTML'),
    '#default_value' => !empty($this->options['element_type']) || (string) $this->options['element_type'] == '0' || !empty($this->options['element_class']) || (string) $this->options['element_class'] == '0',
    '#fieldset' => 'style_settings',
  );
  $form['element_type'] = array(
    '#title' => t('HTML element'),
    '#options' => $this->get_elements(),
    '#type' => 'select',
    '#default_value' => $this->options['element_type'],
    '#description' => t('Choose the HTML element to wrap around this field, e.g. H1, H2, etc.'),
    '#states' => array(
      'visible' => array(
        ':input[name="options[element_type_enable]"]' => array('checked' => TRUE),
      ),
    ),
    '#fieldset' => 'style_settings',
  );

  $form['element_class_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Create a CSS class'),
    '#states' => array(
      'visible' => array(
        ':input[name="options[element_type_enable]"]' => array('checked' => TRUE),
      ),
    ),
    '#default_value' => !empty($this->options['element_class']) || (string) $this->options['element_class'] == '0',
    '#fieldset' => 'style_settings',
  );
  $form['element_class'] = array(
    '#title' => t('CSS class'),
    '#description' => t('You may use token substitutions from the rewriting section in this class.'),
    '#type' => 'textfield',
    '#default_value' => $this->options['element_class'],
    '#states' => array(
      'visible' => array(
        ':input[name="options[element_type_enable]"]' => array('checked' => TRUE),
        ':input[name="options[element_class_enable]"]' => array('checked' => TRUE),
      ),
    ),
    '#fieldset' => 'style_settings',
  );

  $form['element_label_type_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Customize label HTML'),
    '#default_value' => !empty($this->options['element_label_type']) || (string) $this->options['element_label_type'] == '0' || !empty($this->options['element_label_class']) || (string) $this->options['element_label_class'] == '0',
    '#fieldset' => 'style_settings',
  );
  $form['element_label_type'] = array(
    '#title' => t('Label HTML element'),
    '#options' => $this->get_elements(FALSE),
    '#type' => 'select',
    '#default_value' => $this->options['element_label_type'],
    '#description' => t('Choose the HTML element to wrap around this label, e.g. H1, H2, etc.'),
    '#states' => array(
      'visible' => array(
        ':input[name="options[element_label_type_enable]"]' => array('checked' => TRUE),
      ),
    ),
    '#fieldset' => 'style_settings',
  );
  $form['element_label_class_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Create a CSS class'),
    '#states' => array(
      'visible' => array(
        ':input[name="options[element_label_type_enable]"]' => array('checked' => TRUE),
      ),
    ),
    '#default_value' => !empty($this->options['element_label_class']) || (string) $this->options['element_label_class'] == '0',
    '#fieldset' => 'style_settings',
  );
  $form['element_label_class'] = array(
    '#title' => t('CSS class'),
    '#description' => t('You may use token substitutions from the rewriting section in this class.'),
    '#type' => 'textfield',
    '#default_value' => $this->options['element_label_class'],
    '#states' => array(
      'visible' => array(
        ':input[name="options[element_label_type_enable]"]' => array('checked' => TRUE),
        ':input[name="options[element_label_class_enable]"]' => array('checked' => TRUE),
      ),
    ),
    '#fieldset' => 'style_settings',
  );

  $form['element_wrapper_type_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Customize field and label wrapper HTML'),
    '#default_value' => !empty($this->options['element_wrapper_type']) || (string) $this->options['element_wrapper_type'] == '0' || !empty($this->options['element_wrapper_class']) || (string) $this->options['element_wrapper_class'] == '0',
    '#fieldset' => 'style_settings',
  );
  $form['element_wrapper_type'] = array(
    '#title' => t('Wrapper HTML element'),
    '#options' => $this->get_elements(FALSE),
    '#type' => 'select',
    '#default_value' => $this->options['element_wrapper_type'],
    '#description' => t('Choose the HTML element to wrap around this field and label, e.g. H1, H2, etc. This may not be used if the field and label are not rendered together, such as with a table.'),
    '#states' => array(
      'visible' => array(
        ':input[name="options[element_wrapper_type_enable]"]' => array('checked' => TRUE),
      ),
    ),
    '#fieldset' => 'style_settings',
  );

  $form['element_wrapper_class_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Create a CSS class'),
    '#states' => array(
      'visible' => array(
        ':input[name="options[element_wrapper_type_enable]"]' => array('checked' => TRUE),
      ),
    ),
    '#default_value' => !empty($this->options['element_wrapper_class']) || (string) $this->options['element_wrapper_class'] == '0',
    '#fieldset' => 'style_settings',
  );
  $form['element_wrapper_class'] = array(
    '#title' => t('CSS class'),
    '#description' => t('You may use token substitutions from the rewriting section in this class.'),
    '#type' => 'textfield',
    '#default_value' => $this->options['element_wrapper_class'],
    '#states' => array(
      'visible' => array(
        ':input[name="options[element_wrapper_class_enable]"]' => array('checked' => TRUE),
        ':input[name="options[element_wrapper_type_enable]"]' => array('checked' => TRUE),
      ),
    ),
    '#fieldset' => 'style_settings',
  );

  $form['element_default_classes'] = array(
    '#type' => 'checkbox',
    '#title' => t('Add default classes'),
    '#default_value' => $this->options['element_default_classes'],
    '#description' => t('Use default Views classes to identify the field, field label and field content.'),
    '#fieldset' => 'style_settings',
  );

  $form['alter'] = array(
    '#title' => t('Rewrite results'),
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => 100,
  );

  $defaults_changed = FALSE;
  if ($this->options['alter']['alter_text'] || 
    $this->options['alter']['make_link'] || 
    $this->options['alter']['trim'] || 
    $this->options['alter']['strip_tags'] || 
    $this->options['alter']['nl2br']) {
    $defaults_changed = TRUE;
  }
  if ($defaults_changed) {
    $form['alter']['#collapsed'] = FALSE;
  }

  if ($this->allow_advanced_render()) {
    $form['alter']['#tree'] = TRUE;
    $form['alter']['alter_text'] = array(
      '#type' => 'checkbox',
      '#title' => t('Rewrite the output of this field'),
      '#description' => t('Enable to override the output of this field with custom text or replacement tokens.'),
      '#default_value' => $this->options['alter']['alter_text'],
    );

    $form['alter']['text'] = array(
      '#title' => t('Text'),
      '#type' => 'textarea',
      '#default_value' => $this->options['alter']['text'],
      '#description' => t('The text to display for this field. You may include HTML. You may enter data from this view as per the "Replacement patterns" below.'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][alter_text]"]' => array('checked' => TRUE),
        ),
      ),
    );

    $form['alter']['make_link'] = array(
      '#type' => 'checkbox',
      '#title' => t('Output this field as a link'),
      '#description' => t('If checked, this field will be made into a link. The destination must be given below.'),
      '#default_value' => $this->options['alter']['make_link'],
    );
    $form['alter']['path'] = array(
      '#title' => t('Link path'),
      '#type' => 'textfield',
      '#default_value' => $this->options['alter']['path'],
      '#description' => t('The Backdrop path or absolute URL for this link. You may enter data from this view as per the "Replacement patterns" below.'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
        ),
      ),
      '#maxlength' => 255,
    );
    $form['alter']['absolute'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use absolute path'),
      '#default_value' => $this->options['alter']['absolute'],
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
        ),
      ),
    );
    $form['alter']['replace_spaces'] = array(
      '#type' => 'checkbox',
      '#title' => t('Replace spaces with dashes'),
      '#default_value' => $this->options['alter']['replace_spaces'],
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
        ),
      ),
    );
    $form['alter']['external'] = array(
      '#type' => 'checkbox',
      '#title' => t('External server URL'),
      '#default_value' => $this->options['alter']['external'],
      '#description' => t("Links to an external server using a full URL: e.g. 'http://www.example.com' or 'www.example.com'."),
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
        ),
      ),
    );
    $form['alter']['path_case'] = array(
      '#type' => 'select',
      '#title' => t('Transform the case'),
      '#description' => t('When printing url paths, how to transform the case of the filter value.'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
        ),
      ),
      '#options' => array(
        'none' => t('No transform'),
        'upper' => t('Upper case'),
        'lower' => t('Lower case'),
        'ucfirst' => t('Capitalize first letter'),
        'ucwords' => t('Capitalize each word'),
      ),
      '#default_value' => $this->options['alter']['path_case'],
    );
    $form['alter']['link_class'] = array(
      '#title' => t('Link class'),
      '#type' => 'textfield',
      '#default_value' => $this->options['alter']['link_class'],
      '#description' => t('The CSS class to apply to the link.'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
        ),
      ),
    );
    $form['alter']['alt'] = array(
      '#title' => t('Title text'),
      '#type' => 'textfield',
      '#default_value' => $this->options['alter']['alt'],
      '#description' => t('Text to place as "title" text which most browsers display as a tooltip when hovering over the link.'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
        ),
      ),
    );
    $form['alter']['rel'] = array(
      '#title' => t('Rel Text'),
      '#type' => 'textfield',
      '#default_value' => $this->options['alter']['rel'],
      '#description' => t('Include Rel attribute for use in lightbox2 or other javascript utility.'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
        ),
      ),
    );
    $form['alter']['prefix'] = array(
      '#title' => t('Prefix text'),
      '#type' => 'textfield',
      '#default_value' => $this->options['alter']['prefix'],
      '#description' => t('Any text to display before this link. You may include HTML.'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
        ),
      ),
    );
    $form['alter']['suffix'] = array(
      '#title' => t('Suffix text'),
      '#type' => 'textfield',
      '#default_value' => $this->options['alter']['suffix'],
      '#description' => t('Any text to display after this link. You may include HTML.'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
        ),
      ),
    );
    $form['alter']['target'] = array(
      '#title' => t('Target'),
      '#type' => 'textfield',
      '#default_value' => $this->options['alter']['target'],
      '#description' => t("Target of the link, such as _blank, _parent or an iframe's name. This field is rarely used."),
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
        ),
      ),
    );


    // Get a list of the available fields and arguments for token replacement.
    $options = array();
    foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) {
      $options[t('Fields')]["[$field]"] = $handler->ui_name();
      // We only use fields up to (and including) this one.
      if ($field == $this->options['id']) {
        break;
      }
    }
    $count = 0; // This lets us prepare the key as we want it printed.
    foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) {
      $options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->ui_name()));
      $options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name()));
    }

    $this->document_self_tokens($options[t('Fields')]);

    // Default text.
    $output = t('<p>You must add some additional fields to this display before using this field. These fields may be marked as <em>Exclude from display</em> if you prefer. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.</p>');
    // We have some options, so make a list.
    if (!empty($options)) {
      $output = t('<p>The following tokens are available for this field. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.
If you would like to have the characters \'[\' and \']\' please use the html entity codes \'%5B\' or  \'%5D\' or they will get replaced with empty space.</p>');
      foreach (array_keys($options) as $type) {
        if (!empty($options[$type])) {
          $items = array();
          foreach ($options[$type] as $key => $value) {
            $items[] = $key . ' == ' . check_plain($value);
          }
          $output .= theme('item_list', 
          array(
            'items' => $items,
            'type' => $type
          ));
        }
      }
    }
    // This construct uses 'hidden' and not markup because process doesn't
    // run. It also has an extra div because the dependency wants to hide
    // the parent in situations like this, so we need a second div to
    // make this work.
    $form['alter']['help'] = array(
      '#type' => 'fieldset',
      '#title' => t('Replacement patterns'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#value' => $output,
      '#states' => array(
        'visible' => array(
          array(
            ':input[name="options[alter][make_link]"]' => array('checked' => TRUE),
          ),
          array(
            ':input[name="options[alter][alter_text]"]' => array('checked' => TRUE),
          ),
          array(
            ':input[name="options[alter][more_link]"]' => array('checked' => TRUE),
          ),
        ),
      ),
    );

    $form['alter']['trim'] = array(
      '#type' => 'checkbox',
      '#title' => t('Trim this field to a maximum length'),
      '#description' => t('Enable to trim the field to a maximum length of characters'),
      '#default_value' => $this->options['alter']['trim'],
    );

    $form['alter']['max_length'] = array(
      '#title' => t('Maximum length'),
      '#type' => 'textfield',
      '#default_value' => $this->options['alter']['max_length'],
      '#description' => t('The maximum number of characters this field can be.'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][trim]"]' => array('checked' => TRUE),
        ),
      ),
    );

    $form['alter']['word_boundary'] = array(
      '#type' => 'checkbox',
      '#title' => t('Trim only on a word boundary'),
      '#description' => t('If checked, this field be trimmed only on a word boundary. This is guaranteed to be the maximum characters stated or less. If there are no word boundaries this could trim a field to nothing.'),
      '#default_value' => $this->options['alter']['word_boundary'],
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][trim]"]' => array('checked' => TRUE),
        ),
      ),
    );

    $form['alter']['ellipsis'] = array(
      '#type' => 'checkbox',
      '#title' => t('Add an ellipsis'),
      '#description' => t('If checked, a "..." will be added if a field was trimmed.'),
      '#default_value' => $this->options['alter']['ellipsis'],
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][trim]"]' => array('checked' => TRUE),
        ),
      ),
    );

    $form['alter']['more_link'] = array(
      '#type' => 'checkbox',
      '#title' => t('Add a read-more link if output is trimmed.'),
      '#description' => t('If checked, a read-more link will be added at the end of the trimmed output'),
      '#default_value' => $this->options['alter']['more_link'],
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][trim]"]' => array('checked' => TRUE),
        ),
      ),
    );

    $form['alter']['more_link_text'] = array(
      '#type' => 'textfield',
      '#title' => t('More link text'),
      '#default_value' => $this->options['alter']['more_link_text'],
      '#description' => t('The text which will be displayed on the more link. You may enter data from this view as per the "Replacement patterns" above.'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][trim]"]' => array('checked' => TRUE),
          ':input[name="options[alter][more_link]"]' => array('checked' => TRUE),
        ),
      ),
    );
    $form['alter']['more_link_path'] = array(
      '#type' => 'textfield',
      '#title' => t('More link path'),
      '#default_value' => $this->options['alter']['more_link_path'],
      '#description' => t('The path which is used for the more link. You may enter data from this view as per the "Replacement patterns" above.'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][trim]"]' => array('checked' => TRUE),
          ':input[name="options[alter][more_link]"]' => array('checked' => TRUE),
        ),
      ),
    );

    $form['alter']['html'] = array(
      '#type' => 'checkbox',
      '#title' => t('Field can contain HTML'),
      '#description' => t('If checked, HTML corrector will be run to ensure tags are properly closed after trimming.'),
      '#default_value' => $this->options['alter']['html'],
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][trim]"]' => array('checked' => TRUE),
        ),
      ),
    );

    $form['alter']['strip_tags'] = array(
      '#type' => 'checkbox',
      '#title' => t('Strip HTML tags'),
      '#description' => t('If checked, all HTML tags will be stripped.'),
      '#default_value' => $this->options['alter']['strip_tags'],
    );

    $form['alter']['preserve_tags'] = array(
      '#type' => 'textfield',
      '#title' => t('Preserve certain tags'),
      '#description' => t('List the tags that need to be preserved during the stripping process. example &quot;&lt;p&gt; &lt;br&gt;&quot; which will preserve all p and br elements'),
      '#default_value' => $this->options['alter']['preserve_tags'],
      '#states' => array(
        'visible' => array(
          ':input[name="options[alter][strip_tags]"]' => array('checked' => TRUE),
        ),
      ),
    );

    $form['alter']['trim_whitespace'] = array(
      '#type' => 'checkbox',
      '#title' => t('Remove whitespace'),
      '#description' => t('If checked, all whitespaces at the beginning and the end of the output will be removed.'),
      '#default_value' => $this->options['alter']['trim_whitespace'],
    );

    $form['alter']['nl2br'] = array(
      '#type' => 'checkbox',
      '#title' => t('Convert newlines to HTML &lt;br&gt; tags'),
      '#description' => t('If checked, all newlines chars (e.g. \n) are converted into HTML &lt;br&gt; tags.'),
      '#default_value' => $this->options['alter']['nl2br'],
    );
  }

  $form['empty_field_behavior'] = array(
    '#type' => 'fieldset',
    '#title' => t('No results behavior'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => 100,
  );

  $form['empty'] = array(
    '#type' => 'textarea',
    '#title' => t('No results text'),
    '#default_value' => $this->options['empty'],
    '#description' => t('Provide text to display if this field contains an empty result. You may include HTML. You may enter data from this view as per the "Replacement patterns" in the "Rewrite Results" section below.'),
    '#fieldset' => 'empty_field_behavior',
  );

  $form['empty_zero'] = array(
    '#type' => 'checkbox',
    '#title' => t('Count the number 0 as empty'),
    '#default_value' => $this->options['empty_zero'],
    '#description' => t('Enable to display the "no results text" if the field contains the number 0.'),
    '#fieldset' => 'empty_field_behavior',
  );

  $form['hide_empty'] = array(
    '#type' => 'checkbox',
    '#title' => t('Hide if empty'),
    '#default_value' => $this->options['hide_empty'],
    '#description' => t('Enable to hide this field if it is empty. Note that the field label or rewritten output may still be displayed. To hide labels, check the style or row style settings for empty fields. To hide rewritten content, check the "Hide rewriting if empty" checkbox.'),
    '#fieldset' => 'empty_field_behavior',
  );

  $form['hide_alter_empty'] = array(
    '#type' => 'checkbox',
    '#title' => t('Hide rewriting if empty'),
    '#default_value' => $this->options['hide_alter_empty'],
    '#description' => t('Do not display rewritten content if this field is empty.'),
    '#fieldset' => 'empty_field_behavior',
  );
}