You are here

function fontawesome_requirements in Font Awesome Icons 8

Same name and namespace in other branches
  1. 8.2 fontawesome.install \fontawesome_requirements()
  2. 7.3 fontawesome.install \fontawesome_requirements()
  3. 7 fontawesome.install \fontawesome_requirements()
  4. 7.2 fontawesome.install \fontawesome_requirements()

Implements hook_requirements().

File

./fontawesome.install, line 11
Requirements page for Font Awesome.

Code

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

  // Report the version of Font Awesome.
  if ($phase == 'runtime') {
    $requirements['fontawesome'] = [
      'title' => t('Fontawesome'),
    ];

    // Don't really check for Font Awesome if we are using the CDN version.
    if (\Drupal::config('fontawesome.settings')
      ->get('fontawesome_use_cdn')) {
      $fontawesome_library = \Drupal::service('library.discovery')
        ->getLibraryByName('fontawesome', 'fontawesome.cdn');
      $requirements['fontawesome']['severity'] = REQUIREMENT_OK;
      $requirements['fontawesome']['value'] = t('Using CDN version: %version', [
        '%version' => $fontawesome_library['css'][0]['data'],
      ]);
    }
    else {

      // Verify the library is installed.
      $fontawesome_library = \Drupal::service('library.discovery')
        ->getLibraryByName('fontawesome', 'fontawesome');
      if (file_exists(DRUPAL_ROOT . '/' . $fontawesome_library['css'][0]['data'])) {
        $requirements['fontawesome']['severity'] = REQUIREMENT_OK;
        $requirements['fontawesome']['value'] = t('Font Awesome library is installed.');
      }
      else {
        $requirements['fontawesome']['severity'] = REQUIREMENT_WARNING;
        $requirements['fontawesome']['value'] = t('Font Awesome library is not installed. View the README for more information on installing Font Awesome.');
      }
    }
  }
  return $requirements;
}