You are here

public function SqlBase::exposedFormAlter in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/pager/SqlBase.php \Drupal\views\Plugin\views\pager\SqlBase::exposedFormAlter()
  2. 9 core/modules/views/src/Plugin/views/pager/SqlBase.php \Drupal\views\Plugin\views\pager\SqlBase::exposedFormAlter()

Overrides PagerPluginBase::exposedFormAlter

File

core/modules/views/src/Plugin/views/pager/SqlBase.php, line 353

Class

SqlBase
A common base class for sql based pager.

Namespace

Drupal\views\Plugin\views\pager

Code

public function exposedFormAlter(&$form, FormStateInterface $form_state) {
  if ($this
    ->itemsPerPageExposed()) {
    $options = explode(',', $this->options['expose']['items_per_page_options']);
    $sanitized_options = [];
    if (is_array($options)) {
      foreach ($options as $option) {
        $sanitized_options[intval($option)] = intval($option);
      }
      if (!empty($this->options['expose']['items_per_page_options_all']) && !empty($this->options['expose']['items_per_page_options_all_label'])) {
        $sanitized_options['All'] = $this->options['expose']['items_per_page_options_all_label'];
      }
      $form['items_per_page'] = [
        '#type' => 'select',
        '#title' => $this->options['expose']['items_per_page_label'],
        '#options' => $sanitized_options,
        '#default_value' => $this
          ->getItemsPerPage(),
      ];
    }
  }
  if ($this
    ->isOffsetExposed()) {
    $form['offset'] = [
      '#type' => 'textfield',
      '#size' => 10,
      '#maxlength' => 10,
      '#title' => $this->options['expose']['offset_label'],
      '#default_value' => $this
        ->getOffset(),
    ];
  }
}