You are here

public function StylePluginBase::buildOptionsForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/style/StylePluginBase.php \Drupal\views\Plugin\views\style\StylePluginBase::buildOptionsForm()

Provide a form to edit options for this plugin.

Overrides PluginBase::buildOptionsForm

8 calls to StylePluginBase::buildOptionsForm()
EntityReference::buildOptionsForm in core/modules/views/src/Plugin/views/style/EntityReference.php
Provide a form to edit options for this plugin.
Grid::buildOptionsForm in core/modules/views/src/Plugin/views/style/Grid.php
Provide a form to edit options for this plugin.
HtmlList::buildOptionsForm in core/modules/views/src/Plugin/views/style/HtmlList.php
Render the given style.
Mapping::buildOptionsForm in core/modules/views/src/Plugin/views/style/Mapping.php
Provide a form to edit options for this plugin.
Rss::buildOptionsForm in core/modules/views/src/Plugin/views/style/Rss.php
Provide a form to edit options for this plugin.

... See full list

9 methods override StylePluginBase::buildOptionsForm()
DefaultSummary::buildOptionsForm in core/modules/views/src/Plugin/views/style/DefaultSummary.php
Provide a form to edit options for this plugin.
EntityReference::buildOptionsForm in core/modules/views/src/Plugin/views/style/EntityReference.php
Provide a form to edit options for this plugin.
Grid::buildOptionsForm in core/modules/views/src/Plugin/views/style/Grid.php
Provide a form to edit options for this plugin.
HtmlList::buildOptionsForm in core/modules/views/src/Plugin/views/style/HtmlList.php
Render the given style.
Mapping::buildOptionsForm in core/modules/views/src/Plugin/views/style/Mapping.php
Provide a form to edit options for this plugin.

... See full list

File

core/modules/views/src/Plugin/views/style/StylePluginBase.php, line 270
Contains \Drupal\views\Plugin\views\style\StylePluginBase.

Class

StylePluginBase
Base class for views style plugins.

Namespace

Drupal\views\Plugin\views\style

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);

  // Only fields-based views can handle grouping.  Style plugins can also exclude
  // themselves from being groupable by setting their "usesGrouping" property
  // to FALSE.
  // @TODO: Document "usesGrouping" in docs.php when docs.php is written.
  if ($this
    ->usesFields() && $this
    ->usesGrouping()) {
    $options = array(
      '' => $this
        ->t('- None -'),
    );
    $field_labels = $this->displayHandler
      ->getFieldLabels(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' => $this
            ->t('Grouping field Nr.@number', array(
            '@number' => $i + 1,
          )),
          '#options' => $options,
          '#default_value' => $grouping['field'],
          '#description' => $this
            ->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' => $this
            ->t('Use rendered output to group rows'),
          '#default_value' => $grouping['rendered'],
          '#description' => $this
            ->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' => $this
            ->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
    ->usesRowClass()) {
    $form['row_class'] = array(
      '#title' => $this
        ->t('Row class'),
      '#description' => $this
        ->t('The class to provide on each row.'),
      '#type' => 'textfield',
      '#default_value' => $this->options['row_class'],
    );
    if ($this
      ->usesFields()) {
      $form['row_class']['#description'] .= ' ' . $this
        ->t('You may use field tokens from as per the "Replacement patterns" used in "Rewrite the output of this field" for all fields.');
    }
    $form['default_row_class'] = array(
      '#title' => $this
        ->t('Add views row classes'),
      '#description' => $this
        ->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'],
    );
  }
  if (!$this
    ->usesFields() || !empty($this->options['uses_fields'])) {
    $form['uses_fields'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Force using fields'),
      '#description' => $this
        ->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'],
    );
  }
}