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

Provide a form to edit options for this plugin.

Overrides views_plugin::options_form

File

core/modules/views/plugins/views_plugin_style.inc, line 189
Definition of views_plugin_style.

Class

views_plugin_style
Base class to define a style plugin handler.

Code

function options_form(&$form, &$form_state) {
  parent::options_form($form, $form_state);
  // Only fields-based views can handle grouping. Style plugins can also
  // exclude themselves from being groupable by setting their "use grouping"
  // definition key to FALSE.
  // @TODO: Document "uses grouping" in docs.php when docs.php is written.
  if ($this->uses_fields() && $this->definition['uses grouping']) {
    $options = array('' => t('- None -'));
    $field_labels = $this->display->handler->get_field_labels(TRUE);
    $options += $field_labels;
    // If there are no fields, we can't group on them.
    if (count($options) > 1) {
      // This is for backward compatibility, when there was just a single
      // select form.
      if (is_string($this->options['grouping'])) {
        $grouping = $this->options['grouping'];
        $this->options['grouping'] = array();
        $this->options['grouping'][0]['field'] = $grouping;
      }
      if (isset($this->options['group_rendered']) && is_string($this->options['group_rendered'])) {
        $this->options['grouping'][0]['rendered'] = $this->options['group_rendered'];
        unset($this->options['group_rendered']);
      }

      $c = count($this->options['grouping']);
      // Add a form for every grouping, plus one.
      for ($i = 0; $i <= $c; $i++) {
        $grouping = !empty($this->options['grouping'][$i]) ? $this->options['grouping'][$i] : array();
        $grouping += array('field' => '', 'rendered' => TRUE, 'rendered_strip' => FALSE);
        $form['grouping'][$i]['field'] = array(
          '#type' => 'select',
          '#title' => t('Grouping field Nr.@number', array('@number' => $i + 1)),
          '#options' => $options,
          '#default_value' => $grouping['field'],
          '#description' => t('You may optionally specify a field by which to group the records. Leave blank to not group.'),
        );
        $form['grouping'][$i]['rendered'] = array(
          '#type' => 'checkbox',
          '#title' => t('Use rendered output to group rows'),
          '#default_value' => $grouping['rendered'],
          '#description' => t('If enabled the rendered output of the grouping field is used to group the rows.'),
          '#states' => array(
            'invisible' => array(
              ':input[name="style_options[grouping][' . $i . '][field]"]' => array('value' => ''),
            ),
          ),
        );
        $form['grouping'][$i]['rendered_strip'] = array(
          '#type' => 'checkbox',
          '#title' => t('Remove tags from rendered output'),
          '#default_value' => $grouping['rendered_strip'],
          '#states' => array(
            'invisible' => array(
              ':input[name="style_options[grouping][' . $i . '][field]"]' => array('value' => ''),
            ),
          ),
        );
      }
    }
  }

  if ($this->uses_row_class()) {
    $form['row_class'] = array(
      '#title' => t('Row class'),
      '#description' => t('The class to provide on each row.'),
      '#type' => 'textfield',
      '#default_value' => $this->options['row_class'],
    );

    if ($this->uses_fields()) {
      $form['row_class']['#description'] .= ' ' . t('You may use field tokens from the "Replacement patterns" used in "Rewrite the output of this field" for all fields.');
    }

    $form['default_row_class'] = array(
      '#title' => t('Add views row classes'),
      '#description' => t('Add the default row classes like views-row-1 to the output. You can use this to quickly reduce the amount of markup the view provides by default, at the cost of making it more difficult to apply CSS.'),
      '#type' => 'checkbox',
      '#default_value' => $this->options['default_row_class'],
    );
    $form['row_class_special'] = array(
      '#title' => t('Add striping (odd/even), first/last row classes'),
      '#description' => t('Add css classes to the first and last line, as well as odd/even classes for striping.'),
      '#type' => 'checkbox',
      '#default_value' => $this->options['row_class_special'],
    );
  }

  if (!$this->uses_fields() || !empty($this->options['uses_fields'])) {
    $form['uses_fields'] = array(
      '#type' => 'checkbox',
      '#title' => t('Force using fields'),
      '#description' => t('If neither the row nor the style plugin supports fields, this field allows to enable them, so you can for example use groupby.'),
      '#default_value' => $this->options['uses_fields'],
    );
  }
}