Problem/Motivation

Themes always get an extra chance at the end of \Drupal\Core\Theme\Registry::processExtension() to add preprocess to everything, and then also the extra-extra processing for theme suggestions (which I think we an clean up and combine if we extend the current preprocess-collected data and combine it, but that's for D12).

Theme engines currently also looks for theme prefixed functions, Modules don't do that. This check does not support OOP and it specifically does not support LegacyHook, so it might add preprocess twice. It also doesn't deal with base themes.

Adding a breakpoint within the second theme specific loop shows that theme preprocess functions are added twice, the array_unique() in \Drupal\Core\Theme\Registry::postProcessExtension() will then make it unique again.

There is a condition and if comment above that says "Check only if not registered by the theme or engine.", but the second part of that statement is untrue, as engines are processed in a separate call to processExtension(), so $result will never contain templates returned by engines.

This has wrong/unnecessary the since before 2013 when the theme registry discovery was converted to a service.

Steps to reproduce

Proposed resolution

Remove the theme prefix when processing theme extension templates.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3554919

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

berdir created an issue. See original summary.

berdir’s picture

Status: Active » Needs review

I had one fail in a test that first looked related in ThemeTest about switching the default theme, but it was an assert on a config value and must have been a random fail/race condition?

berdir’s picture

Issue summary: View changes
nicxvan’s picture

Status: Needs review » Reviewed & tested by the community

I suspected this was true when we did the theme oop issue but it's easier to confirm here without the noise.

Had very a lengthy discussion in slack about whether there is anything else to consider, but the issue summary sums up our conclusions rather nicely.

catch made their first commit to this issue’s fork.

  • catch committed 4ebc3ee0 on 11.3.x
    fix: #3554919 Stop discovering theme preprocess twice for theme engine...

  • catch committed d0a1f5ba on 11.x
    fix: #3554919 Stop discovering theme preprocess twice for theme engine...
catch’s picture

Version: 11.x-dev » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Good find.

Committed/pushed to 11.x and cherry-picked to 11.3.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

longwave’s picture

We could refactor away that foreach now it only has one iteration, will open a followup.

longwave’s picture

Status: Fixed » Closed (won't fix)

Let's not bother as this is in a deprecated path anyway.

longwave’s picture

Status: Closed (won't fix) » Fixed
catch’s picture

Title: Stop discovering theme preprocess twice for theme engine discovered templates » [head broken] Stop discovering theme preprocess twice for theme engine discovered templates
Version: 11.3.x-dev » 11.x-dev
Category: Task » Bug report
Priority: Normal » Critical
Status: Fixed » Active

Per slack discussion we probably need to revert this due to early installer weirdness. Details to be filled out later (before or after the actual revery, but not doing it immediately).

nicxvan’s picture

Title: [head broken] Stop discovering theme preprocess twice for theme engine discovered templates » Stop discovering theme preprocess twice for theme engine discovered templates
Status: Active » Fixed
Related issues: +#3562319: [regression] The installer does not properly load the theme

Thank you, after further investigation I think we found the root cause, we can address that separately here: #3562319: [regression] The installer does not properly load the theme

Putting this back to fixed for now.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

dww’s picture

Version: 11.x-dev » 11.3.x-dev
Category: Bug report » Task
Priority: Critical » Normal

Restoring more metadata for posterity.

nicxvan’s picture

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

Hate to ping pong a bit, but version should remain 11.x

dww’s picture

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

See #9. 🤓 I think core committers move the version to the earliest real version a change was committed to.

catch’s picture

Yes this is true, it has got a bit messy with the 11.x branch because all the commits that go into 11.x before 11.3.x was opened don't get moved, but we still try to do that when whichever lower branch gets committed to is open.

Status: Fixed » Closed (fixed)

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