You are here

function theme_countryicons_icon in Country Icons 7

Same name and namespace in other branches
  1. 6.2 countryicons.theme.inc \theme_countryicons_icon()
  2. 6 countryicons.module \theme_countryicons_icon()
  3. 7.2 countryicons.theme.inc \theme_countryicons_icon()

Theme a country icon.

Parameters

$variables: An associative array containing:

  • code: A two letter ISO3166 country code.
  • iconset: The icon set to use ('shiny' is the default).
  • alt: The alternative text for text-based browsers (the two letter ISO3166 country code is the default).
  • title: The title text is displayed when the image is hovered in some popular browsers.
  • attributes: Associative array of attributes to be placed in the img tag.

Return value

A string containing the image tag.

File

./countryicons.module, line 152
A collection of country icons, and an API for retrieving them.

Code

function theme_countryicons_icon($variables) {
  $code_lower = drupal_strtolower($variables['code']);
  $image = array();
  $iconset = empty($variables['iconset']) ? 'shiny' : $variables['iconset'];
  $iconsetinfo = countryicons_get_iconset($iconset);
  if (!file_exists($image['path'] = str_replace('*', $code_lower, $iconsetinfo['path']))) {
    $image['path'] = str_replace('*', 'unknown', $iconsetinfo['path']);
  }
  if (isset($iconsetinfo['dimensions'])) {
    list($image['width'], $image['height']) = explode('x', $iconsetinfo['dimensions']);
  }
  $image['alt'] = empty($variables['alt']) ? $variables['code'] : $variables['alt'];
  $image['title'] = $variables['title'];
  $image['attributes'] = $variables['attributes'] ? $variables['attributes'] : array();
  $image['attributes']['class'] = 'countryicon countryicon-iconset-' . $iconset . ' countryicon-code-' . $code_lower . (empty($image['attributes']['class']) ? '' : ' ' . $image['attributes']['class']);
  return theme('image', $image);
}