Problem/Motivation

template_preprocess() signature was changed in #1972514: Impossible to set attributes for all entities. That issue missed changing a single line.

Proposed resolution

Apply patch at #30 to remedy this oversight. Add test to detect changes like this in the future (test only patch is in #9).

Remaining tasks

None

User interface changes

None

API changes

None

Original report by Cottser

theme() sometimes runs template_preprocess(), and the function signature for template_preprocess() was changed in #1972514: Impossible to set attributes for all entities.

One line patch coming which updates the call to template_preprocess() to avoid warnings like:

Warning: Missing argument 3 for template_preprocess(), called in /drupal/core/includes/theme.inc on line 1130 and defined in template_preprocess() (line 2474 of core/includes/theme.inc).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

star-szr’s picture

Status: Active » Needs review
FileSize
579 bytes

Status: Needs review » Needs work

The last submitted patch, 2030457-1.patch, failed testing.

star-szr’s picture

Status: Needs work » Needs review

#1: 2030457-1.patch queued for re-testing.

effulgentsia’s picture

Patch looks great. But this means we're missing test coverage for that if statement, since if we had it, HEAD would be failing tests now. Any chance of adding a test?

effulgentsia’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Changing issue attributes for #4, but if there's a reason why adding a test for this is problematic, please say so.

markhalliwell’s picture

Issue summary: View changes

Updated issue summary.

markhalliwell’s picture

Issue tags: +Twig

I ran into this as well. I'm sorry, but this really should just be RTBC. This was probably introduced with a lot of the Twig changes. These types of "typos" are honestly just bound to happen sometimes. The signature hasn't changed in like... forever, so I can see how you might propose this should require testing. However, seeing as this is the only place these are actually invoked... seems a little like overkill to me.

It's really just an annoying bug of a coding oversight. Reading the comment above it suggests this really just has to do with themes provide a twig template for a theme hook that is only implemented as a function. This will and probably should go away once #1757550: [Meta] Convert core theme functions to Twig templates has been finalized anyhow.

Regardless if they finish that or not, and D8 can still implement theme hooks via functions, this just needs to get fixed. I'll update the issue summary.

markhalliwell’s picture

Issue summary: View changes

Updated issue summary.

markhalliwell’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs tests

Searched the commit history of theme.inc. Not related to Twig, just an oversight.

markhalliwell’s picture

Assigned: Unassigned » markhalliwell
Priority: Normal » Major
Status: Reviewed & tested by the community » Needs work
Issue tags: -Twig +Needs tests

I'll work getting a test in.

markhalliwell’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests +Needs issue summary update
FileSize
4.26 KB
3.63 KB

Alrighty, on my local I was able to get it to fail without the patch and pass with the patch. Go bot go :)

markhalliwell’s picture

Issue summary: View changes

Updated issue summary.

markhalliwell’s picture

Issue summary: View changes

Updated issue summary.

markhalliwell’s picture

Updated issue summary.

star-szr’s picture

Status: Needs review » Needs work

Thank you very much @Mark Carver! Test is looking very good, just found some tiny nitpicks:

