Avoid t() calls, instead use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t()

Created on 12 May 2020, about 4 years ago
Updated 20 January 2023, over 1 year ago

Problem/Motivation

After running coder for Drupal Best Practices, I found the following issues regarding t() calls:

phpcs --standard=DrupalPractice .

FILE: /broken_link/src/Form/BrokenLinkDeleteMultipleForm.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------
 87 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
-----------------------------------------------------------------------------------------------------------------------------------------


FILE: /broken_link/src/Form/BrokenLinkRedirectDeleteForm.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------
 65 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
-----------------------------------------------------------------------------------------------------------------------------------------


FILE: /broken_link/src/BrokenLinkViewsData.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------
 24 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
-----------------------------------------------------------------------------------------------------------------------------------------

Proposed resolution

Need to replace t() calls with $this->t() and use \Drupal\Core\StringTranslation\StringTranslationTrait wherever required.

📌 Task
Status

Closed: duplicate

Version

3.1

Component

Code

Created by

🇮🇳India ankithashetty Karnataka, India

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.69.0 2024