Replace t() calls inside of Controllers that do not use StringTranslationTrait

Created on 8 October 2022, over 1 year ago
Updated 30 June 2024, 2 days ago

Problem/Motivation

I was reviewing the code of SystemController.php and noticed that there was a procedural t() function instead of $this->t() which is not a best practice to use inside a controller.

$admin_theme_options[$theme->getName()] = $theme->info['name'] . ($theme->isExperimental() ? ' (' . t('Experimental') . ')' : '');

Steps to reproduce

Proposed resolution

Fix Controllers in non tests for the sniff 'Drupal.Commenting.DocComment.ShortSingleLine'
That should be these files

  • core/modules/views_ui/src/Controller/ViewsUIController.php
  • Moved to contrib
  • Moved to contrib
  • core/modules/system/src/Controller/SystemController.php
  • core/modules/update/src/Controller/UpdateController.php

Remaining tasks

review
commit

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

RTBC

Version

11.0 🔥

Component
Other 

Last updated about 7 hours ago

Created by

🇮🇳India rakesh.drupal Delhi

Live updates comments and jobs are added and updated live.
  • Coding standards

    It involves compliance with, or the content of coding standards. Requires broad community agreement.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • 🇮🇳India chaitanyadessai

    Replaced all the t() with $this->t()
    Please review.

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Also, the issue summary needs to be updated, since the issue has been rescoped.

  • 🇳🇿New Zealand quietone New Zealand

    I've been doing some more digging into the issues for fixing t() function. In this comment 📌 [META] Replace t() calls inside of classes Active in the parent issue xjm outlines the scope for these issues. That means, that this issue needs to split into two issues, one for the Controllers that have the trait and one for the Controllers that do not have the trait.

    There is also a sniff for this. To find the find that need to be changed I altered the DrupalPractice.Objects.GlobalFunction rule in phpcs.xml to the following.

      <rule ref="DrupalPractice.Objects.GlobalFunction">
        <include-pattern>*/Plugin/*</include-pattern>
        <include-pattern>*Controller*</include-pattern>
        <exclude-pattern>*/tests/*</exclude-pattern>
      </rule>

    The results show errors in 8 files, 5 of which extend from ControllerBase, which has the trait. Lets do those here. I have updated the IS with the files to be fixed here.

    The ones that do not have the trait are

    • core/modules/system/src/Controller/SystemInfoController.php
    • core/modules/file/src/Controller/FileWidgetAjaxController.php
    • core/modules/config/src/Controller/ConfigController.php

    And are to be done in a separate issue.

  • 🇳🇿New Zealand quietone New Zealand
  • Pipeline finished with Failed
    5 days ago
    Total: 371s
    #210715
  • Pipeline finished with Success
    5 days ago
    Total: 511s
    #210737
  • Status changed to Needs review 5 days ago
  • 🇳🇿New Zealand quietone New Zealand
  • 🇳🇿New Zealand quietone New Zealand
  • Status changed to RTBC 2 days ago
  • 🇺🇸United States smustgrave

    Hiding patches for clarity.

    Updated the summary to note that 2 of the findings aren't needed since those moved to contrib.

    Reviewing the current code changes in the MR and change seems good

Production build 0.69.0 2024