From 5032b1660c88f34459ce9c3972beeb78df19728b Mon Sep 17 00:00:00 2001
From: Arti <61371-arti_parmar@users.noreply.drupalcode.org>
Date: Tue, 27 Jun 2023 22:48:48 +0200
Subject: [PATCH] Issue #3368302 by arti_parmar:  t() calls should be avoided
 in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and
 $this->t() instead

---
 .../src/Plugin/Field/GeocodeFormatterBase.php          |  2 +-
 .../src/Plugin/Geocoder/Field/DefaultField.php         | 10 +++++-----
 .../Field/FieldFormatter/GeoPhpGeocodeFormatter.php    |  2 +-
 src/DumperPluginManager.php                            |  2 +-
 src/ProviderPluginManager.php                          |  2 +-
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/modules/geocoder_field/src/Plugin/Field/GeocodeFormatterBase.php b/modules/geocoder_field/src/Plugin/Field/GeocodeFormatterBase.php
index 7099e6f8..f3793479 100644
--- a/modules/geocoder_field/src/Plugin/Field/GeocodeFormatterBase.php
+++ b/modules/geocoder_field/src/Plugin/Field/GeocodeFormatterBase.php
@@ -211,7 +211,7 @@ abstract class GeocodeFormatterBase extends FormatterBase implements ContainerFa
       '#title' => 'Output format',
       '#default_value' => $this->getSetting('dumper'),
       '#options' => $this->dumperPluginManager->getPluginsAsOptions(),
-      '#description' => t('Set the output format of the value. Ex, for a geofield, the format must be set to WKT.'),
+      '#description' => $this->t('Set the output format of the value. Ex, for a geofield, the format must be set to WKT.'),
     ];
 
     return $element;
