You are here

function icon_preprocess_icon_image in Icon API 8

Same name and namespace in other branches
  1. 7 includes/render.inc \icon_preprocess_icon_image()

Implements hook_preprocess_icon_RENDER_HOOK().

File

includes/render.inc, line 29
render.inc Provides hooks and theme callbacks for default render hooks. @TODO add a "sprite" render hook.

Code

function icon_preprocess_icon_image(&$variables) {
  $bundle =& $variables['bundle'];
  $icon =& $variables['icon'];
  if (!isset($bundle['settings']['extension'])) {
    $bundle['settings']['extension'] = 'png';
  }

  // Sanitize and add icon class here.
  $class = \Drupal\Component\Utility\Html::getClass($icon);

  // Check to see if image starts with a alpha-numeric character. If it doesn't,
  // prepend it so it can be a proper CSS class.
  if (is_numeric($class[0])) {
    $class = 'image-' . $class;
  }
  $variables['attributes']['class'][] = $class;
}