function public static function Bootstrap::glyphicon
8.x-3.x Bootstrap.php | public static Bootstrap::glyphicon($name, array $default = []) |
Returns a specific Bootstrap Glyphicon.
Parameters
string $name: The icon name, minus the "glyphicon-" prefix.
array $default: (Optional) The default render array to use if $name is not available.
Return value
array The render containing the icon defined by $name, $default value if icon does not exist or returns NULL if no icon could be rendered.
Class
- Bootstrap
- The primary class for the Drupal Bootstrap base theme.
Namespace
Drupal\bootstrapSource src/Bootstrap.php (line 797)
public static function glyphicon($name, array $default = []) {
$icon = [];
// Ensure the icon specified is a valid Bootstrap Glyphicon.
// @todo Supply a specific version to _bootstrap_glyphicons() when Icon API
// supports versioning.
if (self::getTheme()->hasGlyphicons() && in_array($name, self::glyphicons())) {
// Attempt to use the Icon API module, if enabled and it generates output.
if (\Drupal::moduleHandler()->moduleExists('icon')) {
$icon = [
'#type' => 'icon',
'#bundle' => 'bootstrap',
'#icon' => 'glyphicon-' . $name,
];
}
else {
$icon = [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => '',
'#attributes' => [
'class' => ['icon', 'glyphicon', 'glyphicon-' . $name],
'aria-hidden' => 'true',
],
];
}
}
return $icon ? : $default;
}