diff --git a/modules/geocoder_field/src/Plugin/Geocoder/Field/DefaultField.php b/modules/geocoder_field/src/Plugin/Geocoder/Field/DefaultField.php
index be4dd526..217b2341 100644
--- a/modules/geocoder_field/src/Plugin/Geocoder/Field/DefaultField.php
+++ b/modules/geocoder_field/src/Plugin/Geocoder/Field/DefaultField.php
@@ -165,7 +165,7 @@ class DefaultField extends PluginBase implements GeocoderFieldPluginInterface, C
    */
   public function getSettingsForm(FieldConfigInterface $field, array $form, FormStateInterface &$form_state) {
 
-    $geocoder_settings_link = $this->link->generate(t('Edit options in the Geocoder configuration page</span>'), Url::fromRoute('geocoder.settings', [], [
+    $geocoder_settings_link = $this->link->generate($this->t('Edit options in the Geocoder configuration page</span>'), Url::fromRoute('geocoder.settings', [], [
       'query' => [
         'destination' => Url::fromRoute('<current>')
           ->toString(),
@@ -174,7 +174,7 @@ class DefaultField extends PluginBase implements GeocoderFieldPluginInterface, C
 
     $element = [
       '#type' => 'details',
-      '#title' => t('Geocode'),
+      '#title' => $this->t('Geocode'),
       '#open' => TRUE,
     ];
 
@@ -334,10 +334,10 @@ class DefaultField extends PluginBase implements GeocoderFieldPluginInterface, C
     $element['geocode']['delta_handling'] = [
       '#type' => 'select',
       '#title' => $this->t('Multi-value input handling'),
-      '#description' => 'If the source field is a multi-value field, this is mapped 1-on-1 by default.
+      '#description' => $this->t('If the source field is a multi-value field, this is mapped 1-on-1 by default.
       That means that if you can add an unlimited amount of text fields, this also results in an
       unlimited amount of geocodes. However, if you have one field that contains multiple geocodes
-      (like a file) you can select single-to-multiple to extract all geocodes from the first field.',
+      (like a file) you can select single-to-multiple to extract all geocodes from the first field.'),
       '#default_value' => $field->getThirdPartySetting('geocoder_field', 'delta_handling', 'default'),
       '#options' => [
         'default' => $this->t('Match Multiples (default)'),
@@ -392,7 +392,7 @@ class DefaultField extends PluginBase implements GeocoderFieldPluginInterface, C
     $form_values = $form_state->getValues();
 
     if ($form_values['method'] !== 'none' && empty($form_values['providers'])) {
-      $form_state->setError($form['third_party_settings']['geocoder_field']['providers'], t('The selected Geocode operation needs at least one provider.'));
+      $form_state->setError($form['third_party_settings']['geocoder_field']['providers'], $this->t('The selected Geocode operation needs at least one provider.'));
     }
 
     // On Reverse Geocode the delta_handling should always be 'default'
diff --git a/modules/geocoder_geofield/src/Plugin/Field/FieldFormatter/GeoPhpGeocodeFormatter.php b/modules/geocoder_geofield/src/Plugin/Field/FieldFormatter/GeoPhpGeocodeFormatter.php
index ea7b3cf9..27fe7fa8 100644
--- a/modules/geocoder_geofield/src/Plugin/Field/FieldFormatter/GeoPhpGeocodeFormatter.php
+++ b/modules/geocoder_geofield/src/Plugin/Field/FieldFormatter/GeoPhpGeocodeFormatter.php
@@ -170,7 +170,7 @@ abstract class GeoPhpGeocodeFormatter extends FileGeocodeFormatter {
     $summary['intro'] = $this->pluginDefinition['description'];
     $summary += parent::settingsSummary();
     unset($summary['dumper']);
-    $summary['adapter'] = t('Output format: @format', [
+    $summary['adapter'] = $this->t('Output format: @format', [
       '@format' => !empty($adapter) ? $adapters[$adapter] : $this->t('Not set'),
     ]);
     return $summary;
diff --git a/src/DumperPluginManager.php b/src/DumperPluginManager.php
index d6896428..4b1aed3d 100644
--- a/src/DumperPluginManager.php
+++ b/src/DumperPluginManager.php
@@ -153,7 +153,7 @@ class DumperPluginManager extends GeocoderPluginManagerBase {
     if (\in_array($field_config->getType(), $this->maxLengthFieldTypes, TRUE) &&
       \strlen($dumper_result) > $field_config->getFieldStorageDefinition()->getSetting('max_length')) {
 
-      $incompatibility_warning_message = t("The '@field_name' field 'max length' property is not compatible with the chosen '@dumper' dumper.<br>Thus <b>be aware</b> <u>the dumper output result has been truncated to @max_length chars (max length)</u>.<br> You are advised to change the '@field_name' field definition or chose another compatible dumper.", [
+      $incompatibility_warning_message = $this->t("The '@field_name' field 'max length' property is not compatible with the chosen '@dumper' dumper.<br>Thus <b>be aware</b> <u>the dumper output result has been truncated to @max_length chars (max length)</u>.<br> You are advised to change the '@field_name' field definition or chose another compatible dumper.", [
         '@field_name' => $field_config->getLabel(),
         '@dumper' => $dumper->getPluginId(),
         '@max_length' => $field_config->getFieldStorageDefinition()->getSetting('max_length'),
diff --git a/src/ProviderPluginManager.php b/src/ProviderPluginManager.php
index 69632a4a..35e4d620 100644
--- a/src/ProviderPluginManager.php
+++ b/src/ProviderPluginManager.php
@@ -135,7 +135,7 @@ class ProviderPluginManager extends GeocoderPluginManagerBase {
    *   The plugins table list.
    */
   public function providersPluginsTableList(array $enabled_provider_ids): array {
-    $providers_link = $this->link->generate(t('Geocoder providers configuration page'), Url::fromRoute('entity.geocoder_provider.collection', [], [
+    $providers_link = $this->link->generate($this->t('Geocoder providers configuration page'), Url::fromRoute('entity.geocoder_provider.collection', [], [
       'attributes' => ['target' => '_blank'],
     ]));
 
-- 
GitLab