/* * Converts a string to a suitable html ID attribute. * * http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a * valid ID attribute in HTML. This function: * * - Ensure an ID starts with an alpha character by optionally adding an 'n'. * - Replaces any character except A-Z, numbers, and underscores with dashes. * - Converts entire string to lowercase. * * @param $string * The string * @return * The converted string */ function idealform01_id_safe($string) { // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores. $string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string)); // If the first character is not a-z, add 'n' in front. if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware. $string = 'id'. $string; } return $string; } function idealform01_preprocess_user_profile_item(&$vars) { //dpm($vars); if(!empty($vars['element']['#attributes']['class'])) { $vars['element']['#attributes']['class'] .= ' '; } $vars['element']['#attributes']['class'] .= 'user-profile-item'; $vars['attributes'] = drupal_attributes($vars['element']['#attributes']); } function idealform01_preprocess_user_profile_category(&$vars) { //dpm($vars); if(!empty($vars['element']['#attributes']['class'])) { $vars['element']['#attributes']['class'] .= ' '; } $vars['element']['#attributes']['class'] .= 'user-profile-category user-profile-category-' . idealform01_id_safe($vars['title']); $vars['attributes'] = drupal_attributes($vars['element']['#attributes']); }