Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for deprecated preprocess variables #776

Open
catch56 opened this issue Jul 3, 2024 · 1 comment
Open

Support for deprecated preprocess variables #776

catch56 opened this issue Jul 3, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@catch56
Copy link

catch56 commented Jul 3, 2024

Feature request

Core added support for deprecating Twig variables a couple of years ago, it has not been used much yet, CR is here: https://www.drupal.org/node/3334622

In https://www.drupal.org/project/drupal/issues/3458587 and sub-issues I'm actually trying to use it, of course this immediately runs into limitations.

The support we added in core supports detecting when a deprecated variable is used in a twig template, so that the template author can remove it.

However a lot of custom/contrib preprocess implementations check the value of one preprocess variable to then set the value of another, or overwrite preprocess variables etc. - we don't have any detection for that because it's just array keys.

Alex Pott suggested a phpstan-drupal issue to see if we can add detection. Because the support relies on values of $variables['deprecations'] which is also set in preprocess, it would be extremely difficult for php-stan drupal to dynamically determine this, but we wondered about hardcoding specific variable names like 'teaser' in a list then looking for $variables['teaser'] in any node preprocess hook and notifying if it's found. If we only look for $variables['teaser'] that would reduce false positives like $variables['view_mode'] === 'teaser'. This support would not be perfect, but we could detect the most disruptive changes which would be better than nothing.

https://www.drupal.org/project/drupal/issues/3458183 is the first issue to actually land from the latest round so there is something to try against.

@catch56 catch56 added the enhancement New feature or request label Jul 3, 2024
@mglaman
Copy link
Owner

mglaman commented Jul 4, 2024

We'll need to make a generic rule that can be configured, maybe.

Checks if running in a preprocess hook of X or generic one. And access of any specific key in $variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants