You are here

function template_preprocess_micon in Micon 8

Same name and namespace in other branches
  1. 2.x micon.theme.inc \template_preprocess_micon()

Prepares variables for icon and text display.

Default template: micon.html.twig.

Parameters

array $variables: An associative array containing:

  • element: An associative array containing the icon
  • attributes: HTML attributes for the containing element.

File

./micon.theme.inc, line 21
Contains micon.theme.inc.

Code

function template_preprocess_micon(array &$variables) {
  $icon = $variables['icon'];

  // 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['micon'] = $icon;
    $variables['icon'] = $variables['micon']
      ->setAttributes($variables['icon_attributes'])
      ->toRenderable();
  }
  else {

    // No icon found. We don't want to render anything.
    $variables['icon'] = '';
  }
}