We have a calendar view that has several filters on it, including an exposed multi-select term widget.

When paginating back and forth between days/months/years using the calendar pagination, the selected options for the multi-select are lost.

Looking at the url, the options for that filter look like "&foo[]=1".

However, the links in the pagination corrupt that to look like "&1=1".

Comments

jeremylichtman created an issue. See original summary.

jeremylichtman’s picture

jeremylichtman’s picture

The following work-around is based on the one posted in (https://www.drupal.org/node/2744299#comment-11271393), but has been modified to deal with "array" type parameters in a way that doesn't break the pagination links.

/**
 * Implements hook_preprocess_HOOK for the calendar_pager template.
 *
 * This is a work-around for a bug in the views calendar module, which
 * breaks url params in the form "select multiple".
 */
function module_preprocess_calendar_pager(&$variables) {
  // Check to see if a query string exists
  $current_uri = \Drupal::request()->getRequestUri();
  $uri_parts = explode('?', $current_uri);

  // If a query string exists, set it as an option on the pager links.
  if (isset($uri_parts[1])) {
    // Get the query into an array.
    $query = urldecode($uri_parts[1]);
    parse_str($query, $query_parts);

    // Clean up array params.
    foreach ($query_parts as $index => $query_part) {
      // If we are dealing with a "multiple" option.
      if (is_array($query_part)) {
        // Save it temporarily.
        $temp_key = $index;
        $temp_part = $query_part;

        // Remove it from the index of query items.
        unset($query_parts[$index]);

        // Create separate keyed items in our param array for each
        // of the "multiple" options.
        $key_parts = explode('[', $temp_key);
        foreach ($temp_part as $temp_index => $temp_item) {
          $new_key = $key_parts[0] . '[' . $temp_index . ']';
          $query_parts[$new_key] = $temp_item;
        }
      }
    }

    $query_keys = array_keys($query_parts);
    $query_values = array_values($query_parts);

    // Put the cleaned-up params back into the pagination urls.
    foreach ($variables['items'] as $key => $item) {
      if (is_array($item) && !empty($item['url'])) {
        $variables['items'][$key]['url']->setOption('query', $query_parts);
      }
    }
  }
}
akalata’s picture

@jeremylitchman thanks for providing this workaround -- solves the issue for me!

I added a @see https://www.drupal.org/node/2901061 to the docblock so I can remember to check back here and remove the code when the issue is actually fixed -- you may want to edit your code for others who copy/paste it. :)

huijse’s picture

Thanks! This code fixed my issue as well with a copy paste.

Neslee Canil Pinto’s picture

Status: Active » Closed (outdated)