You are here

function _calendar_systems_factory in Calendar Systems 8.3

20 calls to _calendar_systems_factory()
CalendarSystemsArgHandlerTrait::query in src/Plugin/views/argument/CalendarSystemsArgHandlerTrait.php
CalendarSystemsBlock::build in src/Plugin/Block/CalendarSystemsBlock.php
Builds and returns the renderable array for this block plugin.
CalendarSystemsDate::processDate in src/Element/CalendarSystemsDate.php
Processes a date form element.
CalendarSystemsDateList::calendarSystemsDatetimeRangeYears in src/Element/CalendarSystemsDateList.php
CalendarSystemsDateList::processDatelist in src/Element/CalendarSystemsDateList.php
Expands a date element into an array of individual elements.

... See full list

File

./calendar_systems.module, line 45

Code

function _calendar_systems_factory($tz = NULL, $lang_code = '', $calendar_name = '') {

  // COPY FROM common.inc::format_date() (drupal 7).
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['timezones'] = [];
  }
  $timezones =& $drupal_static_fast['timezones'];
  if (!$tz) {
    $tz = date_default_timezone_get();
  }
  if (is_string($tz)) {
    if (!isset($timezones[$tz])) {
      $timezones[$tz] = timezone_open($tz);
    }
    $tz = $timezones[$tz];
  }
  if (!$calendar_name) {
    $for_lang = Drupal::languageManager()
      ->getCurrentLanguage()
      ->getId();
    if (count(Drupal::languageManager()
      ->getLanguages()) === 1 || $for_lang === 'fa') {
      $calendar_name = 'persian';
    }
    elseif ($for_lang === 'en') {
      $calendar_name = 'gregorian';
    }
  }
  if (!$calendar_name) {
    return NULL;
  }
  if (!$lang_code) {
    if (count(Drupal::languageManager()
      ->getLanguages()) === 1) {
      $lang_code = 'fa';
    }
    else {
      $lang_code = Drupal::languageManager()
        ->getCurrentLanguage()
        ->getId();
    }
  }
  if (!CALENDAR_SYSTEMS_USE_INTL) {
    switch ($calendar_name) {
      case 'persian':
        return new CalendarSystemsPoorMansJaliliCalendar(is_string($tz) ? timezone_open($tz) : $tz, $lang_code);
      default:
        return new CalendarSystemsPoorMansGregorianCalendar(is_string($tz) ? timezone_open($tz) : $tz, $lang_code);
    }
  }
  switch ($calendar_name) {
    case 'persian':
      return new CalendarSystemsPersianIntlCalendar($tz, $calendar_name, $lang_code);
    default:
      return new CalendarSystemsIntlCalendar($tz, $calendar_name, $lang_code);
  }
}