t() calls should be avoided in classes

Created on 24 January 2023, over 1 year ago
Updated 19 April 2023, about 1 year ago
FILE: /var/www/html/dcontri/charts_twig/src/ChartsTwig.php
---------------------------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 8 WARNINGS AFFECTING 6 LINES
---------------------------------------------------------------------------------------------------------------------------------------------
  1 | ERROR   | [x] The PHP open tag must be followed by exactly one blank line
 29 | ERROR   | [x] You must use "/**" style comments for a function comment
 35 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 35 | WARNING | [ ] Only string literals should be passed to t() where possible
 42 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 42 | WARNING | [ ] Only string literals should be passed to t() where possible
 48 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 48 | WARNING | [ ] Only string literals should be passed to t() where possible
 53 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 53 | WARNING | [ ] Only string literals should be passed to t() where possible
---------------------------------------------------------------------------------------------------------------------------------------------
🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇮🇳India gayatri chahar

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Comments & Activities

  • Issue created by @gayatri chahar
  • 🇮🇳India gayatri chahar

    Patch created. Please review it

  • 🇮🇳India akshay.singh Noida

    I will review this.

    Thanks

  • Issue was unassigned.
  • 🇮🇳India akshay.singh Noida
    FILE: /var/www/html/dcontri/charts_twig/src/ChartsTwig.php
    --------------------------------------------------------------------------------
    FOUND 2 ERRORS AND 4 WARNINGS AFFECTING 6 LINES
    --------------------------------------------------------------------------------
      1 | ERROR   | [x] The PHP open tag must be followed by exactly one blank line
     29 | ERROR   | [x] You must use "/**" style comments for a function comment
     35 | WARNING | [ ] Only string literals should be passed to t() where possible
     42 | WARNING | [ ] Only string literals should be passed to t() where possible
     48 | WARNING | [ ] Only string literals should be passed to t() where possible
     53 | WARNING | [ ] Only string literals should be passed to t() where possible
    --------------------------------------------------------------------------------
    

    After applying the above patch. I found the string literal issues along with the formatting issues and fixed them.
    Please check.

    Thanks

  • 🇮🇳India hardikpandya

    I see the patch is applying and all the issues are fixed. Marking as RTBC.

  • Status changed to RTBC over 1 year ago
  • @hardikpandya opened merge request.
  • 🇺🇸United States andileco

    Thank you all for your patches. The base class does not have the string translation method, so it was necessary to add the StringTranslationTrait in order to use $this->t(). I also added a couple adjustments to the docblock, parameters while I was in the code.

  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States andileco

    OK, so right after I created the last patch, I did some testing and realized the $this->t() was not getting reached. If you want to translate, you need to use |t or |trans in the Twig code itself. I added documentation in the README. I also replaced $this->t() with Xss::filter() to provide additional controls on the strings that users can input.

    • andileco committed 5735a1da on 1.0.x
      Issue #3336007 by andileco, hardikpandya, gayatri chahar, akshay.singh:...
  • Status changed to Fixed about 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024