You are here

public function SlickGrouping::buildOptionsForm in Slick Views 8.2

Overrides parent::buildOptionsForm().

File

src/Plugin/views/style/SlickGrouping.php, line 49

Class

SlickGrouping
Slick style plugin with grouping support.

Namespace

Drupal\slick_views\Plugin\views\style

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $definition = $this
    ->getDefinedFormScopes();
  $states = [
    'visible' => [
      'select[name*="[grouping][0][field]"]' => [
        '!value' => '',
      ],
    ],
  ];
  if (!isset($form['grouping_limit'])) {
    $form['grouping_limit'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Grouping limit'),
      '#default_value' => $this->options['grouping_limit'],
      '#description' => $this
        ->t('Limit the amount of rows per group. Leave it empty, or 0, for no limit. Applicable only to the first level. Be sure having enough rows.'),
      '#enforced' => TRUE,
      '#states' => $states,
    ];
  }
  if (!isset($form['grouping_optionset'])) {
    $form['grouping_optionset'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Grouping optionset'),
      '#options' => $this
        ->admin()
        ->getOptionsetsByGroupOptions('main'),
      '#default_value' => $this->options['grouping_optionset'],
      '#description' => $this
        ->t('If provided, the grouping header will be treated as Slick tabs and acts like simple filters. Else regular stacking slicks. Requires: Optionset thumbnail, Vanilla unchecked, and Randomize option disabled for all optionsets, else impressing broken grouping due to reordered slides. Combine with grids to have a complete insanity.'),
      '#enforced' => TRUE,
      '#states' => $states,
    ];
  }
  $groupings = $this->options['grouping'] ?: [];
  for ($i = 0; $i <= count($groupings); $i++) {
    foreach ([
      'rendered',
      'rendered_strip',
    ] as $key) {
      $form['grouping'][$i][$key]['#field_suffix'] = '&nbsp;';
      $form['grouping'][$i][$key]['#title_display'] = 'before';
    }
  }
  $this
    ->buildSettingsForm($form, $definition);
  if (isset($form['optionset_thumbnail'])) {
    $form['optionset_thumbnail']['#description'] .= ' ' . $this
      ->t('This will be used (taken over) for grouping tabs if Grouping optionset is provided. Including all thumbnail-related options: Skin tthumbnail, Thumbnail position.');
  }
}