Commit 2df43894 authored by webchick's avatar webchick

#306358 by dvessel, JohnAlbin, and flobruit: Add a single $classes string (and...

#306358 by dvessel, JohnAlbin, and flobruit: Add a single $classes string (and corresponding $classes_array) for all dynamic classes in template files.
parent cb756bcf
This diff is collapsed.
......@@ -114,8 +114,11 @@ function theme_install_page($content) {
$variables['content'] = $content;
// Delay setting the message variable so it can be processed below.
$variables['show_messages'] = FALSE;
// The maintenance preprocess function is recycled here.
// Variable processors invoked manually since this function and theme_update_page()
// are exceptions in how it works within the theme system.
template_preprocess($variables, 'install_page');
template_preprocess_maintenance_page($variables);
template_process($variables, 'install_page');
// Special handling of error messages
$messages = drupal_set_message();
......@@ -167,8 +170,11 @@ function theme_update_page($content, $show_messages = TRUE) {
// Assign content and show message flag.
$variables['content'] = $content;
$variables['show_messages'] = $show_messages;
// The maintenance preprocess function is recycled here.
// Variable processors invoked manually since this function and theme_install_page()
// are exceptions in how it works within the theme system.
template_preprocess($variables, 'update_page');
template_preprocess_maintenance_page($variables);
template_process($variables, 'update_page');
// Special handling of warning messages.
$messages = drupal_set_message();
......@@ -270,21 +276,19 @@ function template_preprocess_maintenance_page(&$variables) {
$variables['closure'] = '';
// Compile a list of classes that are going to be applied to the body element.
$body_classes = array();
$body_classes[] = 'in-maintenance';
$variables['classes_array'][] = 'in-maintenance';
if (isset($variables['db_is_active']) && !$variables['db_is_active']) {
$body_classes[] = 'db-offline';
$variables['classes_array'][] = 'db-offline';
}
if ($variables['layout'] == 'both') {
$body_classes[] = 'two-sidebars';
$variables['classes_array'][] = 'two-sidebars';
}
elseif ($variables['layout'] == 'none') {
$body_classes[] = 'no-sidebars';
$variables['classes_array'][] = 'no-sidebars';
}
else {
$body_classes[] = 'one-sidebar sidebar-' . $variables['layout'];
$variables['classes_array'][] = 'one-sidebar sidebar-' . $variables['layout'];
}
$variables['body_classes'] = implode(' ', $body_classes);
// Dead databases will show error messages so supplying this template will
// allow themers to override the page and the content completely.
......
......@@ -787,7 +787,9 @@ function template_preprocess_block(&$variables) {
$variables['block']->content = drupal_render($variables['block']->content);
}
$variables['classes_array'][] = 'block-' . $variables['block']->module;
$variables['template_files'][] = 'block-' . $variables['block']->region;
$variables['template_files'][] = 'block-' . $variables['block']->module;
$variables['template_files'][] = 'block-' . $variables['block']->module . '-' . $variables['block']->delta;
}
\ No newline at end of file
}
......@@ -11,8 +11,17 @@
* - $block->module: Module that generated the block.
* - $block->delta: An ID for the block, unique within each module.
* - $block->region: The block region embedding the current block.
* - $classes: String of classes that can be used to style contextually through
* CSS. It can be manipulated through the variable $classes_array from
* preprocess functions. The default values can be one or more of the following:
* - block: The current template type, i.e., "theming hook".
* - block-[module]: The module generating the block. For example, the user module
* is responsible for handling the default user navigation block. In that case
* the class would be "block-user".
*
* Helper variables:
* - $classes_array: Array of html class attribute values. It is flattened
* into a string within the variable $classes.
* - $block_zebra: Outputs 'odd' and 'even' dependent on each block region.
* - $zebra: Same output as $block_zebra but independent of any block region.
* - $block_id: Counter dependent on each block region.
......@@ -23,9 +32,10 @@
*
* @see template_preprocess()
* @see template_preprocess_block()
* @see template_process()
*/
?>
<div id="block-<?php print $block->module . '-' . $block->delta; ?>" class="block block-<?php print $block->module ?>">
<div id="block-<?php print $block->module . '-' . $block->delta; ?>" class="<?php print $classes; ?>">
<?php if ($block->subject): ?>
<h2><?php print $block->subject ?></h2>
<?php endif;?>
......
......@@ -11,11 +11,29 @@
* - $author: Comment author. Can be link or plain text.
* - $date: Date and time of posting.
* - $comment: Full comment object.
* - $classes: String of classes that can be used to style contextually through
* CSS. It can be manipulated through the variable $classes_array from
* preprocess functions. The default values can be one or more of the following:
* - comment-folded: The current template type, i.e., "theming hook".
* - comment-by-anonymous: Comment by an unregistered user.
* - comment-by-node-author: Comment by the author of the parent node.
* The following applies only to viewers who are registered users:
* - comment-unpublished: An unpublished comment visible only to administrators.
* - comment-by-viewer: Comment by the user currently viewing the page.
* - comment-new: New comment since last the visit.
*
* These two variables are provided for context:
* - $comment: Full comment object.
* - $node: Node object the comments are attached to.
*
* Other variables:
* - $classes_array: Array of html class attribute values. It is flattened
* into a string within the variable $classes.
*
* @see template_preprocess_comment_folded()
* @see theme_comment_folded()
*/
?>
<div class="comment-folded">
<div class="<?php print $classes; ?>">
<span class="subject"><?php print $title . ' ' . $new; ?></span><span class="credit"><?php print t('by') . ' ' . $author; ?></span>
</div>
......@@ -8,6 +8,10 @@
* Available variables:
* - $content: All comments for a given page. Also contains comment form
* if enabled.
* - $classes: String of classes that can be used to style contextually through
* CSS. It can be manipulated through the variable $classes_array from
* preprocess functions. The default value has the following:
* - comment-wrapper: The current template type, i.e., "theming hook".
*
* The following variables are provided for contextual information.
* - $node: Node object the comments are attached to.
......@@ -18,14 +22,15 @@
* - COMMENT_MODE_FLAT_EXPANDED
* - COMMENT_MODE_THREADED_COLLAPSED
* - COMMENT_MODE_THREADED_EXPANDED
* - $display_order
* - COMMENT_ORDER_NEWEST_FIRST
* - COMMENT_ORDER_OLDEST_FIRST
*
* Other variables:
* - $classes_array: Array of html class attribute values. It is flattened
* into a string within the variable $classes.
*
* @see template_preprocess_comment_wrapper()
* @see theme_comment_wrapper()
*/
?>
<div id="comments">
<div id="comments" class="<?php print $classes; ?>">
<?php print $content; ?>
</div>
......@@ -128,7 +128,7 @@ function comment_theme() {
),
'comment_folded' => array(
'template' => 'comment-folded',
'arguments' => array('comment' => NULL),
'arguments' => array('comment' => NULL, 'node' => NULL),
),
'comment_flat_collapsed' => array(
'arguments' => array('comment' => NULL, 'node' => NULL),
......@@ -1833,7 +1833,7 @@ function theme_comment_view($comment, $node, $links = array(), $visible = TRUE)
$output .= theme('comment', $comment, $node, $links);
}
else {
$output .= theme('comment_folded', $comment);
$output .= theme('comment_folded', $comment, $node);
}
return $output;
......@@ -1865,6 +1865,25 @@ function template_preprocess_comment(&$variables) {
else {
$variables['status'] = ($comment->status == COMMENT_NOT_PUBLISHED) ? 'comment-unpublished' : 'comment-published';
}
// Gather comment classes.
if ($comment->uid === 0) {
$variables['classes_array'][] = 'comment-by-anonymous';
}
else {
// Published class is not needed. It is either 'comment-preview' or 'comment-unpublished'.
if ($variables['status'] != 'comment-published') {
$variables['classes_array'][] = $variables['status'];
}
if ($comment->uid === $variables['node']->uid) {
$variables['classes_array'][] = 'comment-by-node-author';
}
if ($comment->uid === $variables['user']->uid) {
$variables['classes_array'][] = 'comment-by-viewer';
}
if ($comment->new) {
$variables['classes_array'][] = 'comment-new';
}
}
}
/**
......@@ -1879,6 +1898,25 @@ function template_preprocess_comment_folded(&$variables) {
$variables['date'] = format_date($comment->timestamp);
$variables['new'] = $comment->new ? t('new') : '';
$variables['title'] = l($comment->subject, comment_node_url() . '/' . $comment->cid, array('fragment' => "comment-$comment->cid"));
// Gather comment classes.
if ($comment->uid === 0) {
$variables['classes_array'][] = 'comment-by-anonymous';
}
else {
if ($comment->status == COMMENT_NOT_PUBLISHED) {
$variables['classes_array'][] = 'comment-unpublished';
}
if ($comment->uid === $variables['node']->uid) {
$variables['classes_array'][] = 'comment-by-node-author';
}
if ($comment->uid === $variables['user']->uid) {
$variables['classes_array'][] = 'comment-by-viewer';
}
if ($comment->new) {
$variables['classes_array'][] = 'comment-new';
}
}
}
/**
......
......@@ -17,16 +17,33 @@
* comment-unpublished, comment-published or comment-preview.
* - $submitted: By line with date and time.
* - $title: Linked title.
* - $classes: String of classes that can be used to style contextually through
* CSS. It can be manipulated through the variable $classes_array from
* preprocess functions. The default values can be one or more of the following:
* - comment: The current template type, i.e., "theming hook".
* - comment-by-anonymous: Comment by an unregistered user.
* - comment-by-node-author: Comment by the author of the parent node.
* - comment-preview: When previewing a new or edited comment.
* The following applies only to viewers who are registered users:
* - comment-unpublished: An unpublished comment visible only to administrators.
* - comment-by-viewer: Comment by the user currently viewing the page.
* - comment-new: New comment since last the visit.
*
* These two variables are provided for context.
* These two variables are provided for context:
* - $comment: Full comment object.
* - $node: Node object the comments are attached to.
*
* Other variables:
* - $classes_array: Array of html class attribute values. It is flattened
* into a string within the variable $classes.
*
* @see template_preprocess()
* @see template_preprocess_comment()
* @see template_process()
* @see theme_comment()
*/
?>
<div class="comment<?php print ($comment->new) ? ' comment-new' : ''; print ' ' . $status ?> clearfix">
<div class="<?php print $classes; ?> clearfix">
<?php print $picture ?>
<?php if ($comment->new): ?>
......
......@@ -239,7 +239,7 @@ function number_elements() {
'number' => array(
'#input' => TRUE,
'#columns' => array('value'), '#delta' => 0,
'#process' => array('number_process'),
'#process' => array('number_elements_process'),
),
);
}
......@@ -296,7 +296,7 @@ function number_field_widget_error($element, $error) {
*
* The $field and $instance arrays are in $form['#fields'][$element['#field_name']].
*/
function number_process($element, $form_state, $form) {
function number_elements_process($element, $form_state, $form) {
$field_name = $element['#field_name'];
$field = field_info_field($element['#field_name']);
$instance = field_info_instance($element['#field_name'], $element['#bundle']);
......
......@@ -83,17 +83,17 @@ function options_elements() {
'options_select' => array(
'#input' => TRUE,
'#columns' => array('value'), '#delta' => 0,
'#process' => array('options_select_process'),
'#process' => array('options_select_elements_process'),
),
'options_buttons' => array(
'#input' => TRUE,
'#columns' => array('value'), '#delta' => 0,
'#process' => array('options_buttons_process'),
'#process' => array('options_buttons_elements_process'),
),
'options_onoff' => array(
'#input' => TRUE,
'#columns' => array('value'), '#delta' => 0,
'#process' => array('options_onoff_process'),
'#process' => array('options_onoff_elements_process'),
),
);
}
......@@ -125,7 +125,7 @@ function options_field_widget_error($element, $error) {
*
* The $field and $instance arrays are in $form['#fields'][$element['#field_name']].
*/
function options_buttons_process($element, &$form_state, $form) {
function options_buttons_elements_process($element, &$form_state, $form) {
$field = $form['#fields'][$element['#field_name']]['field'];
$instance = $form['#fields'][$element['#field_name']]['instance'];
$field_key = $element['#columns'][0];
......@@ -182,7 +182,7 @@ function options_buttons_process($element, &$form_state, $form) {
*
* The $field and $instance arrays are in $form['#fields'][$element['#field_name']].
*/
function options_select_process($element, &$form_state, $form) {
function options_select_elements_process($element, &$form_state, $form) {
$field = $form['#fields'][$element['#field_name']]['field'];
$instance = $form['#fields'][$element['#field_name']]['instance'];
$field_key = $element['#columns'][0];
......@@ -223,7 +223,7 @@ function options_select_process($element, &$form_state, $form) {
* Build the form element. When creating a form using FAPI #process,
* note that $element['#value'] is already set.
*/
function options_onoff_process($element, &$form_state, $form) {
function options_onoff_elements_process($element, &$form_state, $form) {
$field = $form['#fields'][$element['#field_name']]['field'];
$instance = $form['#fields'][$element['#field_name']]['instance'];
$field_key = $element['#columns'][0];
......
......@@ -238,13 +238,13 @@ function text_elements() {
'text_textfield' => array(
'#input' => TRUE,
'#columns' => array('value'), '#delta' => 0,
'#process' => array('text_textfield_process'),
'#process' => array('text_textfield_elements_process'),
'#autocomplete_path' => FALSE,
),
'text_textarea' => array(
'#input' => TRUE,
'#columns' => array('value', 'format'), '#delta' => 0,
'#process' => array('text_textarea_process'),
'#process' => array('text_textarea_elements_process'),
'#filter_value' => FILTER_FORMAT_DEFAULT,
),
);
......@@ -310,7 +310,7 @@ function text_field_widget_error($element, $error) {
* information needed to adjust the behavior of the 'element' should be
* extracted in hook_field_widget() above.
*/
function text_textfield_process($element, $form_state, $form) {
function text_textfield_elements_process($element, $form_state, $form) {
$field = $form['#fields'][$element['#field_name']]['field'];
$instance = $form['#fields'][$element['#field_name']]['instance'];
$field_key = $element['#columns'][0];
......@@ -353,7 +353,7 @@ function text_textfield_process($element, $form_state, $form) {
*
* The $field and $instance arrays are in $form['#fields'][$element['#field_name']].
*/
function text_textarea_process($element, $form_state, $form) {
function text_textarea_elements_process($element, $form_state, $form) {
$field = $form['#fields'][$element['#field_name']]['field'];
$instance = $form['#fields'][$element['#field_name']]['instance'];
$field_key = $element['#columns'][0];
......
......@@ -1387,6 +1387,25 @@ function template_preprocess_node(&$variables) {
$variables['submitted'] = '';
$variables['picture'] = '';
}
// Gather node classes.
$variables['classes_array'][] = 'node-' . $node->type;
if ($variables['promote']) {
$variables['classes_array'][] = 'node-promoted';
}
if ($variables['sticky']) {
$variables['classes_array'][] = 'node-sticky';
}
if (!$variables['status']) {
$variables['classes_array'][] = 'node-unpublished';
}
if ($variables['teaser']) {
$variables['classes_array'][] = 'node-teaser';
}
if (isset($variables['preview'])) {
$variables['classes_array'][] = 'node-preview';
}
// Clean up name so there are no underscores.
$variables['template_files'][] = 'node-' . str_replace('_', '-', $node->type);
$variables['template_files'][] = 'node-' . $node->nid;
......
......@@ -20,6 +20,19 @@
* - $terms: the themed list of taxonomy term links output from theme_links().
* - $submitted: themed submission information output from
* theme_node_submitted().
* - $classes: String of classes that can be used to style contextually through
* CSS. It can be manipulated through the variable $classes_array from
* preprocess functions. The default values can be one or more of the following:
* - node: The current template type, i.e., "theming hook".
* - node-[type]: The current node type. For example, if the node is a
* "Blog entry" it would result in "node-blog". Note that the machine
* name will often be in a short form of the human readable label.
* - node-teaser: Nodes in teaser form.
* - node-preview: Nodes in preview mode.
* The following are controlled through the node publishing options.
* - node-promoted: Nodes promoted to the front page.
* - node-sticky: Nodes ordered above other non-sticky nodes in teaser listings.
* - node-unpublished: Unpublished nodes visible only to administrators.
* TODO D7 : document $FIELD_NAME_rendered variables.
*
* Other variables:
......@@ -28,6 +41,8 @@
* - $comment_count: Number of comments attached to the node.
* - $uid: User ID of the node author.
* - $created: Time the node was published formatted in Unix timestamp.
* - $classes_array: Array of html class attribute values. It is flattened
* into a string within the variable $classes.
* - $zebra: Outputs either "even" or "odd". Useful for zebra striping in
* teaser listings.
* - $id: Position of the node. Increments each time it's output.
......@@ -47,9 +62,10 @@
*
* @see template_preprocess()
* @see template_preprocess_node()
* @see template_process()
*/
?>
<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?> clearfix">
<div id="node-<?php print $node->nid; ?>" class="<?php print $classes ?> clearfix">
<?php print $picture ?>
......
......@@ -23,7 +23,7 @@
<?php print $scripts; ?>
<script type="text/javascript"><?php /* Needed to avoid Flash of Unstyled Content in IE */ ?> </script>
</head>
<body class="<?php print $body_classes; ?>">
<body class="<?php print $classes; ?>">
<div id="page">
<div id="header">
<div id="logo-title">
......
......@@ -13,6 +13,8 @@
* - $css: An array of CSS files for the current page.
* - $directory: The directory the template is located in, e.g. modules/system
* or themes/garland.
* - $classes_array: Array of html class attribute values. It is flattened
* into a string within the variable $classes.
* - $is_front: TRUE if the current page is the front page. Used to toggle the mission statement.
* - $logged_in: TRUE if the user is registered and signed in.
* - $is_admin: TRUE if the user has permission to access administration pages.
......@@ -29,9 +31,26 @@
* - $styles: Style tags necessary to import all CSS files for the page.
* - $scripts: Script tags necessary to load the JavaScript files and settings
* for the page.
* - $body_classes: A set of CSS classes for the BODY tag. This contains flags
* indicating the current layout (multiple columns, single column), the current
* path, whether the user is logged in, and so on.
* - $classes: String of classes that can be used to style contextually through
* CSS. It should be placed within the <body> tag. When selecting through CSS
* it's recommended that you use the body tag, e.g., "body.front". It can be
* manipulated through the variable $classes_array from preprocess functions.
* The default values can be one or more of the following:
* - page: The current template type, i.e., "theming hook".
* - front: Page is the home page.
* - not-front: Page is not the home page.
* - logged-in: The current viewer is logged in.
* - not-logged-in: The current viewer is not logged in.
* - page-[level 1 path]: The internal first level path. For example, viewing
* example.com/user/2 would result in "page-user". Path aliases do not apply.
* - node-type-[node type]: When viewing a single node, the type of that node.
* For example, if the node is a "Blog entry" it would result in "node-type-blog".
* Note that the machine name will often be in a short form of the human readable label.
* The following only apply with the default 'left' and 'right' block regions:
* - two-sidebars: When both sidebars have content.
* - no-sidebars: When no sidebar content exists.
* - one-sidebar and sidebar-left or sidebar-right: A combination of the two classes
* when only one of the two sidebars have content.
*
* Site identity:
* - $front_page: The URL of the front page. Use this instead of $base_path,
......@@ -69,6 +88,7 @@
*
* @see template_preprocess()
* @see template_preprocess_page()
* @see template_process()
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
......@@ -82,7 +102,7 @@
<?php print $styles; ?>
<?php print $scripts; ?>
</head>
<body class="<?php print $body_classes; ?>">
<body class="<?php print $classes; ?>">
<div id="page-wrapper"><div id="page">
......
<?php
// $Id$
?>
<div id="block-<?php print $block->module . '-' . $block->delta; ?>" class="clearfix block block-<?php print $block->module ?>">
<div id="block-<?php print $block->module . '-' . $block->delta; ?>" class="<?php print $classes; ?> clearfix">
<?php if (!empty($block->subject)): ?>
<h2><?php print $block->subject ?></h2>
......
<?php
// $Id$
?>
<div class="comment<?php print ($comment->new) ? ' comment-new' : ''; print ' ' . $status; print ' ' . $zebra; ?>">
<div class="<?php print $classes . ' ' . $zebra; ?>">
<div class="clearfix">
<?php if ($submitted): ?>
......
......@@ -24,7 +24,7 @@
<?php print garland_get_ie_styles(); ?>
<![endif]-->
</head>
<body class="<?php print $body_classes ?>">
<body class="<?php print $classes ?>">
<!-- Layout -->
<div id="header-region" class="clearfix"><?php print $header; ?></div>
......
<?php
// $Id$
?>
<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">
<div id="node-<?php print $node->nid; ?>" class="<?php print $classes ?>">
<?php print $picture ?>
......
......@@ -13,7 +13,7 @@
<?php print $ie_styles ?>
<![endif]-->
</head>
<body class="<?php print $body_classes ?>">
<body class="<?php print $classes ?>">
<div id="header-region" class="clearfix"><?php print $header ?></div>
......
......@@ -690,14 +690,14 @@ ul.links li, ul.inline li {
float: right; /* LTR */
}
.preview .node, .preview .comment, .sticky {
.preview .node, .preview .comment, .node-sticky {
margin: 0;
padding: 0.5em 0;
border: 0;
background: 0;
}
.sticky {
.node-sticky {
padding: 1em;
background-color: #fff;
border: 1px solid #e0e5fb;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment