Problem/Motivation
t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead.
Steps to reproduce
phpcs --standard=DrupalPractice --sniffs=DrupalPractice.Objects.GlobalFunction .
FILE: ...contrib/rocketship_paragraphs/modules/menu_clickthrough/src/Menu/MenuTreeStorageMenuHelper.php
----------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
----------------------------------------------------------------------------------------------------
71 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
72 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
----------------------------------------------------------------------------------------------------
FILE: ...tship_paragraphs/modules/menu_clickthrough/src/Plugin/Field/FieldWidget/ClickthroughWidget.php
----------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
----------------------------------------------------------------------------------------------------
103 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
104 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
120 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
121 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
----------------------------------------------------------------------------------------------------
FILE: ...paragraphs/modules/menu_clickthrough/src/Plugin/Field/FieldFormatter/ClickthroughFormatter.php
----------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
----------------------------------------------------------------------------------------------------
187 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
262 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
----------------------------------------------------------------------------------------------------
FILE: .../rocketship_paragraphs/src/Form/SettingsForm.php
----------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 22 WARNINGS AFFECTING 22 LINES
----------------------------------------------------------------------------------------------------
43 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
49 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
51 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
56 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
58 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
63 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
65 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
70 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
71 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
93 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
99 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
101 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
106 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
108 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
113 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
115 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
120 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
122 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
127 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
129 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
210 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
215 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
----------------------------------------------------------------------------------------------------
FILE: .../rocketship_paragraphs/src/Plugin/Field/FieldFormatter/NameRuleFormatter.php
----------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------
80 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
----------------------------------------------------------------------------------------------------
FILE: .../rocketship_paragraphs/src/Plugin/Field/FieldFormatter/ImageUrlFormatter.php
----------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
----------------------------------------------------------------------------------------------------
103 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
106 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
117 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
120 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
----------------------------------------------------------------------------------------------------
Time: 109ms; Memory: 10MB
Comments
Comment #2
harshita mehna commentedHello Maintainers,
I have provided a patch to fix this issue.
To get more information visit https://www.drupal.org/project/drupal/issues/3115809
Please review it.
Thanks!
Comment #3
nginex commentedComment #4
harshita mehna commentedThanks, for your review @nginex
Comment #5
lucienchalom commentedneither of the files needed the 'use Drupal\Core\StringTranslation\StringTranslationTrait;' because they extends code that already have it.
There are still some t() calls, I edited the Issue Sumary, with the list.
Comment #6
harshita mehna commentedHello, Maintainers and @lucienchalom
Thanks for the review.
I have updated the patch please review it.
Thanks!
Comment #7
lucienchalom commentedThank you for the update.
There are still t call in these files:
rocketship_paragraphs/modules/menu_clickthrough/src/Menu/MenuTreeStorageMenuHelper.php
rocketship_paragraphs/modules/menu_clickthrough/src/Plugin/Field/FieldWidget/ClickthroughWidget.php
rocketship_paragraphs/modules/menu_clickthrough/src/Plugin/Field/FieldFormatter/ClickthroughFormatter.php
Back to needs work
Comment #8
nitin_lamaComment #10
bharath-kondeti commentedAddressed #7 and fixed the issues.
Comment #12
avpadernoComment #13
lucienchalom commentedPatch and MR are the same, the t() calls were fixed without any problem.
Looks good to me.
RTBC
Comment #17
l_vandamme commentedCommitted to 5.2.x and released as part of https://www.drupal.org/project/rocketship_paragraphs/releases/5.2.0
Comment #19
l_vandamme commented