You are here

function _swagger_ui_formatter_get_library_version in Swagger UI Field Formatter 8.2

Gets Swagger UI library version information.

Return value

string The library version or an empty string if the version cannot be determined.

2 calls to _swagger_ui_formatter_get_library_version()
swagger_ui_formatter_library_info_build in ./swagger_ui_formatter.module
Implements hook_library_info_build().
swagger_ui_formatter_requirements in ./swagger_ui_formatter.install
Implements hook_requirements().

File

./swagger_ui_formatter.module, line 125
Main module file for Swagger UI Field Formatter.

Code

function _swagger_ui_formatter_get_library_version() {
  if ($library_path = _swagger_ui_formatter_get_library_path()) {
    $file = DRUPAL_ROOT . $library_path . '/package.json';
    if (!file_exists($file)) {
      return '';
    }
    $content = file_get_contents($file);
    if (!$content) {
      return '';
    }
    $data = Json::decode($content);
    if (isset($data['version'])) {
      return $data['version'];
    }
  }
  return '';
}