function fontawesome_extract_icons in Font Awesome Icons 8
Same name and namespace in other branches
- 7.3 fontawesome.module \fontawesome_extract_icons()
- 7.2 fontawesome.module \fontawesome_extract_icons()
Extracts all icons from the CSS file.
Return value
array Array containing icons.
2 calls to fontawesome_extract_icons()
- EditorIconDialog::buildForm in src/
Form/ EditorIconDialog.php - fontawesome_icon_bundles in ./
fontawesome.module - Implements hook_icon_bundles().
File
- ./
fontawesome.module, line 159 - Drupal integration with Font Awesome, the iconic font for use with Bootstrap.
Code
function fontawesome_extract_icons() {
// If CDN is enabled, get CSS content from the CDN URL.
if (\Drupal::config('fontawesome.settings')
->get('fontawesome_use_cdn')) {
$fontawesome_library = \Drupal::service('library.discovery')
->getLibraryByName('fontawesome', 'fontawesome.cdn');
$url = $fontawesome_library['css'][0]['data'];
// The URL needs to have a schema to work with drupal_http_request.
if (strpos($url, '//') === 0) {
$url = 'http:' . $url;
}
$response = \Drupal::httpClient()
->get($url, [
'headers' => [
'Accept' => 'text/plain',
],
]);
$content = (string) $response
->getBody();
}
else {
$fontawesome_library = \Drupal::service('library.discovery')
->getLibraryByName('fontawesome', 'fontawesome');
$filepath = DRUPAL_ROOT . '/' . $fontawesome_library['css'][0]['data'];
$content = file_exists($filepath) ? file_get_contents($filepath) : '';
}
// Parse the CSS content.
if (preg_match_all('@\\.fa-([a-zA-Z0-9\\-]*?):before[\\s]?{[\\s]*content:[\\s]?"\\\\f[a-f0-9]+"@m', $content, $matches)) {
$icons = $matches[1];
asort($icons);
return array_combine($icons, $icons);
}
return [];
}