1

I have a calendar view for events. The events are categorized by taxonomy terms. I use the minicalendar for the selection of days and filter the result list with an exposed list of the categories.

This is all working fine.

But user interface lacks a bit of coherence. There's no indication of which day is picked on the minicalendar (which only has a class for "today").

This snippet helped me getting an "active" class for the datebox, so users can see, which date they have chosen:

<?php
function YOURTHEME_preprocess_calendar_datebox(&$vars) {
  $url = $vars['url']; // The (absolute) URL of the item.
  $current = url(request_path(), array('absolute' => TRUE)); // The absolute URL of the page being viewed.
  if ($url == $current) {
    $classes = explode(' ', $vars['class']); // Extract the current classes as a list.
    $classes[] = 'active'; // Add 'active' to the class list.
    $vars['class'] = implode(' ', $classes); // Concatenate and attach the updated class list.
  }
}
?>

But here's the problem: when i select a taxonomy term, the url changes from:

/myview/2014-11-27

to

/myview?field_category_tid_selective=8 (e.g)

and my active class is gone. How can i achieve that the class stays, even when a filter is active on the results?

Any help appreciated! Thx

1
+150

Try next, that work without using urls, using second argument:

function YOURTHEME_preprocess_calendar_datebox(&$vars) {
  $arg = arg();

  // If no second argument provided - that's mean today. 
  // Please check how argument date supplied for next day: 2014-12-01 or 2014-12-1 and change date() to appropriate.
  $url_date = empty($arg[1]) ? date('Y-m-d') : $arg[1]; 

  if ($vars['date'] == $url_date) {
    $classes = explode(' ', $vars['class']); // Extract the current classes as a list.
    $classes[] = 'active'; // Add 'active' to the class list.
    $vars['class'] = implode(' ', $classes); // Concatenate and attach the updated class list.
  }
}
  • Thanks, that's almost working! But the active class is assigned to "today" when a filter is selected, instead of the day the user has selected. So right now if i choose the 27th of Nov and select a filter, the active class is assigned to 25th of Nov (today). The argument format is correct, it's Y-m-d... – Volker Nov 25 '14 at 8:31
  • I think the problem is, when the filter is applied the url has no date argument no more, but somehow stores which date is selected. If i select a filter and change to another day, the active class is assigned correct, until i change the filter again. Then the active class is gone again... – Volker Nov 25 '14 at 8:36
  • I assume then you select filter, it's loss current selected date. Is it? – Nikit Nov 25 '14 at 23:38
  • Yes, correct... – Volker Nov 26 '14 at 8:31
  • I mean, if you selecting filter and in url no date, it shouldn't show to you some date, only today. Is it? – Nikit Nov 26 '14 at 23:44
0

You can add extra parameters to a path if you use Page Manager (part of ctools) and Panels.

  1. Go to structure -> pages in the admin menu (admin/structure/pages) and click +add custom page
  2. Set the [Path] to something like myview/%selected-date
  3. Set the [Variant type] to Panel, don't worry about the [Optional features]
  4. Choose a one column layout (for starters at least)
  5. In the content area click the cog and choose add content

content area and cog

  1. Find your view and place it as content

Voila!

Now you can use your current method to set the url to myview/2014-11-27 and when they choose a filter it will look like myview/2014-11-27?field_category_tid_selective=8.

Hope this helps =)

  • Darvanen, sorry i couldn't review your answer because i had no time but I'll definitely look into it. Thanks for your answer... – Volker Dec 4 '14 at 15:54
  • It's all good mate, it is simply an alternative. – Darvanen Dec 4 '14 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.