You are here

public static function CalendarHelper::getCalendarArguments in Calendar 8.2

Helper function to find the calendar date argument handlers for a view.

Parameters

\Drupal\views\ViewExecutable $view: The view.

Return value

array|false Returns the argument handler if one is found, or FALSE otherwise.

5 calls to CalendarHelper::getCalendarArguments()
CalendarHelper::day in src/CalendarHelper.php
Returns an array for day.
CalendarHelper::getCalendarDisplays in src/CalendarHelper.php
Get views that (may) act as Calendar Display. Used to select views with other granularity to link to.
CalendarHelper::month in src/CalendarHelper.php
Returns an array for month.
CalendarHelper::week in src/CalendarHelper.php
Returns an array for week.
CalendarPager::render in src/Plugin/views/pager/CalendarPager.php
Return the renderable array of the pager.

File

src/CalendarHelper.php, line 232

Class

CalendarHelper
Class CalendarHelper.

Namespace

Drupal\calendar

Code

public static function getCalendarArguments(ViewExecutable $view) {
  $calendar_arguments = [];
  foreach ($view->argument as $argument) {
    if (substr($argument
      ->getPluginId(), 0, 9) === 'calendar_') {
      $date = new DrupalDateTime($argument->argument);
      if ($date
        ->hasErrors()) {
        $now = new DrupalDateTime();
        switch ($argument
          ->getPluginId()) {
          case 'calendar_year_month':
            $argument->argument = $now
              ->format('Ym');
            break;
          case 'calendar_year_week':
            $argument->argument = $now
              ->format('YW');
            break;
          case 'calendar_day':
            $argument->argument = $now
              ->format('Ymd');
            break;
        }
      }
      $calendar_arguments[] = [
        'field' => str_replace('_value', '', $argument->realField),
        'argument' => $argument->argument,
        //          'plugin' => $argument->getPlugin(),
        'id' => $argument
          ->getPluginId(),
      ];
    }
  }
  if ($calendar_arguments) {
    return $calendar_arguments;
  }
  else {
    return FALSE;
  }
}