You are here

public function YamlFormLibrariesManager::requirements in YAML Form 8

Get third party libraries status for hook_requirements and drush.

Return value

array An associative array of third party libraries keyed by library name.

Overrides YamlFormLibrariesManagerInterface::requirements

File

src/YamlFormLibrariesManager.php, line 33

Class

YamlFormLibrariesManager
Form libraries manager.

Namespace

Drupal\yamlform

Code

public function requirements() {
  $cdn = \Drupal::config('yamlform.settings')
    ->get('library.cdn', FALSE);
  $status = [];
  $libraries = $this
    ->getLibraries();
  foreach ($libraries as $library_name => $library) {
    $library_path = '/' . $library['destination'] . '/' . $library['directory_name'];
    $library_exists = file_exists(DRUPAL_ROOT . $library_path) ? TRUE : FALSE;
    $t_args = [
      '@title' => $library['title'],
      '@version' => $library['version'],
      '@path' => $library_path,
      ':download_href' => $library['download']['url'],
      ':library_href' => $library['url']
        ->toString(),
      ':install_href' => 'http://cgit.drupalcode.org/yamlform/tree/INSTALL.md?h=8.x-1.x',
      ':external_href' => 'https://www.drupal.org/docs/8/theming-drupal-8/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-theme#external',
      ':settings_href' => Url::fromRoute('yamlform.settings', [], [
        'fragment' => 'edit-library',
      ])
        ->toString(),
    ];
    if ($library_exists) {
      $value = $this
        ->t('@version (Installed)', $t_args);
      $description = $this
        ->t('The <a href=":library_href">@title</a> library is installed in <b>@path</b>.', $t_args);
      $severity = REQUIREMENT_OK;
    }
    elseif ($cdn) {
      $value = $this
        ->t('@version (CDN).', $t_args);
      $description = $this
        ->t('The <a href=":library_href">@title</a> library is <a href=":external_href">externally hosted libraries</a> and loaded via a Content Delivery Network (CDN).', $t_args);
      $severity = REQUIREMENT_OK;
    }
    else {
      $value = $this
        ->t('@version (CDN).', $t_args);
      $description = $this
        ->t('Please download the <a href=":library_href">@title</a> library from <a href=":download_href">:download_href</a> and copy it to <b>@path</b> or use <a href=":install_href">Drush</a> to install this library. (<a href=":settings_href">Disable CDN warning)', $t_args);
      $severity = REQUIREMENT_WARNING;
    }
    $status['yamlform_library_' . $library_name] = [
      'library' => $library,
      'title' => $this
        ->t('YAML Form library: @title', $t_args),
      'value' => $value,
      'description' => $description,
      'severity' => $severity,
    ];
  }
  return $status;
}