You are here

function swagger_ui_formatter_requirements in Swagger UI Field Formatter 8.2

Same name and namespace in other branches
  1. 8.3 swagger_ui_formatter.install \swagger_ui_formatter_requirements()
  2. 7.2 swagger_ui_formatter.install \swagger_ui_formatter_requirements()

Implements hook_requirements().

Drush and Config Installer does not perform requirements check before enables a module.

See also

https://www.drupal.org/project/config_installer/issues/3061127

https://github.com/drush-ops/drush/issues/3669

File

./swagger_ui_formatter.install, line 17
Install, update and uninstall functions for Swagger UI Field Formatter.

Code

function swagger_ui_formatter_requirements($phase) {
  $requirements = [];

  // Make sure _swagger_ui_formatter_get_library_path() is defined.
  if ($phase === 'install') {
    module_load_include('module', 'swagger_ui_formatter');
  }
  if (in_array($phase, [
    'runtime',
    'install',
  ])) {
    if ($library_path = _swagger_ui_formatter_get_library_path()) {
      $requirements['swagger_ui_library'] = [
        'title' => t('Swagger UI'),
        'severity' => REQUIREMENT_OK,
        'value' => _swagger_ui_formatter_get_library_version(),
        'description' => t('Swagger UI library installed at %path.', [
          '%path' => DRUPAL_ROOT . $library_path,
        ]),
      ];
    }
    else {
      $requirements['swagger_ui_library'] = [
        'title' => t('Swagger UI'),
        'severity' => REQUIREMENT_ERROR,
        'description' => t('Swagger UI library was not found. Download <a href=":link" target="_blank">the appropriate version</a> and place it in the [DRUPAL ROOT]/libraries directory (e.g. [DRUPAL ROOT]/libraries/swagger-ui).', [
          ':link' => 'https://github.com/swagger-api/swagger-ui/releases',
        ]),
      ];
    }
  }
  return $requirements;
}