Currently in a Drupal 8 training, and we had an empty stub hook_theme() function with no return. When we enabled this module, it caused PHP fatal errors. The code in _theme_process_registry() could just simply check for a non-empty value.

Issue fork drupal-2064573

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new762 bytes
steinmb’s picture

Looks good to me if testbot comes back green.

dawehner’s picture

StatusFileSize
new2.15 KB

Casting would be also possible ... here is a version which a test included.

chx’s picture

Status: Needs review » Closed (won't fix)
  $result = $function($cache, $type, $theme, $path);
  foreach ($result as $hook => $info) {

This is the same as in Drupal 6 https://api.drupal.org/api/drupal/includes%21theme.inc/function/_theme_p... and Drupal 7 https://api.drupal.org/api/drupal/includes%21theme.inc/function/_theme_p... I am all for this new found babysitting but if it was fine for two releases, it'll be fine for a third. Why are you implementing hook_theme / how are you implementing if it does not look like return array(...) ?

dave reid’s picture

Ah, if it's the same as D7, then this seems appropriate. Odd that hook_theme() is the only one that fails if you don't return something.

chx’s picture

It's not a normal hook, after all, but still: what are you doing that hook_theme is empty? I really, really would like to know.

dawehner’s picture

hook_theme() is the only one because all that logic is properly fixed in ModuleHandler, ... this checks that the result "isset"

dave reid’s picture

Even though it's been this way for a while, It would be nice if we could make this hook work like other hooks where no return value doesn't break the entire system with just a simple if check.

neclimdul’s picture

Status: Closed (won't fix) » Active

Just because it was wrong before doesn't make it right now. If we don't fix it this just falls into all the numerous "what's a hook?" inconsistencies we've been confusing people with for years. Also, its a trivial fix so why would it be a big deal?

dawehner’s picture

Status: Active » Needs review

Back to needs review.

Crell’s picture

A fatal error that doesn't give you a useful message about what you did wrong is a bug. Period. This should be fixed. (It should have been fixed long ago, but let's fix it now.)

chx’s picture

Then let's at least NOT do this test. It's silly to add a whole new module needing enabling further slowing down poor bot. That's my problem.

Of course, there's no answer to the repeated question "what are you doing that it's not an array" instead we have theory ("it's a bug") again and again. I am sick of theories.

Crell’s picture

It's not that an empty hook_theme implementation or a hook_theme implementation that forgets a return statement at the end (same result) isn't a bug. It's that the current handling of that bug is utterly useless to help a developer fix it. "Fail fast, fail cheap, fail *usefully*. If you can fail gracefully, even better.

(Background: I accidentally wrote an empty hook_theme implementation in sample code for the training class Palantir is running this week without realizing it, and proceeded to confuse an entire class full of people with a totally unhelpful error for 10 minutes before we figured out WTF was going on. That's 9 minutes and 58 seconds longer than it should have taken. And allowing a null return to be treated as an empty array means that it would have been a non-issue, quickly resolved when the students began writing a hook_theme implementation 15 minutes after that.)

I have no opinion on whether or not we burn extra testbot cycles on it.

dawehner’s picture

I totally agree that this simple bug should be fixed. Regarding test coverage ... we could also add a state check in the theme_test and return NULL when needed.

chx’s picture

Sounds great! Let's do that.

dawehner’s picture

StatusFileSize
new2.24 KB

.

chx’s picture

Status: Needs review » Reviewed & tested by the community
catch’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/includes/theme.inc
@@ -463,7 +463,7 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) {
+    $result = (array) $function($cache, $type, $theme, $path);

Needs a comment as to why we're casting.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new594 bytes
new2.31 KB

There we go.

alansaviolobo’s picture

Issue summary: View changes
StatusFileSize
new606 bytes

rerolling

Status: Needs review » Needs work

The last submitted patch, 20: an_empty_hook_theme-2064573-20.patch, failed testing.

joelpittet’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: +rc target triage
StatusFileSize
new2.42 KB

Rerolling and tested this and it seems to fix the issue. There was a nice fatal before the patch and after the patch it was fine.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 22: an_empty_hook_theme-2064573-22.patch, failed testing.

xjm’s picture

Issue tags: -rc target triage

I don't think it's necessary to fix this during RC.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
larowlan’s picture

This looks like it just needs a reroll and we're off to the races

catch’s picture

+++ b/core/modules/system/tests/modules/theme_test/theme_test.module
@@ -6,6 +6,9 @@
+    return NULL;

Nit: this can just be return;

Revisited the approach, I think the cast + test coverage are fine, so just a re-roll seems plenty here.

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new2.45 KB

Rerolled per comment #35 + #36

Status: Needs review » Needs work

The last submitted patch, 37: 2064573-37.patch, failed testing. View results

immaculatexavier’s picture

Status: Needs work » Needs review
StatusFileSize
new3.02 KB
new2.08 KB

Rerolled patch against 9.3.x
Attached Rerolled diff against #37

Status: Needs review » Needs work

The last submitted patch, 39: 2064573-39.patch, failed testing. View results

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

rassoni’s picture

Status: Needs work » Needs review
StatusFileSize
new11.46 KB
new9.31 KB

Fixed Failed test #39
Added interdiff

Status: Needs review » Needs work

The last submitted patch, 42: 2064573-42.patch, failed testing. View results

medha kumari’s picture

Version: 9.4.x-dev » 9.5.x-dev
Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new4.01 KB

Reroll the patch #39 with Drupal 9.5.x

Status: Needs review » Needs work

The last submitted patch, 44: 2064573-44.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new961 bytes
new5.07 KB

Fixed test case in #44

vinmayiswamy’s picture

As mentioned in #35 and #36, I just verified the re-rolled patch #46 in Drupal 9.5.x version. Patch applied successfully.

Also the return statement was updated as mentioned in #36

+++ b/core/modules/system/tests/modules/theme_test/theme_test.module
@@ -12,6 +12,9 @@
  * Implements hook_theme().
  */
 function theme_test_theme($existing, $type, $theme, $path) {
+  if (Drupal::state()->get('theme_test_theme_null')) {
+    return;
+  }

Thanks for the patch @smustgrave

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

sahil.goyal’s picture

StatusFileSize
new10.37 KB

Reroll the patch for the current version 10.1.x as latest patch was not compatible.

Sorry, forgot to add patch

sahil.goyal’s picture

StatusFileSize
new9.47 KB
new10.37 KB

Re-uploading the patch and rerolldiff

ameymudras’s picture

Status: Needs work » Needs review
StatusFileSize
new9.5 KB
new703 bytes
bhanu951’s picture

StatusFileSize
new9.45 KB
new363 bytes

Fixed test failure.

bhanu951’s picture

StatusFileSize
new358 bytes

Fixed corrupt patch and added it as MR.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new85 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

rishabh vishwakarma’s picture

Status: Needs work » Needs review
StatusFileSize
new9.5 KB

Patch against 10.1.x

rishabh vishwakarma’s picture

StatusFileSize
new539 bytes

Interdiff #52-#57

bhanu951’s picture

@Rishabh Vishwakarma what was the base for your re-roll ?

Can you post interdiff ?

As you can see there is already a MR raised against 10.x branch there is no need for patches. You can just continue working on the MR. Thanks.

edit : Seems you added the details before this comment got published.

As you can see there is already a MR raised against 10.x branch there is no need for patches. You can just continue working on the MR. Thanks.

This point still stands. Your patch is identical to MR.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Novice +Needs Review Queue Initiative, +Needs issue summary update

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

This could use an issue summary update. What is the proposed solution as this is touching a number of files? May need framework review too
Recommend using issue summary template.

larowlan’s picture

Left a review, there's a lot of out of scope changes here.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.