You are here

function theme_linkicon_item in Link Icon 7

Formats an individual linkicon item.

2 theme calls to theme_linkicon_item()
linkicon_field_formatter_view in ./linkicon.module
Implements hook_field_formatter_view().
_linkicon_field_formatter_settings_form in includes/linkicon.admin.inc
Implements hook_field_formatter_settings_form().

File

./linkicon.theme.inc, line 59
Hooks and preprocess functions for the Linkicon module.

Code

function theme_linkicon_item($variables) {
  extract($variables);
  $element = $variables['element'];
  foreach ([
    'attributes',
    'icon_name',
    'settings',
    'title',
  ] as $key) {
    $default = $key == 'attributes' || $key == 'settings' ? [] : '';
    $variables[$key] = isset($element["#{$key}"]) ? $element["#{$key}"] : $default;
  }
  $build = $icon = '';
  $settings = $variables['settings'];
  $attributes =& $variables['attributes'];
  $prefix = check_plain(trim($settings['prefix']));
  $icon_class = drupal_clean_css_identifier(drupal_strtolower($prefix . '-' . trim($variables['icon_name'])));
  $title = '<span class="linkicon__text">' . $element['#title'] . '</span>';
  $attributes['class'][] = 'linkicon__icon';

  // Adds consistent styling for Fontawesome >= 4, and non-fontello icons.
  if (isset($settings['prefix']) && $settings['prefix'] != 'icon') {
    $attributes['class'][] = 'icon';
  }

  // Order is important for FontAwesome, else broken, fab far fas come first.
  if (!empty($settings['icon_class'])) {
    $attributes['class'][] = trim($settings['icon_class']);
  }
  $attributes['class'][] = $prefix . ' ' . $icon_class;
  $attributes['class']['aria-hidden'] = 'true';
  if (!empty($settings['bundle'])) {

    // As of this writing, icon API has no consistent way to prefixing icon
    // as appears on fontello, icomoon, fontawesome modules.
    $icons[] = array(
      '#theme' => 'icon',
      '#bundle' => $settings['bundle'],
      '#icon' => $variables['icon_name'],
      '#attributes' => $attributes,
    );
    $icon = drupal_render($icons);
    $title = !empty($icon) ? $title : '<span class="linkicon__noicon">' . $element['#title'] . '</span>';
  }
  else {
    $icon = '<span ' . drupal_attributes($attributes) . '></span>';
  }
  $build = in_array($settings['position'], array(
    'right',
    'bottom',
  )) ? $title . $icon : $icon . $title;
  return $build;
}