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
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Harshita mehna created an issue. See original summary.

harshita mehna’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new9.27 KB

Hello 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!

nginex’s picture

Version: 5.x-dev » 5.0.x-dev
harshita mehna’s picture

Thanks, for your review @nginex

lucienchalom’s picture

Issue summary: View changes
Status: Needs review » Needs work

neither 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.

harshita mehna’s picture

Status: Needs work » Needs review
StatusFileSize
new8.4 KB

Hello, Maintainers and @lucienchalom
Thanks for the review.
I have updated the patch please review it.

Thanks!

lucienchalom’s picture

Status: Needs review » Needs work

Thank 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

nitin_lama’s picture

Assigned: Unassigned » nitin_lama

bharath-kondeti made their first commit to this issue’s fork.

bharath-kondeti’s picture

Status: Needs work » Needs review
StatusFileSize
new12.2 KB

Addressed #7 and fixed the issues.

avpaderno’s picture

Title: t() calls should be avoided. » Replace the calls to t() done in classes
Assigned: nitin_lama » Unassigned
Category: Bug report » Task
lucienchalom’s picture

Status: Needs review » Reviewed & tested by the community

Patch and MR are the same, the t() calls were fixed without any problem.
Looks good to me.
RTBC

  • 8882d221 committed on 5.2.x
    fix: #3368205 Replace the calls to t() done in classes
    
    By: harshita...

l_vandamme’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

l_vandamme’s picture

Status: Fixed » Closed (fixed)