You are here

function responsive_menu_requirements in Responsive and off-canvas menu 4.0.x

Same name and namespace in other branches
  1. 8.3 responsive_menu.install \responsive_menu_requirements()
  2. 8.2 responsive_menu.install \responsive_menu_requirements()
  3. 4.4.x responsive_menu.install \responsive_menu_requirements()
  4. 4.1.x responsive_menu.install \responsive_menu_requirements()
  5. 4.3.x responsive_menu.install \responsive_menu_requirements()

Implements hook_requirements().

File

./responsive_menu.install, line 85
Contains install and update functions.

Code

function responsive_menu_requirements($phase) {
  $requirements = [];
  if ($phase !== 'runtime') {
    return $requirements;
  }

  // Check whether the libraries are installed.
  $libraries = [
    'mmenu' => [
      'title' => 'mmenu library',
      'version' => '8.4.0',
      'path' => '/libraries/mmenu',
      'version_path' => '/libraries/mmenu/package.json',
      'severity' => REQUIREMENT_ERROR,
      'download_url' => 'https://github.com/FrDH/mmenu-js/releases/latest',
      'homepage_url' => 'http://mmenu.frebsite.nl',
    ],
    'superfish' => [
      'title' => 'superfish library',
      'version' => '1.7.0',
      'path' => '/libraries/superfish',
      'version_path' => '/libraries/superfish/package.json',
      'severity' => REQUIREMENT_WARNING,
      'download_url' => 'https://api.github.com/repos/joeldbirch/superfish/zipball',
      'homepage_url' => 'https://superfish.joelbirch.co',
    ],
    'hammerjs' => [
      'title' => 'hammerjs library',
      'version' => '2.0.7',
      'path' => '/libraries/hammerjs',
      'version_path' => '/libraries/hammerjs/hammer.min.js',
      'severity' => REQUIREMENT_WARNING,
      'download_url' => 'https://api.github.com/repos/hammerjs/hammer.js/zipball',
      'homepage_url' => 'http://hammerjs.github.io',
    ],
  ];
  foreach ($libraries as $key => $library) {
    if (isset($library['version'])) {
      $version = responsive_menu_get_library_version($library['version_path']);
    }
    else {
      $version = $library['title'];
    }
    $t_args = [
      '@title' => $library['title'],
      '@version' => $version,
      '@required' => isset($library['version']) ? $library['version'] : '',
      '@path' => $library['path'],
      ':download_href' => $library['download_url'],
      ':homepage_href' => $library['homepage_url'],
    ];

    // Does this library exist?
    $library_exists = file_exists(DRUPAL_ROOT . $library['path']);

    // Does the library meet the version requirements?
    if (isset($library['version'])) {
      $library_installed = $library_exists && responsive_menu_check_library_version($version, $library['version']);
    }
    else {
      $library_installed = $library_exists;
    }

    // The requirements array for rendering.
    $requirements['responsive_menu' . $key] = [
      'title' => 'Responsive menu: ' . $library['title'],
      'value' => $library_installed ? t('@version (Installed)', $t_args) : t('@version (Not installed)', $t_args),
      'severity' => $library_installed ? REQUIREMENT_OK : $library['severity'],
    ];
    if (!$library_installed) {
      if ($library_exists && $version > 0) {
        $requirements['responsive_menu' . $key]['value'] = t('Version @version is installed but @required is required', $t_args);
      }
      else {
        $requirements['responsive_menu' . $key]['value'] = t('Library not installed');
      }
      $requirements['responsive_menu' . $key]['description'] = t('The @title must be installed at @path and must be version @required or greater. The download url is :download_href', $t_args);
    }
  }
  return $requirements;
}