You are here

public function Grouping::buildConfigurationForm in Search API Grouping 8

Return the settings form for this processor.

Overrides FieldsProcessorPluginBase::buildConfigurationForm

File

src/Plugin/search_api/processor/Grouping.php, line 58

Class

Grouping
Processor for grouping up items on behalf of user defined fields.

Namespace

Drupal\search_api_grouping\Plugin\search_api\processor

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $supported_fields = $this
    ->getSupportedFields();
  $form['grouping_fields'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Fields to collapse on'),
    '#options' => $supported_fields['field_options'],
    '#attributes' => [
      'class' => [
        'search-api-checkboxes-list',
      ],
    ],
    '#description' => $this
      ->t('Choose the fields upon which to collapse the results into groups. Note that while selecting multiple fields is technicially supported, it may result in unexpected behaviour.'),
    '#default_value' => $this->configuration['grouping_fields'],
  ];
  $form['group_sort'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Group sort'),
    '#options' => $supported_fields['field_sorts'],
    '#description' => $this
      ->t('Choose the field by to sort within each group, the groups themselves will be sorted by the main query sorts.'),
    '#default_value' => $this->configuration['group_sort'],
  ];
  $form['group_sort_direction'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Group sort direction'),
    '#options' => [
      'asc' => $this
        ->t('Ascending'),
      'desc' => $this
        ->t('Descending'),
    ],
    '#default_value' => $this->configuration['group_sort_direction'],
  ];
  $form['truncate'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Truncate results before facets'),
    '#description' => $this
      ->t('If checked, facet counts are based on the most relevant document of each group matching the query, otherwise they are calculated for all documents before grouping.'),
    '#default_value' => $this->configuration['truncate'],
  ];
  $form['group_limit'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Results per group'),
    '#description' => $this
      ->t('The number of results are limited per group. By default, 1 result per group is returned.'),
    '#default_value' => $this->configuration['group_limit'],
    '#element_validate' => [
      'element_validate_integer_positive',
    ],
    '#size' => 3,
  ];
  return $form;
}