Problem/Motivation
Postponed on #3579629: Add procedural hooks to test theme to test collection and invoking legacy hooks so we can add some crucial testing back in.
There are no more functions I am aware of that must reside in .theme files, magic autoloading of .theme files can be the source of some very hard to find bugs.
There is a simple script to assist with converting the hooks in themes and remaining functions can almost just be copy pasted.
We should deprecate the .theme file extension
Important to note: This is not about deprecating the Extension type of themes, just the procedural .theme files.
Steps to reproduce
Proposed resolution
Check for .theme extension files during hook collection.
Add SuppressExtensionFileDeprecation attribute core and contrib can use to skip deprecations.
Emit deprecations for any .theme files without that attribute.
Remaining tasks
Review
Follow ups
Update general documentation:
https://www.drupal.org/docs/develop/theming-drupal
https://www.drupal.org/docs/develop/theming-drupal/drupal-theme-folder-s...
https://www.drupal.org/docs/8/theming-drupal-8/modifying-attributes-in-a...
Add requirements check: #3587107: Add requirements check for deprecated .theme file extensions
Test rector conversion:
https://github.com/palantirnet/drupal-rector/pull/325
https://gitlab.com/-/snippets/5975084
User interface changes
N/A
Introduced terminology
N/A
API changes
.theme files will no longer be autoloaded in Drupal 13.
Data model changes
N/A
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3581218
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:
- 3581218-theme-deprecation-version
changes, plain diff MR !16524
- 3581218-theme-deprecation-11.x
changes, plain diff MR !16525
- 3581218-deprecate-attribute-ignore
changes, plain diff MR !15566
- 3581218-deprecate-theme-file-extension
compare
- 3581218-deprecate-theme-extension
changes, plain diff MR !15190
- main
compare
- 3581218-pp-1-deprecate-.theme
compare
Comments
Comment #2
nicxvan commentedComment #5
nicxvan commentedComment #6
nicxvan commentedComment #7
nicxvan commentedComment #8
nicxvan commentedHad a discussion in Slack with @berdir about this, he strongly thinks we should avoid doing it somewhere that gets hit on most requests or tests.
One potential is that we do it during install or in load ( I don't think that is often enough, though scanners can check no matter what )
We should add an ignore deprecation key to info.yml
ignore_theme_file_deprecationWe should try to match what modules will need too since there are so many more modules when that finally drops too.
I think with this in mind, we add the key to info.yml
In Extension::load we set a flag for .theme files
Add a runtime_requirements hook that reports the list and triggers deprecations for ones that don't have ignore set
This obviously is runtime only, and only for installed themes, but @berdir contends that is enough.
We could explore checking the actual discovery result too, which would probably require adding the info yml key to the extension object even if just for a version or two.
Edit to add: I agree with @berdir where I have it now isn't quite right, I was just trying to see if tons of things blew up.
Comment #9
nicxvan commentedComment #10
catchOption #2 seems reasonable. I'm not sure how much we should worry about not installed themes, they're most likely to be on their way to being removed from a code base? Or installed in some other context when the warning will show.
Comment #11
nicxvan commentedComment #12
nicxvan commentedTagging release manager and framework manager since this is the first time we've deprecated a file extension and I think we'll need feedback on when the removal is.
Comment #13
catchI've been assuming we'd remove support in 13.0 so that we can also remove procedural hook discovery then.
Comment #14
nicxvan commentedOk I converted this to the new approach and added the flag.
We may not need to postpone this actually.
Comment #15
nicxvan commentedComment #16
nicxvan commentedComment #17
nicxvan commentedComment #18
nicxvan commentedComment #19
nicxvan commentedComment #20
nicxvan commentedI took another look. I think doing the deprecation in ThemeHookCollectorPass will be difficult.
We don't have the info parameters we need.
@berdir and I briefly chatted in slack about skipping only if all functions are skipped in the collection, but that also ran into issues with tracking across themes. I think we can collect the info in THCP, but if we don't want the runtime we need somewhere else to actually throw the deprecations.
Comment #21
nicxvan commentedLooking at the kernel again and extension discovery the
ignore_theme_file_deprecationshould be available, I need to take another look.Then we could properly deprecated in thcp.
Comment #22
nicxvan commentedI could be persuaded this isn't a blocker, but I think it fits the bill.
Comment #23
nicxvan commentedOk I took another look:
We'd have to update ExtensionDiscovery to preserve the info parser info for themes to pass it into the kernel:
$type = $this->infoParser->parse($fileinfo->getPathname())['type'] ?? FALSE;We need that so we can track the skipping.
This feels far too low level, we can adjust to the other plan and drop the manual way to skip and only skip if there are no procedural function not skipped in the theme. This feels like it defeats the purpose of having a skip though.
The thing is I think most people get notified about deprecations from upgrade status and tests. Maybe we do it in Extension::load? once we get the ThemeExtension in place?
Comment #24
berdirAgreed, .info.yml is not a good option.
For modules we could add another service parameter, won't work for themes. Adding support for services.yml in themes just for this seems overkill, although there _some_ use cases. \Drupal\default_admin\Settings really wants to be a service, it implements it's own singleton through the classResolver().
I'd prefer to avoid Extension::load() or anything at runtime/every request because of the overhead.
We could add another marker attribute like \Drupal\Core\Hook\Attribute\ProceduralHookScanStop, something like #AcknowledgeExtensionFileDeprecation. If we see that anywhere during parsing, we don't trigger the deprecation. And/Or we could also skip it if no functions are discovered as part of the scan. That would work for stable9.theme as only has two functions, both have the LegacyHook attribute. extra API functions could just slap that on too, doesn't hurt if someone cares. Or we could add support for the #Deprecated.
Comment #28
nicxvan commentedI hid the other branch, I think this is far more elegant, unfortunately we need another file cache for the deprecation suppression, but that feels small.
If this looks agreeable I will update the CR and the IS for the new approach.
Edit: we do still want a notice on the status report page, let me add that back.
Comment #29
nicxvan commentedObsolete
Comment #30
nicxvan commentedThinking about this further, I think this is the way to go, I'll update the IS and CR now.
Comment #32
nicxvan commentedComment #33
nicxvan commentedI created a follow up to discuss the requirements issue: #3587107: Add requirements check for deprecated .theme file extensions
Comment #34
nicxvan commentedComment #35
nicxvan commentedComment #36
berdirSorry for the nitpicks and back and forth, just trying to get this right as it's going to be a pretty big one once it lands.
Comment #37
nicxvan commentedNo worries!
Comment #38
nicxvan commentedComment #39
nicxvan commentedComment #40
berdirI think this is ready. See the open MR on whether or not we want to backport the deprecation to 11.4 or not. I think it can both ways. There's value in warning early, but there are also valid arguments on waiting for D12 Tooling isn't quite there yet still I think, might not want to push too hard yet on that just yet. Modules will definitely not happen in 11.4, we're not there yet in core despite making good progress on preparing core.
Comment #41
nicxvan commentedComment #42
alexpottThis looks great but I think the deprecation message can be improved.
Comment #43
nicxvan commentedI think that's much clearer!
Comment #44
nicxvan commentedThis is ready for review again.
Comment #45
smustgrave commentedFeedback from 41 appears to be addressed and since it was previously RTBC going to move that direction too.
Comment #46
nicxvan commentedComment #47
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #48
nicxvan commentedRebased, conflict was just the use statement for Settings.
Comment #49
nicxvan commentedGotta handle the new theme files.
Comment #50
nicxvan commentedComment #51
berdirUpdate for the new test looks correct.
Comment #53
alexpottI think we should also improve:
(without the .theme extension)anymore.(without the .theme extension)anymore.There is also \Drupal\system\Form\ThemeSettingsForm::buildForm() which includes .theme files (add theme-settings.php) and triggers a form alter :) - do we have an issue for OOifying that?
This would leave the following .theme references which imo are correct and should only be fixed once we no longer support .theme (ie. Drupal 13)
Comment #54
nicxvan commentedGood catch!
I've updated those three documentation points.
They are just hook_form_alters at the end of the day, they can already be OOP, there is #3580152: Deprecate theme-settings.php files for explicitly deprecating using that file though which is postponed on this issue.
I agree, I'm not sure when we clean up the .gitattributes, since we also have the .engine extension in there, but that can be a follow up.
Comment #55
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #56
nicxvan commentedMissed a period.
Comment #57
larowlanAgree with the deprecate in 12 remove in 13 timeline from a FM POV, removing the tag
Comment #58
nicxvan commentedNot sure why I added the subsystem maintainer tag.
Comment #59
berdirneeds work to possibly address the review, did reply to some points.
Comment #60
catchI'm not sure how much we need the attribute for themes but given we'll need it for modules and it makes sense to have parity between the two, seems fine to have it here. Everything apart from the attribute situation is pretty straightforward so removing the needs release manager review tag.
Comment #61
nicxvan commentedAddressed the feedback, I think this is ready for review again.
Comment #62
smustgrave commented1 small question on the MR. It's small enough I'm not going to hold this up since it's got sign off on every level needed.
Comment #64
larowlanCommitted 62c7178 and pushed to main. Thanks!
Need a new MR for 11.5, setting to Patch (to be ported).
Published change record.
Comment #67
nicxvan commentedAre we backporting this? If we are we need to update the message on main.
11.x will require a fair bit more work since olivero and stable9 still have .theme files. I'm not sure if it's worth backporting.
Comment #68
larowlanThe 11.5.0 release priority tag you added made me think you were planning on it?
Comment #69
nicxvan commentedI forgot about that! :) yeah I think it's better to backport to be honest.
I'll add the ignore attribute to the themes since they are converted in 12.
Comment #70
nicxvan commentedI backported to 11.x and added the ignore tag to the three remaining .theme files since we've converted them all in main.
The only conflict was the test for deprecated themes since that had been removed in main and readded, but here it's just a new method.
I also opened a new MR against main for the deprecation version update.
Comment #71
smustgrave commentedSeems like a good backport. Congrats on landing this btw!
Comment #72
larowlanCommitted to 11.x and updated change record - thanks
Comment #76
quietone commentedI updated the change record but did not publish it as I have questions about it. I am going to ask in Slack first about it.
Comment #77
quietone commentedChanged my mind.
The questions are:
Comment #78
nicxvan commentedComment #79
quietone commented@nicxvan, thanks for the answers.
nicxvan and I also chatted in #core-development where I was still confused about the need to mention 11.3 in the change record. It comes down to me not knowing enough about themes and the whole converting to OO process. We also updated the change record making some small clarifications and the rector script was also changed to state that is it for DDEV.
I have published the change record.
Comment #81
ressaThanks for the clean up. Under "Remaining tasks", there are links to a few doc pages in need of an update. I am not sure if some of these were tasks were done, and pages were created, but just not published yet?
There is a link in the Change Record .theme file extensions have been deprecated to a DDEV script, which may seem a bit complicated for some site builders ... so it would be nice if a new "Converting from .theme-file to an object oriented class" section was added on https://www.drupal.org/docs/8/theming-drupal-8/modifying-attributes-in-a..., which outlines how to convert the existing
mytheme_preprocess_menufunction to use the new method. Perhaps inspiration can be found in Hooks in themes can now be OOP?Also, maybe a new documentation Page under https://www.drupal.org/docs/develop/theming-drupal could be created, documenting the new method for functions in themes, with a few examples? Hooks in themes can now be OOP could be an excellent starting point, which could be adjusted and expanded in this new doc page.
Comment #83
nicxvan commented