<?php
/******************************************************************
* A Drupal module for integrating custom icons with the Icons API
* @src: custom_icons.module
*****************************************************************/
/**
* Implements hook_icon_providers()
* - This function let's the Icon module know abour our custom provider
*/
function icons_icon_providers() {
$providers['custom_icons'] = array(
'title' => t('Custom icons'),
'default bundle' => array(
'settings' => array(),
),
);
return $providers;
}
/**
* Implements hook_icon_bundle_configure()
* - Creates our Drupal Icon API provider as well as sets the HTML tag type for each icon's render function
*/
function icons_icon_bundle_configure(&$settings, &$form_state, &$complete_form) {
$bundle = $form_state['bundle'];
if ($bundle['provider'] === custom_icons) {
$settings['tag'] = array(
'#type' => 'select',
'#title' => t('HTML Markup'),
'#description' => t('Choose the HTML markup tag', array(
'%tag' => '<' . $bundle['settings']['tag'] . '>',
)),
'#options' => drupal_map_assoc(array('i', 'span', 'div')),
'#default_value' => $bundle['settings']['tag'],
);
}
}
/**
* Implements hook_preprocess_icon_RENDER_HOOK()
* - Icon specific settings such as what prefixes each class name
*/
function icons_preprocess_icon_sprite(&$variables) {
$bundle = &$variables['bundle'];
if ($bundle['provider'] === 'icons') {
// Remove the default "icon" class.
$key = array_search('icon', $variables['attributes']['class']);
if ($key !== FALSE) {
unset($variables['attributes']['class'][$key]);
}
foreach($variables['attributes']['class'] as $idx => $value) {
if ($value == $variables['icon']) {
$variables['attributes']['class'][$idx] = 'icon-' . $value;
}
}
}
}
/**
* Implements hook_icon_bundles()
* - This function sets all of our custom icon class names
* - Keep in mind, a prefix was set above and will be needed to use these
*/
function icons_icon_bundles() {
$bundles['icons'] = array(
'title' => 'Custom icons',
'render' => 'sprite',
'settings' => array(
'tag' => 'i',
),
'icons' => array(
'accredited' => 'accredited',
'apply-now' => 'apply-now',
'board-docs' => 'board-docs',
'business-plus' => 'business-plus',
'calendars' => 'calendars',
'careers' => 'careers',
'district-a-z' => 'district-a-z',
'enroll' => 'enroll',
'financial-transparency' => 'financial-transparency',
'for-staff' => 'for-staff',
'safe-2-tell' => 'safe-2-tell',
'superintendent-msg' => 'superintendent-msg',
'upcoming-events' => 'upcoming-events',
'weather-alert' => 'weather-alert',
),
);
return $bundles;
}
/**
* Generate markup needed to display our icons
* - Example usage: <?php icons_render($node->field_icon);?>
*/
function icons_render($field_icon) {
$element[] = array(
'#theme' => 'icon',
'#bundle' => $field_icon['bundle'],
'#icon' => $field_icon['icon'],
);
print drupal_render($element);
}