summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-01-13 05:40:03 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-01-13 05:40:03 +0000
commit02d2f6e04a29acb1c3fcedcd5068878cffb10fbf (patch)
tree48d65b410f2dc34eaf8d69a822a09ec83e9d85df /modules
parent5d2cdb6ba95549da448e0a127e40fcc375e3886c (diff)
downloadbrdo-02d2f6e04a29acb1c3fcedcd5068878cffb10fbf.tar.gz
brdo-02d2f6e04a29acb1c3fcedcd5068878cffb10fbf.tar.bz2
#678714 by effulgentsia: Unify use of theme hook / template suggestions, fix clobbering problems, and improve suggestion discovery performance.
Diffstat (limited to 'modules')
-rw-r--r--modules/block/block.module6
-rw-r--r--modules/comment/comment.module4
-rw-r--r--modules/field/field.module8
-rw-r--r--modules/forum/forum.module14
-rw-r--r--modules/node/node.module4
-rw-r--r--modules/poll/poll.module25
-rw-r--r--modules/profile/profile.module3
-rw-r--r--modules/search/search.pages.inc6
-rw-r--r--modules/simpletest/tests/theme.test31
9 files changed, 50 insertions, 51 deletions
diff --git a/modules/block/block.module b/modules/block/block.module
index 9a898628b..282eaafe7 100644
--- a/modules/block/block.module
+++ b/modules/block/block.module
@@ -871,9 +871,9 @@ function template_preprocess_block(&$variables) {
$variables['classes_array'][] = drupal_html_class('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;
+ $variables['theme_hook_suggestions'][] = 'block__' . $variables['block']->region;
+ $variables['theme_hook_suggestions'][] = 'block__' . $variables['block']->module;
+ $variables['theme_hook_suggestions'][] = 'block__' . $variables['block']->module . '__' . $variables['block']->delta;
}
/**
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index 3bbc3d991..678c92bf2 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -2126,7 +2126,7 @@ function template_preprocess_comment(&$variables) {
// Preprocess fields.
field_attach_preprocess('comment', $comment, $variables['elements'], $variables);
- $variables['template_files'][] = 'comment-' . $variables['node']->type;
+ $variables['theme_hook_suggestions'][] = 'comment__' . $variables['node']->type;
// Helpful $content variable for templates.
foreach (element_children($variables['elements']) as $key) {
@@ -2217,7 +2217,7 @@ function template_preprocess_comment_wrapper(&$variables) {
// Provide contextual information.
$variables['node'] = $variables['content']['#node'];
$variables['display_mode'] = variable_get('comment_default_mode_' . $variables['node']->type, COMMENT_MODE_THREADED);
- $variables['template_files'][] = 'comment-wrapper-' . $variables['node']->type;
+ $variables['theme_hook_suggestions'][] = 'comment_wrapper__' . $variables['node']->type;
}
/**
diff --git a/modules/field/field.module b/modules/field/field.module
index 4f3518007..5c209e300 100644
--- a/modules/field/field.module
+++ b/modules/field/field.module
@@ -777,11 +777,11 @@ function template_preprocess_field(&$variables) {
'field-type-' . $field_type_css,
'field-label-' . $element['#label_display'],
),
- 'template_files' => array(
+ 'theme_hook_suggestions' => array(
'field',
- 'field-' . $element['#field_name'],
- 'field-' . $element['#bundle'],
- 'field-' . $element['#field_name'] . '-' . $element['#bundle'],
+ 'field__' . $element['#field_name'],
+ 'field__' . $element['#bundle'],
+ 'field__' . $element['#field_name'] . '__' . $element['#bundle'],
),
);
$variables = array_merge($variables, $additions);
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index 8e9eba04c..53668052e 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -948,17 +948,17 @@ function template_preprocess_forums(&$variables) {
// Provide separate template suggestions based on what's being output. Topic id is also accounted for.
// Check both variables to be safe then the inverse. Forums with topic ID's take precedence.
if ($variables['forums'] && !$variables['topics']) {
- $variables['template_files'][] = 'forums-containers';
- $variables['template_files'][] = 'forums-' . $variables['tid'];
- $variables['template_files'][] = 'forums-containers-' . $variables['tid'];
+ $variables['theme_hook_suggestions'][] = 'forums__containers';
+ $variables['theme_hook_suggestions'][] = 'forums__' . $variables['tid'];
+ $variables['theme_hook_suggestions'][] = 'forums__containers__' . $variables['tid'];
}
elseif (!$variables['forums'] && $variables['topics']) {
- $variables['template_files'][] = 'forums-topics';
- $variables['template_files'][] = 'forums-' . $variables['tid'];
- $variables['template_files'][] = 'forums-topics-' . $variables['tid'];
+ $variables['theme_hook_suggestions'][] = 'forums__topics';
+ $variables['theme_hook_suggestions'][] = 'forums__' . $variables['tid'];
+ $variables['theme_hook_suggestions'][] = 'forums__topics__' . $variables['tid'];
}
else {
- $variables['template_files'][] = 'forums-' . $variables['tid'];
+ $variables['theme_hook_suggestions'][] = 'forums__' . $variables['tid'];
}
}
diff --git a/modules/node/node.module b/modules/node/node.module
index 32b107abe..1ba7b8513 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -1382,8 +1382,8 @@ function template_preprocess_node(&$variables) {
}
// Clean up name so there are no underscores.
- $variables['template_files'][] = 'node-' . str_replace('_', '-', $node->type);
- $variables['template_files'][] = 'node-' . $node->nid;
+ $variables['theme_hook_suggestions'][] = 'node__' . $node->type;
+ $variables['theme_hook_suggestions'][] = 'node__' . $node->nid;
}
/**
diff --git a/modules/poll/poll.module b/modules/poll/poll.module
index c2d759048..841510c59 100644
--- a/modules/poll/poll.module
+++ b/modules/poll/poll.module
@@ -38,7 +38,7 @@ function poll_init() {
* Implements hook_theme().
*/
function poll_theme() {
- return array(
+ $theme_hooks = array(
'poll_vote' => array(
'template' => 'poll-vote',
'render element' => 'form',
@@ -55,6 +55,21 @@ function poll_theme() {
'variables' => array('title' => NULL, 'votes' => NULL, 'total_votes' => NULL, 'vote' => NULL, 'block' => NULL),
),
);
+ // The theme system automatically discovers the theme's functions and
+ // templates that implement more targeted "suggestions" of generic theme
+ // hooks. But suggestions implemented by a module must be explicitly
+ // registered.
+ $theme_hooks += array(
+ 'poll_results__block' => array(
+ 'template' => 'poll-results--block',
+ 'variables' => $theme_hooks['poll_results']['variables'],
+ ),
+ 'poll_bar__block' => array(
+ 'template' => 'poll-bar--block',
+ 'variables' => $theme_hooks['poll_bar']['variables'],
+ ),
+ );
+ return $theme_hooks;
}
/**
@@ -733,9 +748,8 @@ function template_preprocess_poll_vote(&$variables) {
$variables['vote'] = drupal_render($form['vote']);
$variables['rest'] = drupal_render_children($form);
$variables['block'] = $form['#block'];
- // If this is a block, allow a different tpl.php to be used.
if ($variables['block']) {
- $variables['template_files'][] = 'poll-vote-block';
+ $variables['theme_hook_suggestions'][] = 'poll_vote__block';
}
}
@@ -833,9 +847,8 @@ function template_preprocess_poll_results(&$variables) {
}
$variables['title'] = check_plain($variables['raw_title']);
- // If this is a block, allow a different tpl.php to be used.
if ($variables['block']) {
- $variables['template_files'][] = 'poll-results-block';
+ $variables['theme_hook_suggestions'][] = 'poll_results__block';
}
}
@@ -850,7 +863,7 @@ function template_preprocess_poll_results(&$variables) {
*/
function template_preprocess_poll_bar(&$variables) {
if ($variables['block']) {
- $variables['template_files'][] = 'poll-bar-block';
+ $variables['theme_hook_suggestions'][] = 'poll_bar__block';
}
$variables['title'] = check_plain($variables['title']);
$variables['percentage'] = round($variables['votes'] * 100 / max($variables['total_votes'], 1));
diff --git a/modules/profile/profile.module b/modules/profile/profile.module
index 0261f1549..244c8804d 100644
--- a/modules/profile/profile.module
+++ b/modules/profile/profile.module
@@ -585,8 +585,7 @@ function template_preprocess_profile_wrapper(&$variables) {
$variables['current_field'] = '';
if ($field = arg(1)) {
$variables['current_field'] = $field;
- // Supply an alternate template suggestion based on the browsable field.
- $variables['template_files'][] = 'profile-wrapper-' . $field;
+ $variables['theme_hook_suggestions'][] = 'profile_wrapper__' . $field;
}
}
diff --git a/modules/search/search.pages.inc b/modules/search/search.pages.inc
index 575b62ede..7c1c95048 100644
--- a/modules/search/search.pages.inc
+++ b/modules/search/search.pages.inc
@@ -77,8 +77,7 @@ function template_preprocess_search_results(&$variables) {
$variables['search_results'] .= theme('search_result', array('result' => $result, 'type' => $variables['type']));
}
$variables['pager'] = theme('pager', array('tags' => NULL));
- // Provide alternate search results template.
- $variables['template_files'][] = 'search-results-' . $variables['type'];
+ $variables['theme_hook_suggestions'][] = 'search_results__' . $variables['type'];
}
/**
@@ -113,8 +112,7 @@ function template_preprocess_search_result(&$variables) {
// Provide separated and grouped meta information..
$variables['info_split'] = $info;
$variables['info'] = implode(' - ', $info);
- // Provide alternate search result template.
- $variables['template_files'][] = 'search-result-' . $variables['type'];
+ $variables['theme_hook_suggestions'][] = 'search_result__' . $variables['type'];
}
/**
diff --git a/modules/simpletest/tests/theme.test b/modules/simpletest/tests/theme.test
index ff6250546..0be8cb05a 100644
--- a/modules/simpletest/tests/theme.test
+++ b/modules/simpletest/tests/theme.test
@@ -19,36 +19,25 @@ class TemplateUnitTest extends DrupalWebTestCase {
}
/**
- * Test function template_page_suggestions() for SA-CORE-2009-003.
+ * Test function theme_get_suggestions() for SA-CORE-2009-003.
*/
- function testTemplateSuggestions() {
+ function testThemeSuggestions() {
// Set the front page as something random otherwise the CLI
// test runner fails.
variable_set('site_frontpage', 'nobody-home');
$args = array('node', '1', 'edit');
- $suggestions = template_page_suggestions($args, 'page');
- $this->assertEqual($suggestions, array('page-node', 'page-node-%', 'page-node-1', 'page-node-edit'), t('Found expected node edit page template suggestions'));
+ $suggestions = theme_get_suggestions($args, 'page');
+ $this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1', 'page__node__edit'), t('Found expected node edit page suggestions'));
// Check attack vectors.
$args = array('node', '\\1');
- $suggestions = template_page_suggestions($args, 'page');
- $this->assertEqual($suggestions, array('page-node', 'page-node-%', 'page-node-1'), t('Removed invalid \\ from template suggestions'));
+ $suggestions = theme_get_suggestions($args, 'page');
+ $this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), t('Removed invalid \\ from suggestions'));
$args = array('node', '1/');
- $suggestions = template_page_suggestions($args, 'page');
- $this->assertEqual($suggestions, array('page-node', 'page-node-%', 'page-node-1'), t('Removed invalid / from template suggestions'));
+ $suggestions = theme_get_suggestions($args, 'page');
+ $this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), t('Removed invalid / from suggestions'));
$args = array('node', "1\0");
- $suggestions = template_page_suggestions($args, 'page');
- $this->assertEqual($suggestions, array('page-node', 'page-node-%', 'page-node-1'), t('Removed invalid \\0 from template suggestions'));
- // Tests for drupal_discover_template()
- $suggestions = array('page');
- $this->assertEqual(drupal_discover_template(array('themes/garland'), $suggestions), 'themes/garland/page.tpl.php', t('Safe template discovered'));
- $suggestions = array('page');
- $this->assertEqual(drupal_discover_template(array('themes/garland'), $suggestions, '\\.tpl.php'), 'themes/garland/page.tpl.php', t('Unsafe extension fixed'));
- $suggestions = array('page\\');
- $this->assertEqual(drupal_discover_template(array('themes/garland'), $suggestions), 'themes/garland/page.tpl.php', t('Unsafe template suggestion fixed'));
- $suggestions = array('page/');
- $this->assertEqual(drupal_discover_template(array('themes/garland'), $suggestions), 'themes/garland/page.tpl.php', t('Unsafe template suggestion fixed'));
- $suggestions = array("page\0");
- $this->assertEqual(drupal_discover_template(array('themes/garland'), $suggestions), 'themes/garland/page.tpl.php', t('Unsafe template suggestion fixed'));
+ $suggestions = theme_get_suggestions($args, 'page');
+ $this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), t('Removed invalid \\0 from suggestions'));
}
}