Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2.  
  3. /******************************************************************
  4.  * A Drupal module for integrating custom icons with the Icons API
  5.  * @src: custom_icons.module
  6.  *****************************************************************/
  7.  
  8. /**
  9.  * Implements hook_icon_providers()
  10.  * - This function let's the Icon module know abour our custom provider
  11.  */
  12. function icons_icon_providers() {
  13.   $providers['custom_icons'] = array(
  14.     'title' => t('Custom icons'),
  15.     'default bundle' => array(
  16.       'settings' => array(),
  17.     ),
  18.   );
  19.   return $providers;
  20. }
  21.  
  22. /**
  23.  * Implements hook_icon_bundle_configure()
  24.  * - Creates our Drupal Icon API provider as well as sets the HTML tag type for each icon's render function
  25.  */
  26. function icons_icon_bundle_configure(&$settings, &$form_state, &$complete_form) {
  27.   $bundle = $form_state['bundle'];
  28.   if ($bundle['provider'] === custom_icons) {
  29.     $settings['tag'] = array(
  30.       '#type' => 'select',
  31.       '#title' => t('HTML Markup'),
  32.       '#description' => t('Choose the HTML markup tag', array(
  33.         '%tag' => '<' . $bundle['settings']['tag'] . '>',
  34.       )),
  35.       '#options' => drupal_map_assoc(array('i', 'span', 'div')),
  36.       '#default_value' => $bundle['settings']['tag'],
  37.     );
  38.   }
  39. }
  40.  
  41. /**
  42.  * Implements hook_preprocess_icon_RENDER_HOOK()
  43.  * - Icon specific settings such as what prefixes each class name
  44.  */
  45. function icons_preprocess_icon_sprite(&$variables) {
  46.   $bundle = &$variables['bundle'];
  47.   if ($bundle['provider'] === 'icons') {
  48.     // Remove the default "icon" class.
  49.     $key = array_search('icon', $variables['attributes']['class']);
  50.     if ($key !== FALSE) {
  51.       unset($variables['attributes']['class'][$key]);
  52.     }
  53.     foreach($variables['attributes']['class'] as $idx => $value) {
  54.       if ($value == $variables['icon']) {
  55.         $variables['attributes']['class'][$idx] = 'icon-' . $value;
  56.       }
  57.     }
  58.   }
  59. }
  60.  
  61. /**
  62.  * Implements hook_icon_bundles()
  63.  * - This function sets all of our custom icon class names
  64.  * - Keep in mind, a prefix was set above and will be needed to use these
  65.  */
  66. function icons_icon_bundles() {
  67.   $bundles['icons'] = array(
  68.     'title' => 'Custom icons',
  69.     'render' => 'sprite',
  70.     'settings' => array(
  71.       'tag' => 'i',
  72.     ),
  73.     'icons' => array(
  74.       'accredited' => 'accredited',
  75.       'apply-now' => 'apply-now',
  76.       'board-docs' => 'board-docs',
  77.       'business-plus' => 'business-plus',
  78.       'calendars' => 'calendars',
  79.       'careers' => 'careers',
  80.       'district-a-z' => 'district-a-z',
  81.       'enroll' => 'enroll',
  82.       'financial-transparency' => 'financial-transparency',
  83.       'for-staff' => 'for-staff',
  84.       'safe-2-tell' => 'safe-2-tell',
  85.       'superintendent-msg' => 'superintendent-msg',
  86.       'upcoming-events' => 'upcoming-events',
  87.       'weather-alert' => 'weather-alert',
  88.     ),
  89.   );
  90.   return $bundles;
  91. }
  92.  
  93. /**
  94.  * Generate markup needed to display our icons
  95.  * - Example usage: <?php icons_render($node->field_icon);?>
  96.  */
  97. function icons_render($field_icon) {
  98.   $element[] = array(
  99.     '#theme' => 'icon',
  100.     '#bundle' => $field_icon['bundle'],
  101.     '#icon' => $field_icon['icon'],
  102.   );
  103.   print drupal_render($element);
  104. }