Follow-up from #241570-68: Theme preprocess functions do not get retained when using patterns.

hook_theme() allows for specifying a 'file' key, so that a default theme function and preprocess functions can reside in a separate include file. For example, user_theme() does this for 'user_profile', allowing template_preprocess_user_profile() to reside in user.pages.inc.

We also allow for theme hook suggestions to be specified as a #theme value. For example, a module or theme can implement hook_user_view_alter(), and change $build['#theme'] from 'user_profile' to 'user_profile__' . $account->uid. Doing so would, for example, allow a theme to implement a user-profile--1.tpl.php in order to customize the display of the root user's profile.

In #241570: Theme preprocess functions do not get retained when using patterns, we made sure that the preprocess functions for the base hook (e.g., 'user_profile') are still called, even when the theme implements a specific suggestion override (e.g., user-profile--1.tpl.php).

However, there is currently a bug in theme() where the file in which those base preprocess functions are located isn't included, thereby, the preprocess functions fail to get called unless that file happened to be included elsewhere.

#4 contains a test that demonstrates this by changing the original test from #241570: Theme preprocess functions do not get retained when using patterns from testing 'breadcrumb' to testing a new test theme hook.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mradcliffe’s picture

This works for me in D7. I don't have a D8 install to test on.

mradcliffe’s picture

Oh, dangit. I didn't format patch on the right branch :(

Here's just a standard git diff patch for d7.

mradcliffe’s picture

Nope. I am an idiot sometimes. Sorry for spam.

effulgentsia’s picture

Thanks for the find and fix! Here's a test-only patch that demonstrates the bug, and a patch with that test plus the fix in #1 with a minor code comment tweak. Adding the backport tag so we remember to commit this to 7.x too, though the actual backport work might just be to remove 'core/' from the patch file.

effulgentsia’s picture

Title: Template preprocess function base hook includes not included in theme(). » Preprocess functions in an include file fail to get called when the theme implements a suggestion override
effulgentsia’s picture

Issue summary: View changes

Updated issue summary.

sun’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, looks good to me.

Lars Toomre’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/simpletest/tests/theme.testundefined
@@ -52,11 +52,19 @@ class ThemeUnitTest extends DrupalWebTestCase {
   /**
-  * Preprocess functions for the base hook should run even for suggestion implementations.
-  */
+   * Ensure preprocess functions for the base hook run even for suggestion implementations.

This documentation block needs work.

The first line of a docblock should start with an active verb tense and the whole line should be less than 80 characters. If necessary include more in an additional comment (after a blank line).

sun’s picture

Status: Needs work » Reviewed & tested by the community

As of now, that doesn't really apply to test methods in test cases. Before we apply the phpDoc summary there, I'd like to see the existing phpDoc summaries getting fixed.

xjm’s picture

Well, I wasn't assertive enough to NW a patch sun reviewed over a docs nit, but I did think the same thing and considered rerolling it before an incident distracted me yesterday. :) And having it over 80 characters is already inconsistent with all our docblocks everywhere.

Here is the existing issue to clean up the docblocks in this file:
#1431664: Clean up API docs for system/tests, J-Z, including subdirectories

The more correct we can make all patches currently going in, the less the cleanup patches will be reroll-inducing, baby-eating nightmares. So I'd disagree with postponing writing proper docs to cleanup issues.

xjm’s picture

Assigned: Unassigned » xjm

Oh, I'll just do it. :)

mradcliffe’s picture

Thank you for the tests, effulgentsia. Those look good to me as well.

Lars Toomre’s picture

Thank you @xjm.

The comment in #8 left my nose a bit out of joint. Since when do we ever knowingly allow docblock lines to exceed 80 characters?? I can recall many patch comments where @sun himself would note a docblock line exceeded 80 characters.

no_commit_credit’s picture

FileSize
1.13 KB
4.75 KB
xjm’s picture

#11 #13 just tweaks the docblocks a little. Trivial nitpicky comment change, so leaving the issue at RTBC. :) Thanks everyone!

xjm’s picture

Assigned: xjm » Unassigned
no_commit_credit’s picture

FileSize
992 bytes
4.75 KB
xjm’s picture

The above fixes a code style issue webchick spotted and also removes t() from the assertion message. References: http://drupal.org/simpletest-tutorial-drupal7#t and #500866: [META] remove t() from assert message.

catch’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

Thanks!

Committed/pushed to 8.x, moving back to 7.x for backport.

catch’s picture

Version: 8.x-dev » 7.x-dev
NROTC_Webmaster’s picture

Status: Patch (to be ported) » Needs review
FileSize
5.33 KB

Here is the port

xjm’s picture

Status: Needs review » Reviewed & tested by the community

Backport checks out.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

I initially got confused here about the fact that the theme.inc hunk references 'includes' but the test function adds 'file', however it looks like this is just the theme system being inconsistent with itself. xjm pointed out that http://qa.drupal.org/pifr/test/229313 shows the test failing without the patch.

Committed and pushed to 7.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

cweagans’s picture

Issue tags: +Needs backport to D7
cweagans’s picture

Issue summary: View changes

Updated issue summary.