You are here

function calendar_systems_element_info_alter in Calendar Systems 8.3

Same name and namespace in other branches
  1. 8 calendar_systems.module \calendar_systems_element_info_alter()
  2. 7 calendar_systems.module \calendar_systems_element_info_alter()
  3. 7.2 calendar_systems.module \calendar_systems_element_info_alter()

Implements hook_element_info_alter().

Swap drupal elements with calendar_systems elements.

Parameters

array $info:

File

./calendar_systems.module, line 147

Code

function calendar_systems_element_info_alter(array &$info) {
  $rep = function ($find_for) {
    switch ($find_for) {
      case Datelist::class:
        $rep = CalendarSystemsDateList::class;
        break;
      case \Drupal\Core\Datetime\Element\Datetime::class:
        $rep = CalendarSystemsDateTime::class;
        break;
      case Date::class:
        $rep = CalendarSystemsDate::class;
        break;
      default:
        $rep = NULL;
    }
    return $rep;
  };
  foreach ([
    'date',
    'datelist',
    'datetime',
  ] as $el_) {
    if (!isset($info[$el_])) {
      continue;
    }
    $el =& $info[$el_];
    if ($el_ === 'date' || $el_ === 'datetime') {
      $el['#attached']['library'][] = 'calendar_systems/picker';
    }
    foreach ([
      '#process',
      '#pre_render',
      '#element_validate',
      '#value_callback',
    ] as $attr_) {
      if (!isset($el[$attr_])) {
        continue;
      }
      foreach ($el[$attr_] as $ai => &$a) {
        if (is_array($a)) {
          $a[0] = $rep($a[0]) ?: $a[0];
        }
        else {
          $el[$attr_][$ai] = $rep($a) ?: $a;
        }
      }
    }
  }
}