You are here

moment.install in Moment.js 7.2

Same filename and directory in other branches
  1. 8.2 moment.install

Install, update and uninstall functions for the Moment.js module.

File

moment.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the Moment.js module.
 */

/**
 * Implements hook_requirements().
 */
function moment_requirements($phase) {
  $return = [];
  $t = get_t();
  if ($phase === 'runtime') {
    $libVersions = moment_lib_version_ranges();
    foreach ($libVersions as $libName => $libVersionConstraints) {
      $return["moment_library__{$libName}"] = moment_requirement_entry_lib($t('Moment.js'), $libName, $libVersionConstraints);
    }
  }
  return $return;
}

/**
 * @param string $hostName
 * @param string $libName
 * @param array $versionConstraints
 */
function moment_requirement_entry_lib($hostName, $libName, array $versionConstraints) {
  $t = get_t();
  $lib = libraries_detect($libName);
  $version = !empty($lib['version']) ? $lib['version'] : '';
  $isValidVersion = $version && moment_is_valid_version($version, $versionConstraints);
  $libNameHuman = !empty($lib['name']) ? $lib['name'] : $libName;
  return [
    'title' => $t('@host - @label library version', [
      '@host' => $hostName,
      '@label' => $libNameHuman,
    ]),
    'value' => $version ? $version : $t('Not available'),
    'severity' => $isValidVersion ? REQUIREMENT_OK : REQUIREMENT_ERROR,
  ];
}