You are here

protected function BetterExposedFilters::defineOptions in Better Exposed Filters 8.4

Same name and namespace in other branches
  1. 8.5 src/Plugin/views/exposed_form/BetterExposedFilters.php \Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters::defineOptions()

Information about options for all kinds of purposes will be held here.


'option_name' => array(
 - 'default' => default value,
 - 'contains' => (optional) array of items this contains, with its own
     defaults, etc. If contains is set, the default will be ignored and
     assumed to be array().
 ),

Return value

array Returns the options of this handler/plugin.

Overrides InputRequired::defineOptions

File

src/Plugin/views/exposed_form/BetterExposedFilters.php, line 100

Class

BetterExposedFilters
Exposed form plugin that provides a basic exposed form.

Namespace

Drupal\better_exposed_filters\Plugin\views\exposed_form

Code

protected function defineOptions() {
  $options = parent::defineOptions();

  // General, sort, pagers, and filter.
  $bef_options = [
    'general' => [
      'autosubmit' => FALSE,
      'autosubmit_exclude_textfield' => FALSE,
      'autosubmit_textfield_delay' => 500,
      'autosubmit_hide' => FALSE,
      'input_required' => FALSE,
      'allow_secondary' => FALSE,
      'secondary_label' => $this
        ->t('Advanced options'),
      'secondary_open' => FALSE,
    ],
    'sort' => [
      'plugin_id' => 'default',
    ],
  ];

  // Initialize options if any sort is exposed.
  // Iterate over each sort and determine if any sorts are exposed.
  $is_sort_exposed = FALSE;

  /** @var \Drupal\views\Plugin\views\HandlerBase $sort */
  foreach ($this->view->display_handler
    ->getHandlers('sort') as $sort) {
    if ($sort
      ->isExposed()) {
      $is_sort_exposed = TRUE;
      break;
    }
  }
  if ($is_sort_exposed) {
    $bef_options['sort']['plugin_id'] = 'default';
  }

  // Initialize options if the pager is exposed.
  $pager = $this->view
    ->getPager();
  if ($pager && $pager
    ->usesExposed()) {
    $bef_options['pager']['plugin_id'] = 'default';
  }

  // Go through each exposed filter and set default format.

  /** @var \Drupal\views\Plugin\views\HandlerBase $filter */
  foreach ($this->view->display_handler
    ->getHandlers('filter') as $filter_id => $filter) {
    if (!$filter
      ->isExposed()) {
      continue;
    }
    $bef_options['filter'][$filter_id]['plugin_id'] = 'default';
  }

  // Iterate over bef options and convert them to be compatible with views
  // default options.
  $options += $this
    ->createOptionDefaults([
    'bef' => $bef_options,
  ]);
  return $options;
}