You are here

function _fontawesome_modify_library in Font Awesome Icons 8.2

Modifies library inclusions to use CDN files when necessary.

Parameters

array $libraries: The libraries inclusion array.

string $librarySuffix: The suffix of the library being modified.

string $type: The type of library we are modifying.

string $cdnLocation: The location of the CDN file being used.

1 call to _fontawesome_modify_library()
fontawesome_library_info_alter in ./fontawesome.module
Implements hook_library_info_alter().

File

./fontawesome.module, line 102
Drupal integration with Font Awesome, the iconic font for use with Bootstrap.

Code

function _fontawesome_modify_library(array &$libraries, $librarySuffix, $type, $cdnLocation) {

  // Determine the name of the library.
  $libraryName = 'fontawesome.' . $type;
  if (!empty($librarySuffix)) {
    $libraryName .= '.' . $librarySuffix;
  }

  // Load the configuration settings.
  $configuration_settings = \Drupal::config('fontawesome.settings');

  // Handle SVG method.
  if ($type == 'svg') {
    $librarySettings = array_shift($libraries[$libraryName]['js']);
    $librarySettings['type'] = 'external';
    $librarySettings['attributes']['crossorigin'] = 'anonymous';

    // Add the integrity check if set.
    if (!empty($configuration_settings
      ->get('external_svg_integrity'))) {
      $librarySettings['attributes']['integrity'] = $configuration_settings
        ->get('external_svg_integrity');
    }
    $libraries[$libraryName]['js'] = [
      $cdnLocation => $librarySettings,
    ];
  }
  elseif ($type == 'webfonts') {
    $librarySettings = array_shift($libraries[$libraryName]['css']['theme']);
    $librarySettings['type'] = 'external';

    // TODO: add integrity and crossorigin to CSS.
    // See https://www.drupal.org/project/drupal/issues/2716115.
    $libraries[$libraryName]['css']['theme'] = [
      $cdnLocation => $librarySettings,
    ];
  }
}