function template_preprocess_micon_icon in Micon 2.x
Same name and namespace in other branches
- 8 micon.theme.inc \template_preprocess_micon_icon()
Prepares variables for the Micon icon template.
Default template: micon-icon-font.html.twig.
Parameters
array $variables: An associative array containing:
- elements: An associative array containing the icon
- attributes: HTML attributes for the containing element.
File
- ./
micon.theme.inc, line 47 - Contains micon.theme.inc.
Code
function template_preprocess_micon_icon(array &$variables) {
$icon = $variables['icon'];
$variables['tag'] = 'span';
$variables['attributes']['class'][] = 'micon';
// Allow icon_id to be used as #icon.
if (is_string($icon)) {
$icon = \Drupal::service('micon.icon.manager')
->getIconMatch($icon);
}
if ($icon instanceof MiconIconInterface) {
$variables['icon'] = $icon;
$variables['type'] = $icon
->getType();
$variables['tag'] = $icon
->getWrappingElement();
$variables['attributes']['class'][] = $icon
->getSelector();
$variables['attributes']['aria-hidden'] = 'true';
$variables['children'] = $icon
->getChildren();
}
}