Problem/Motivation

Part of #3504381: [meta] Convert Template Preprocess hooks to OOP equivalent

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3533290

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

Title: Convert template_preprocess functions in image and file modules » Convert template_preprocess functions in image module
Status: Active » Needs review

Reducing scope to image module. there are several, in different include files, so that seems enough on its own.

Not 100% sure on BC for the functions in the include files, there might be some edge cases where that might fail anyway, but kept the pattern for now and moved them to .module.

Used the new closure pattern for the injected logger service, makes it a tiny bit more complicated, but seems like a good compromise for the typical logger-used-in-rare-case scenario and we'd need an Attribute anyway for autowiring.

berdir’s picture

The performance test fail confused me, I thought we somehow no longer load a config or I had the wrong config name. But that's not it, it's the opposite. Because this is now injected here, it's loaded already on the initial user/login request that warms up bootstrap caches and it's cached afterwards.

I opened #3533322: Do not fetch default image toolkit ID in ImageFactory::__construct() for this.

berdir’s picture

Updated the comment references in templates that I forgot before. I'd prefer doing the issue in #4 first to avoid the misleading performance test change here.

smustgrave’s picture

Are we doing CRs for all the twig templates that would have to be updated on contrib modules?

nicxvan’s picture

What twig templates would need to be updated?

smustgrave’s picture

This one has 5 twig template it appears to be updating the @see for.

nicxvan’s picture

We've not done CRs on other issues like this for that, I don't think this really warrants one since it's just a comment.

berdir’s picture

Initially I considered to drop this pattern with the @see referencing the template/initial preprocess, but got some resistance on that from theme maintainers, so I gave up on that, at least in this scope. It's similar with the docs in twig templates in general, some of these templates have extensive docs that are copy pasted around and tend to get outdated. The default node.html.twig for example has 60 lines of comments and 20 lines of actual markup. And that whole thing exists 11 times in core. And it is at least partially outdated, there's a whole block on default classes, which in fact do not exist but are set within the twig template itself in some cases and not others. Many of us are probably using IDE's or editors that hide that by default and don't even notice it anymore. But I also don't have a great idea on what else we should do. It can be useful for people who are new to Drupal and theming I guess.

smustgrave’s picture

Yea not sure what the best approach is. I know when I override a template I usually copy the whole thing, comments included for the next dev.

What if we had just a generic overall CR for themers to update their templates to use these classes?

berdir’s picture

We have a generic change record: https://www.drupal.org/node/3504125. but I don't see the point of telling people to update the @see. Nobody is going to do that, that's a lot of tedious work for no real gain. Yeah, in 5 years, if someone looks at a template they won't find that function anymore. But they can just look at the source template, that takes a few seconds, far less time than manually updating all templates.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The 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.

berdir’s picture

The soft blocker is in, this can be rerolled and there shouldn't be any performance test changes anymore.

berdir’s picture

Status: Needs work » Needs review

Rebased without the performance stuff

nicxvan’s picture

Status: Needs review » Reviewed & tested by the community

This is ready now!

I confirmed template_preprocess_HOOK were all moved to image.module
There are only single _
Zebra shows only changes are file key, DI, t() and comments for cs
Confirmed deprecations are file and functions as expected
All initial preprocess align with the theme keys

quietone’s picture

I am going to ask the other committers about the change record on this.

I have updated credit.

quietone’s picture

I think it best to link to a change record instead of an issue. I talked to catch and we agreed to continue to use the existing CR but to update it to resolve the @todo at the bottom of it. This is the @todo. And I think it should just be just Drupal 12 as it looks like all the conversions will be completed by then.

Discovery of legacy template_preprocess_HOOK() functions is deprecated and will be removed in Drupal 12 or 13 (@todo: Update when decided)

catch’s picture

I've updated the CR to include this line "Note that some procedural functions were converted in Drupal 11.2 and some in 11.3. " next to where we say we don't expect people to be interacting with them directly.

Also updated the removal version to Drupal 12 per #18 - we can always change our minds again later but there's not that many of these compared to hooks in general.

  • catch committed 0f066170 on 11.x
    Issue #3533290 by berdir, smustgrave, nicxvan, quietone: Convert...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x, thanks!

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

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

Maintainers, please credit people who helped resolve this issue.

berdir’s picture

Component: theme system » image.module
Category: Feature request » Task

That reminds me, the information when a BC layer is removed does currently not exist in a structured way in change records, that would be way more useful than the branch. Does someone know if an issue exists to add that? Especially now when not everything is being removed for the next major.

I think removing old template_preprocess functions in D12 is one thing, removing support for it might be pretty disruptive. On the other side, BC is built-in and just works (Drupal 11.2+ only looks for a template_ function if no explicit initial preprocess is specified), so it's pretty easy to do that, I recently updated token module accordingly. You don't need a LegacyHook attribute or anything, just leave the old function there and either call the new or just keep it as-is, depending on how much code there is. And it would also make it easier to also deprecate the file and includes keys in hook_theme for D12 (which aren't deprecated yet), because template_preprocess functions is really the only thing they are still used for. We an add an explicit deprecation in either the meta issue or a follow-up of it and finalize that there.

Updating metadata, this in image.module task not a feature.

Status: Fixed » Closed (fixed)

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