+++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.phpundefined
@@ -162,6 +162,14 @@ function testTemplateOverride() {
+    $this->assertText('Theme function overridden', 'Theme hook function overridden by defined \'template\'.');

Instead of escaping the single quotes, surround the assertion message in double quotes.

+++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.phpundefined
@@ -162,6 +162,14 @@ function testTemplateOverride() {
+   * Ensures that a function only based theme hook can be overridden with a template.

For a summary line this is slightly too long, should fit in 80 characters. Additional description can be added in a paragraph below if needed, but this can probably just be shortened. See http://drupal.org/node/1354#functions.

+++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.phpundefined
@@ -162,6 +162,14 @@ function testTemplateOverride() {
+    $this->assertText('Theme function overridden', 'Theme hook function overridden by defined \'template\'.');

+++ b/core/modules/system/tests/themes/test_theme/theme-test-function-template-override.html.twigundefined
@@ -0,0 +1,2 @@
+Theme function overridden

I would love for this test output to end in a period, just to make it consistent with other theme test output.

+++ b/core/modules/system/tests/modules/theme_test/theme_test.moduleundefined
@@ -97,6 +106,13 @@ function theme_test_template_test_page_callback() {
+  return theme('theme_test_function_template_override');

Please return a render array from the page callback :) See #2006152: [meta] Don't call theme() directly anywhere outside drupal_render().

markhalliwell’s picture

Status: Needs work » Needs review
FileSize
2.4 KB
4.48 KB

Yeah, apparently PHPStorm keeps resetting my project settings so my drupal code sniffer was not running. I cleaned up some of the verbiage to better reflect what is happening. Good catch on the the theme() to render array. Old habits die slowly lol

markhalliwell’s picture

Issue summary: View changes

Updated issue summary.

star-szr’s picture

Status: Needs review » Needs work

Looking better :)

+++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.phpundefined
@@ -162,11 +162,12 @@ function testTemplateOverride() {
+   * Ensures that a theme hook implemented via only a function can be
+   * successfully overridden with a template file from a theme.

+++ b/core/modules/system/tests/modules/theme_test/theme_test.moduleundefined
@@ -106,10 +106,14 @@ function theme_test_template_test_page_callback() {
+ * Menu callback for testing that a theme hook implemented via only a function
+ * can be overridden with a template file from a theme.

Both of these are now too long to be summary lines. Summary lines can't wrap - per https://drupal.org/node/1354#drupal "All summaries (first lines of docblocks) must be under 80 characters…"

+++ b/core/modules/system/tests/modules/theme_test/theme_test.moduleundefined
@@ -97,6 +106,17 @@ function theme_test_template_test_page_callback() {
+function theme_test_function_template_override_callback() {
+  $theme_test_function_template_override = array(
+    '#theme' => 'theme_test_function_template_override',
+  );
+  return drupal_render($theme_test_function_template_override);
+}

You don't need to drupal_render() here, you can just return a render array from the page callback. return array('#theme' => …);

markhalliwell’s picture

Status: Needs work » Needs review
FileSize
1.53 KB
4.25 KB

Ah. Didn't read that part, sorry. Here's the right patch.

star-szr’s picture

Status: Needs review » Reviewed & tested by the community

I have no more nits to pick, this looks good to me. Thanks @Mark Carver!

catch’s picture

Status: Reviewed & tested by the community » Needs work

The test menu callback should use the new routing system instead - otherwise we'll have to convert that later. Otherwise agreed it looks good.

markhalliwell’s picture

@catch: I'm confused, should I convert the entire theme_test menu to the new routing system? The only reason I didn't was because we don't change stuff that doesn't pertain to the issue at hand.

catch’s picture

It's fine to add a new item as a route, and leave the rest as hook_menu().

markhalliwell’s picture

Status: Needs work » Needs review
+++ b/core/modules/system/tests/modules/theme_test/theme_test.module
@@ -71,6 +74,12 @@ function theme_test_menu() {
+    'theme callback' => '_theme_custom_theme',

This test requires the custom theme to be used on this page callback, which currently isn't doable via the routing system. See #1954892: Replace 'theme callback' and hook_custom_theme() with a clean theme negotiation system.

markhalliwell’s picture

Status: Needs review » Needs work

Nevermind, dawehner helped me figure out the weird combination of the two.... seems sketchy at best.

markhalliwell’s picture

Status: Needs work » Needs review
FileSize
1.13 KB
3.77 KB

Ok, here's it using the new routing.yml. Let me know what you think.

Status: Needs review » Needs work

The last submitted patch, drupal-warning-missing-argument-2030457-19.patch, failed testing.

markhalliwell’s picture

Status: Needs work » Needs review
FileSize
1.13 KB
5.66 KB

Drush IQ fail, doesn't add unstaged files. New patch.

Status: Needs review » Needs work

The last submitted patch, drupal-warning-missing-argument-2030457-19.patch, failed testing.

markhalliwell’s picture

FileSize
3.43 KB

Correct interdiff.txt

markhalliwell’s picture

Status: Needs work » Needs review
star-szr’s picture

Title: Warning: Missing argument 3 for template_preprocess() » Warning: Missing argument 3 for template_preprocess() for theme functions overridden by templates

Re-titling.

star-szr’s picture

(double post)

star-szr’s picture

Issue summary: View changes

Updated issue summary.

star-szr’s picture

+++ b/core/modules/system/tests/modules/theme_test/lib/Drupal/theme_test/ThemeTestController.phpundefined
@@ -0,0 +1,34 @@
+  /**
+   * Creates the controller.
+   */
+  public static function create(ContainerInterface $container) {
+    return new static();
+  }

This docblock should just use {@inheritdoc}. Other than that, RTBC :)

Ref. https://drupal.org/node/1354#inheritdoc

markhalliwell’s picture

Patch submitted by the Drush iq-submit command.

star-szr’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, looks good :)

star-szr’s picture

Issue summary: View changes

Updated issue summary.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 1398ddf and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Updated issue summary.