Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
While doing #2073075, it was discovered that some classes are using global function t() - while including StringTranslationTrait, which has its own t() method.
We found it in field_ui's EntityDisplayModeListBuilder, FieldStorageConfigListBuilder - but these are fixed now in the related issue.
There definitely are more *ListBuilder classes in other modules (and possibly other classes using StringTranslationTrait) that should be changed. We didn't check how many yet.
Proposed resolution
The older t() can be replaced by $this->t().
Remaining tasks
- find out how many changes there are to make
- decide if this is novice or not
- Change the code
User interface changes
No
API changes
No
Comments
Comment #1
roderikFYI:
I spotted this in #2073075 which is just replacing t() with $this->t() now so I guess it should be done in the classes mentioned in the summary, too (and not in tests)...
...but tbh I don't know the best scope of this issue. (Per subsystem? Should we search for e.g. all classes using EntityHandlerBase in Drupal core, and do a patch for them in one go? Or is this cleanup part of another issue already - I couldn't find any.)
So anyone who has an opinion on that - please say it.
Comment #2
roderik(Rephrasing to current scope checked in the issue summary)
Comment #3
roderiktagging
Comment #4
YesCT CreditAttribution: YesCT commentedre-scoped based on a change in #2073075: Don't call the t() function in OO code in the field_ui module
removing novice until we know how giant this might end up being.
Comment #5
roderikComment #6
xjmThanks @vanilla-bear and @roderik for finding and filing this!
As a normal task, this especially needs to be checked against the Allowed changes during the Drupal 8 beta. Following through the chart there:
t()
is not marked deprecated.So, we should postpone this change to 8.1.x. It's okay to make it in 8.1.x, because there will be no BC break.
However, I noticed that the docs for
t()
do not even mention the availability ofStringTranslationTrait
. So maybe we could file a separate issue to add documentation suggesting the use ofStringTranslationTrait
rather thant()
in classes? That would be okay before 8.0.0 as it's just an improvement to documentation.Comment #17
quietone CreditAttribution: quietone as a volunteer commentedLooks like the work this is to do is being done in #3113904: [META] Replace t() calls inside of classes . I think this can be closed as a duplicate.