You are here

function calendar_date_default_argument_alter in Calendar 8

Same name and namespace in other branches
  1. 7.3 calendar.module \calendar_date_default_argument_alter()

Implements hook_date_default_argument_alter().

Adjust the default date for a view based on the stored session value. This is used for current date tracking.

@todo Is this still necessary?

File

./calendar.module, line 38

Code

function calendar_date_default_argument_alter(&$argument, &$value) {
  $user = \Drupal::currentUser();
  $style_options = $argument->view->display_handler
    ->get_option('style_options');
  $tracking = \Drupal::config('calendar.settings')
    ->get('calendar_track_date');
  if (!empty($tracking) && ($tracking == 2 || !empty($user->uid))) {

    // If this is a default date, i.e. we are visiting a new calendar display,
    // set the default date for the display. See if we already have a session
    // date to use. If so, use it. Otherwise the default is the current date.
    if (!empty($_SESSION[$argument->view->name]['default_date'])) {
      $default_date = $_SESSION[$argument->view->name]['default_date'];
    }
    else {
      $default_date = date_now();
      $_SESSION[$argument->view->name]['default_date'] = $default_date;
    }

    // Get the current date from the session.
    $value = $default_date
      ->format($argument->arg_format);
  }
}