t() calls should be avoided in classes, use dependency injection and $this->t() instead in DateFormatFormBase.php , SiteInformationForm.php , SiteMaintenanceModeForm.php files.

Comments

Hardik_Patel_12 created an issue. See original summary.

hardik_patel_12’s picture

StatusFileSize
new7.92 KB

Kindly review a patch.

hardik_patel_12’s picture

Assigned: hardik_patel_12 » Unassigned
Status: Needs work » Needs review
longwave’s picture

Why not combine #3106261: t() calls should be avoided , use $this->t() instead in RegionalForm.php with this? This sort of thing feels like we should have one issue per module.

hardik_patel_12’s picture

Should i include all error in 1 issue , i thought it would be better to add different issue for different file.

pandaski’s picture

Second #4 it is good to do with this issue in a bulk to reduce the small piece of commits.

hardik_patel_12’s picture

Title: t() calls should be avoided , use $this->t() instead in multiple form files » t() calls should be avoided , use $this->t() instead in System module
hash6’s picture

Assigned: Unassigned » hash6
hash6’s picture

Thank @Hardik_Patel_12 for the patch, reviewed the patch successfully.

hash6’s picture

Assigned: hash6 » Unassigned
hash6’s picture

Status: Needs review » Reviewed & tested by the community
pandaski’s picture

Checked 120 changes, great job. thanks RTBC +1

andypost’s picture

Status: Reviewed & tested by the community » Needs work
andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new796 bytes
new44.18 KB

re-roll and fix usage in systemmanager, should be green now

Status: Needs review » Needs work

The last submitted patch, 15: 3106263-15.patch, failed testing. View results

andypost’s picture

Status: Needs work » Needs review

All 3 failed tests are passing locally, requeued

Status: Needs review » Needs work

The last submitted patch, 15: 3106263-15.patch, failed testing. View results

swatichouhan012’s picture

Assigned: Unassigned » swatichouhan012
Issue tags: +VbContribution2020

We will work on this in #VbContribution2020.

andypost’s picture

+++ b/core/modules/system/src/Controller/SystemInfoController.php
@@ -63,7 +63,7 @@ public function php() {
-      $output = t('The phpinfo() function has been disabled for security reasons. For more information, visit <a href=":phpinfo">Enabling and disabling phpinfo()</a> handbook page.', [':phpinfo' => 'https://www.drupal.org/node/243993']);
+      $output = $this->t('The phpinfo() function has been disabled for security reasons. For more information, visit <a href=":phpinfo">Enabling and disabling phpinfo()</a> handbook page.', [':phpinfo' => 'https://www.drupal.org/node/243993']);

this controller has no t() method

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new7.85 KB
new48.67 KB

Fixed remains, few methods are static so should use class directly (instead of trait)
Also fixed few CS issues (only for changed lines)

swatichouhan012’s picture

Assigned: swatichouhan012 » Unassigned
longwave’s picture

Status: Needs review » Reviewed & tested by the community

This looks good now.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Needs a reroll.

jungle’s picture

Assigned: Unassigned » jungle
jungle’s picture

StatusFileSize
new46.62 KB

No interdiff, rerolled form #21

hardik_patel_12’s picture

Status: Needs work » Needs review
jungle’s picture

Assigned: jungle » Unassigned
alexpott’s picture

alexpott’s picture

alexpott’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/system/src/Controller/SystemInfoController.php
    @@ -2,6 +2,7 @@
    +use Drupal\Core\StringTranslation\StringTranslationTrait;
     use Symfony\Component\DependencyInjection\ContainerInterface;
     use Symfony\Component\HttpFoundation\Response;
     use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
    @@ -12,6 +13,8 @@
    
    @@ -12,6 +13,8 @@
      */
     class SystemInfoController implements ContainerInjectionInterface {
     
    +  use StringTranslationTrait;
    +
    

    Should we extend from ControllerBase

  2. +++ b/core/modules/system/src/Form/SystemBrandingOffCanvasForm.php
    @@ -8,6 +8,7 @@
    +use Drupal\Core\StringTranslation\StringTranslationTrait;
    
    @@ -17,6 +18,8 @@
     class SystemBrandingOffCanvasForm extends PluginFormBase implements ContainerInjectionInterface {
     
    +  use StringTranslationTrait;
    +
    

    This poses the question whether PluginFormBase should use the trait. I think it should because it is about building forms. But this needs a separate issue as it should also change \Drupal\system\Form\SystemMenuOffCanvasForm - and should discuss which traits to use.

  3. +++ b/core/modules/system/src/SystemManager.php
    @@ -164,7 +165,7 @@ public function getBlockContents() {
           $output = [
    -        '#markup' => t('You do not have any administrative items.'),
    +        '#markup' => new TranslatableMarkup('You do not have any administrative items.'),
           ];
    

    This is a service and so we should inject the string translation service. But also this really calls into question the relationship between SystemController and SystemManager - and where different responsibilities lie.

jungle’s picture

Assigned: Unassigned » jungle

Working on comments form #31

jungle’s picture

Assigned: jungle » Unassigned
Status: Needs work » Needs review
StatusFileSize
new48.76 KB
new3.74 KB

Changes made to 1 and 3, ignored 2 according to comment #31

xjm’s picture

Status: Needs review » Closed (duplicate)

Thanks for working on this.

In general, issues should not be scoped by file or module; instead, they should be scoped by making the exact specific change across as much of core as possible. Reference: https://www.drupal.org/core/scope#files

In particular, t() calls should be replaced based on whether the translation service is already available in the class, and more specifically, based on which base class it extends. (So, for example, one issue for form builders, one for controllers, one for list builders, and then splitting that up further only if the resulting patch is too large to be manageable.) We also need to decide the approach before we proceed with child issues. See #3113904: [META] Replace t() calls inside of classes for more discussion. So, closing as a duplicate of the parent issue in #3113904: [META] Replace t() calls inside of classes .

Thanks!