Comments

sandeepscs created an issue. See original summary.

sandeepscs’s picture

Status: Active » Needs review
StatusFileSize
new5.36 KB

Please find patch

Aanal.addweb’s picture

Status: Needs review » Reviewed & tested by the community

@sandeepscs, Thanks for the updated patch, I checked it through manually patch uploading process in module, as per my testing it works well.

cilefen’s picture

Version: 8.2.6 » 8.4.x-dev
cilefen’s picture

Title: Action module : $this->t() should be used instead of t() » $this->t() should be used instead of t()
Component: other » action.module
Category: Bug report » Task
Lal_’s picture

Assigned: sandeepscs » Unassigned
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new5.32 KB

Status: Needs review » Needs work

The last submitted patch, 6: 285062-6.patch, failed testing.

tameeshb’s picture

Status: Needs work » Needs review
StatusFileSize
new5.19 KB

Redone patch for 8.4.x

joshi.rohit100’s picture

Status: Needs review » Needs work

ActionListBuilder is still affected.

manishmittal9’s picture

Assigned: Unassigned » manishmittal9
manishmittal9’s picture

Status: Needs work » Needs review
StatusFileSize
new6.17 KB

New patch addressing the comment #9

manishmittal9’s picture

Assigned: manishmittal9 » Unassigned
phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Looks perfect. Thank you!

phenaproxima’s picture

Title: $this->t() should be used instead of t() » $this->t() should be used instead of t() in Action classes
alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Thank you for your work on cleaning up Drupal core's use of deprecated APIs!

In order to deprecate APIs in a maintainable way, converting deprecated uses should be replaced across all of core for a given kind of usage, rather than in individual modules or files. Such issues should also always be part of an overall plan to ensure all usages are removed, rather than standalone patches.

For background information on why we usually will not commit cleanups that aren't scoped in that way, see the core issue scope guidelines. See the core deprecation policy for more information on how we handle deprecations.

Contributing to the overall plan above will help ensure that your cleanups for core's deprecated code improve core in a maintainable and minimally disruptive way.

I think that we're going to need a coding standard to enforce this one because there are just too many usages. I.e. we need to add a rule to coder that can check for t() function use in a class and apply it to core.

The next steps are here are to:

  1. Close this and all the duplicate issues
  2. Open an issue on the Coder project to create the rule - there will need be some nuance to the rule because t() is permitted within static methods - or maybe be we want to fix them too - since they could just create TranslatableMarkup objects.
  3. On #2859390: t() should be replaced with $this->t() file a mega-patch to apply the rule to core and fix everything.
chi’s picture

Just out of curiosity, do we have officially approved coding standard about disallowing t() function in OOP code?

alexpott’s picture

@Chi - no but Coder doesn't have to be just about coding standards - it can recommend best practices. And best practices are to not use procedural methods from classes as this makes code harder to unit test. We don't need a coding standard for this.

manishmittal9’s picture

Status: Needs work » Closed (duplicate)

As suggested in comment #15, the issue is closed.
A new issue has been created on coder project https://www.drupal.org/node/2860116 recommending the practice of using $this->t() instead of t()
Issue https://www.drupal.org/node/2859390 is open for work to patch to all the modules of the core

chi’s picture

Coder doesn't have to be just about coding standards - it can recommend best practices

Well, the description of Drupal ruleset says "Drupal coding standard", but another ruleset called Drupal best practice seems to be the right place for this rule. But I am not aware if it is used by drupal.org CI system.

There were multiple issues of this type raised recently (I've closed a couple - details). I propose this best practice to be established and documented somewhere first.