Pro přidání aktuální uživatelské role a cesty (verze A) do pole $body_classes stačí do souboru template.php v používaném tématu vzhledu vložit níže uvedený snippet a změňte MYTHEMENAME na aktuální název tématu vzhledu:
Verze A
/** * Add current user's role and path to $body_classes shown in <body> */ function MYTHEMENAME_preprocess_html(&$vars) { //$body_classes = array($vars['classes_array']); // normal theme $body_classes = array($vars['attributes_array']['class']); // omega theme if ($vars['user']) { foreach($vars['user']->roles as $key => $role) { $role_class = 'role-' . str_replace(' ', '-', $role); //$vars['classes_array'][] = $role_class; // normal theme $vars['attributes_array']['class'][] = $role_class; // omega theme } } $path = drupal_get_path_alias($_GET['q']); $aliases = explode('/', $path); foreach($aliases as $alias) { //$vars['classes_array'][] = drupal_clean_css_identifier($alias); // normal theme $vars['attributes_array']['class'][] = drupal_clean_css_identifier($alias); // omega theme } }
Verze B
/** * Add current user's role to $body_classes shown in <body> */ function MYTHEMENAME_preprocess_page(&$vars) { if ($vars['user']) { foreach($vars['user']->roles as $key => $role){ $vars['class'][] = 'role-' . drupal_html_class($role); } } }
/** * Add current user's role to $body_classes shown in <body> */ function MYTHEMENAME_preprocess_page(&$vars, $hook) { $body_classes = array($vars['body_classes']); if ($vars['user']) { foreach($vars['user']->roles as $key => $role){ $role_class = 'role-' . str_replace(' ', '-', $role); $body_classes[] = $role_class; } } $vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces }