function fontawesome_page_attachments in Font Awesome Icons 8
Same name and namespace in other branches
- 8.2 fontawesome.module \fontawesome_page_attachments()
Implements hook_page_attachments().
Purposefully only load on page requests and not hook_init(). This is required so it does not increase the bootstrap time of Drupal when it isn't necessary.
File
- ./
fontawesome.module, line 67 - Drupal integration with Font Awesome, the iconic font for use with Bootstrap.
Code
function fontawesome_page_attachments(array &$page) {
if (\Drupal::config('fontawesome.settings')
->get('fontawesome_use_cdn')) {
$page['#attached']['library'][] = 'fontawesome/fontawesome.cdn';
}
else {
$fontawesome_library = \Drupal::service('library.discovery')
->getLibraryByName('fontawesome', 'fontawesome');
if (!file_exists(DRUPAL_ROOT . '/' . $fontawesome_library['css'][0]['data'])) {
drupal_set_message(t('The Font Awesome library could not be found. Please verify Font Awesome was downloaded and extracted at %directory. Please check the Font Awesome module README file for more details.', [
'%directory' => 'libraries/fontawesome',
]), 'warning');
}
$page['#attached']['library'][] = 'fontawesome/fontawesome';
}
}