Setting first day of the week or hook_variable_get_alter* — Drupal 7

We use a lot of calendar based views on the site, for our clients, walkers and for administration. We needed to change the first-day-of-the-week to Sunday for our clients. The site-wide default was set to Monday (in ‘Regional Settings). We didn’t want to switch all calendars, especially since switching to Sunday means we couldn’t use ISO-8601 week numbers.

So how do we set the first-day-of-the-week only for client calendars and date pop-up widgets? Fortunately Drupal is open source and a glance at the implementation of variable_get provides the solution; variables are loaded to a global $conf array, and variable_get fetches the relevant variable from that global array. This allows us to change the variable on client-facing pages only, and maintain the default for others.

The code above shows the implementation. To make sure you can use of ajax-based date pointers in calendars its best to modify the first day of the week using hook_views_pre_build. Modify date pop-up wizards by calling the first-day-of-the-week setting function from the form definition function or through hook_form_alter as appropriate.

Its not hook_variable_get_alter, but its pretty close…

Like what you read? Give bluetegu a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.