zen-8.x-7.0-alpha15/template.php
template.php
<?php
/**
* Override or insert variables into the comment templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("comment" in this case.)
*/
function zen_preprocess_comment(&$variables, $hook) {
// Add $unpublished variable.
$variables['unpublished'] = ($variables['status'] == 'comment-unpublished') ? TRUE : FALSE;
// Add $preview variable.
$variables['preview'] = ($variables['status'] == 'comment-preview') ? TRUE : FALSE;
// If comment subjects are disabled, don't display them.
if (variable_get('comment_subject_field_' . $variables['node']->type, 1) == 0) {
$variables['title'] = '';
}
// If the comment is unpublished/preview, add a "unpublished" watermark class.
if ($variables['unpublished'] || $variables['preview']) {
$variables['classes_array'][] = 'watermark__wrapper';
}
// Add the comment__permalink class.
$uri = entity_uri('comment', $variables['comment']);
$uri_options = $uri['options'] + array('attributes' => array('class' => array('comment__permalink'), 'rel' => 'bookmark'));
$variables['permalink'] = l(t('Permalink'), $uri['path'], $uri_options);
// Remove core's permalink class and add the comment__title class.
$variables['title_attributes_array']['class'][] = 'comment__title';
$uri_options = $uri['options'] + array('attributes' => array('rel' => 'bookmark'));
$variables['title'] = l($variables['comment']->subject, $uri['path'], $uri_options);
}
/**
* Implements hook_form_BASE_FORM_ID_alter().
*
* Prevent user-facing field styling from screwing up node edit forms by
* renaming the classes on the node edit form's field wrappers.
*/
function zen_form_node_form_alter(&$form, &$form_state, $form_id) {
// Remove if #1245218 is backported to D7 core.
foreach (array_keys($form) as $item) {
if (strpos($item, 'field_') === 0) {
if (!empty($form[$item]['#attributes']['class'])) {
foreach ($form[$item]['#attributes']['class'] as &$class) {
// Core bug: the field-type-text-with-summary class is used as a JS hook.
if ($class != 'field-type-text-with-summary' && strpos($class, 'field-type-') === 0 || strpos($class, 'field-name-') === 0) {
// Make the class different from that used in theme_field().
$class = 'form-' . $class;
}
}
}
}
}
}
/**
* Implements hook_preprocess_menu_link().
*/
function zen_preprocess_menu_link(&$variables, $hook) {
// Normalize menu item classes to be an array.
if (empty($variables['element']['#attributes']['class'])) {
$variables['element']['#attributes']['class'] = array();
}
$menu_item_classes =& $variables['element']['#attributes']['class'];
if (!is_array($menu_item_classes)) {
$menu_item_classes = array($menu_item_classes);
}
// Normalize menu link classes to be an array.
if (empty($variables['element']['#localized_options']['attributes']['class'])) {
$variables['element']['#localized_options']['attributes']['class'] = array();
}
$menu_link_classes =& $variables['element']['#localized_options']['attributes']['class'];
if (!is_array($menu_link_classes)) {
$menu_link_classes = array($menu_link_classes);
}
// Add BEM-style classes to the menu item classes.
$extra_classes = array('menu__item');
foreach ($menu_item_classes as $key => $class) {
switch ($class) {
// Menu module classes.
case 'expanded':
case 'collapsed':
case 'leaf':
case 'active':
// Menu block module classes.
case 'active-trail':
$extra_classes[] = 'is-' . $class;
break;
case 'has-children':
$extra_classes[] = 'is-parent';
break;
}
}
$menu_item_classes = array_merge($extra_classes, $menu_item_classes);
// Add BEM-style classes to the menu link classes.
$extra_classes = array('menu__link');
if (empty($menu_link_classes)) {
$menu_link_classes = array();
}
else {
foreach ($menu_link_classes as $key => $class) {
switch ($class) {
case 'active':
case 'active-trail':
$extra_classes[] = 'is-' . $class;
break;
}
}
}
$menu_link_classes = array_merge($extra_classes, $menu_link_classes);
}
