You are here

function MefibsDisplayExtender::setDefaultValues in MEFIBS - More exposed forms in blocks 8

Set default values for the exposed items of a block.

File

lib/Drupal/mefibs/Plugin/views/display_extender/MefibsDisplayExtender.php, line 608
Contains \Drupal\mefibs\Plugin\views\display_extender\MefibsDisplayExtender.

Class

MefibsDisplayExtender
Plugin annotation @ViewsDisplayExtender( id = "mefibs", title = @Translation("Mefibs"), help = @Translation("Provides additional exposed filter blocks for this view."), no_ui = FALSE )

Namespace

Drupal\mefibs\Plugin\views\display_extender

Code

function setDefaultValues(&$form, $block_id) {
  $elements = mefibs_get_expected_items_for_exposed_form_block($this->view, $block_id);
  $view_name = $this->view->storage
    ->id();
  $display_id = $this->view->current_display;
  if (!isset($_SESSION['views'][$view_name][$display_id]['mefibs'])) {
    return;
  }
  $items = array_keys($elements['filter']);
  $items = array_merge($items, $elements['other']);
  if (count($elements['sort'])) {
    $items[] = 'sort_by';
    $items[] = 'sort_order';
  }
  $current_filters = $_SESSION['views'][$view_name][$display_id]['mefibs'];
  foreach (element_children($form) as $element) {
    if (in_array($element, $items) && isset($current_filters[$element])) {
      $form[$element]['#default_value'] = $current_filters[$element];
    }
    if (count(element_children($form[$element]))) {
      $this
        ->setDefaultValues($form[$element], $block_id);
    }
  }
}