You are here

public function ComplexGrouping::buildOptionsForm in Views Complex Grouping 8

Provide a form to edit options for this plugin.

Overrides StylePluginBase::buildOptionsForm

File

src/Plugin/views/style/ComplexGrouping.php, line 64

Class

ComplexGrouping
Class ComplexGrouping.

Namespace

Drupal\views_complex_grouping\Plugin\views\style

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $field_labels = $this->displayHandler
    ->getFieldLabels(TRUE);
  foreach ($form['grouping'] as $index => $info) {
    $form['grouping'][$index]['complex_grouping'] = [
      '#type' => 'fieldset',
      '#title' => t('Limit and extra fields for grouping field No. @num', [
        '@num' => $index + 1,
      ]),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    ];
    $form['grouping'][$index]['complex_grouping']['grouping_fields'] = [
      '#type' => 'select',
      '#multiple' => TRUE,
      '#title' => t('Selected'),
      '#options' => $field_labels,
      '#default_value' => $this
        ->getGroupingDefaultValues($index, 'grouping_fields'),
      '#description' => t('Select which fields will be displayed alongside the field No. @num', [
        '@num' => $index + 1,
      ]),
    ];
    $form['grouping'][$index]['complex_grouping']['grouping_limit'] = [
      '#type' => 'textfield',
      '#title' => t('Items to display:'),
      '#default_value' => $this
        ->getGroupingDefaultValues($index, 'grouping_limit'),
      '#size' => 6,
      '#element_validate' => [
        [
          get_called_class(),
          'complexGroupingValidate',
        ],
      ],
      '#description' => t('The number of rows to show under the field Nr. @num. Leave 0 to show all of them.', [
        '@num' => $index + 1,
      ]),
    ];
    $form['grouping'][$index]['complex_grouping']['grouping_offset'] = [
      '#type' => 'textfield',
      '#title' => t('Offset:'),
      '#default_value' => $this
        ->getGroupingDefaultValues($index, 'grouping_offset'),
      '#size' => 6,
      '#element_validate' => [
        [
          get_called_class(),
          'complexGroupingValidate',
        ],
      ],
      '#description' => t('The row to start on.'),
    ];
  }
}