1 icon.inc icon_get_style($icon_name)

Helper function to get an icon style based on the last segment of the icon name. We have some pre-approved suffixes that correspond to style options.

Parameters

string $icon_name: The icon name to get the style for.

Return value

array: An array keyed with:

  • 'style': A string containing the style of the icon, or empty for default.
  • 'is_brand': A boolean indicating whether this is a brand icon.

File

core/includes/icon.inc, line 488
Provides the Backdrop API for placing icons.

Code

function icon_get_style($icon_name) {
  $icon_data = array(
    'style' => '',
    'is_brand' => FALSE,
  );

  static $icon_allowed_styles;
  if (!isset($icon_allowed_styles)) {
    $icon_allowed_styles = icon_allowed_styles();
  }

  // Split icon name by '-' and get the last segment.
  $icon_name = explode('-', $icon_name);
  $icon_style = array_pop($icon_name);
  $brand_check = array_pop($icon_name);

  if (in_array($icon_style, array_keys($icon_allowed_styles))) {
    $icon_data['style'] = $icon_style;
  }
  else {
    // Default to outline if no approved style is provided.
    $icon_data['style'] = 'outline';
  }
  if ($icon_style == 'logo' || $brand_check == 'logo') {
    $icon_data['is_brand'] = TRUE;
  }

  return $icon_data;
}