From e191e497a8426fc7b381f66a796be7f51d51f16e Mon Sep 17 00:00:00 2001
From: Liam Morland <lkmorlan@uwaterloo.ca>
Date: Thu, 24 Mar 2022 11:22:54 -0400
Subject: [PATCH] Issue #3271310 by chakkche, Liam Morland, victoria-marina:
 Replace t() with StringTranslationTrait

---
 src/FillPdfAccessController.php                   | 4 +++-
 src/FillPdfFormListBuilder.php                    | 6 +++---
 src/Form/FillPdfFormForm.php                      | 2 +-
 src/Form/FillPdfSettingsForm.php                  | 2 +-
 tests/src/Functional/FillPdfTestBase.php          | 2 ++
 tests/src/Functional/PdfWebformPopulationTest.php | 2 +-
 6 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/FillPdfAccessController.php b/src/FillPdfAccessController.php
index 2b39752..a5ff1bd 100644
--- a/src/FillPdfAccessController.php
+++ b/src/FillPdfAccessController.php
@@ -4,6 +4,7 @@ namespace Drupal\fillpdf;
 
 use Drupal\Core\Access\AccessResult;
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpFoundation\RequestStack;
 use Drupal\Core\Logger\LoggerChannelTrait;
@@ -17,6 +18,7 @@ class FillPdfAccessController implements ContainerInjectionInterface {
 
   use MessengerTrait;
   use LoggerChannelTrait;
+  use StringTranslationTrait;
 
   /**
    * The FillPDF access helper.
@@ -107,7 +109,7 @@ class FillPdfAccessController implements ContainerInjectionInterface {
     catch (\InvalidArgumentException $exception) {
       $message = $exception->getMessage();
       $is_admin = $this->currentUser->hasPermission('administer pdfs');
-      $this->messenger()->addError($is_admin ? $message : t('An error occurred. Please notify the administrator.'));
+      $this->messenger()->addError($is_admin ? $message : $this->t('An error occurred. Please notify the administrator.'));
       $this->getLogger('fillpdf')->error($message);
       return AccessResult::forbidden();
     }
diff --git a/src/FillPdfFormListBuilder.php b/src/FillPdfFormListBuilder.php
index 4cbb6c7..324343a 100644
--- a/src/FillPdfFormListBuilder.php
+++ b/src/FillPdfFormListBuilder.php
@@ -24,17 +24,17 @@ class FillPdfFormListBuilder extends EntityListBuilder {
   public function getDefaultOperations(EntityInterface $entity) {
 
     $duplicate = [
-      'title' => t('Duplicate'),
+      'title' => $this->t('Duplicate'),
       'weight' => 10,
       'url' => $this->ensureDestination($entity->toUrl('duplicate-form')),
     ];
     $export = [
-      'title' => t('Export configuration'),
+      'title' => $this->t('Export configuration'),
       'weight' => 20,
       'url' => $this->ensureDestination($entity->toUrl('export-form')),
     ];
     $import = [
-      'title' => t('Import configuration'),
+      'title' => $this->t('Import configuration'),
       'weight' => 30,
       'url' => $this->ensureDestination($entity->toUrl('import-form')),
     ];
diff --git a/src/Form/FillPdfFormForm.php b/src/Form/FillPdfFormForm.php
index e502ab5..267e114 100644
--- a/src/Form/FillPdfFormForm.php
+++ b/src/Form/FillPdfFormForm.php
@@ -373,7 +373,7 @@ class FillPdfFormForm extends ContentEntityForm {
     $form['additional_settings']['security'] = [
       '#name' => 'security',
       '#type' => 'details',
-      '#title' => t('PDF Security (currently only works with pdftk)'),
+      '#title' => $this->t('PDF Security (currently only works with pdftk)'),
       '#weight' => 100,
       '#open' => $fillpdf_form && (
           !empty($fillpdf_form->pdftk_encryption->value) ||
diff --git a/src/Form/FillPdfSettingsForm.php b/src/Form/FillPdfSettingsForm.php
index beb44a8..69f6703 100644
--- a/src/Form/FillPdfSettingsForm.php
+++ b/src/Form/FillPdfSettingsForm.php
@@ -198,7 +198,7 @@ class FillPdfSettingsForm extends ConfigFormBase {
       '#default_value' => array_key_exists($template_scheme, $template_scheme_options) ? $template_scheme : $file_default_scheme,
       '#options' => $template_scheme_options,
       '#description' => $this->t('This setting is used as the storage for uploaded templates; note that the use of %public is more efficient, but does not provide any access control.<br />Changing this setting will require you to migrate associated files and data yourself and is not recommended after you have uploaded a template.', [
-        '%public' => t('Public files'),
+        '%public' => $this->t('Public files'),
       ]),
     ];
 
diff --git a/tests/src/Functional/FillPdfTestBase.php b/tests/src/Functional/FillPdfTestBase.php
index f70081e..cfff89f 100644
--- a/tests/src/Functional/FillPdfTestBase.php
+++ b/tests/src/Functional/FillPdfTestBase.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\fillpdf\Functional;
 
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Drupal\Tests\file\Functional\FileFieldTestBase;
 use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait;
 use Drupal\Tests\fillpdf\Traits\TestImageFieldTrait;
@@ -12,6 +13,7 @@ use Drupal\user\Entity\Role;
  */
 abstract class FillPdfTestBase extends FileFieldTestBase {
 
+  use StringTranslationTrait;
   use TestFillPdfTrait;
   use TestImageFieldTrait;
 
diff --git a/tests/src/Functional/PdfWebformPopulationTest.php b/tests/src/Functional/PdfWebformPopulationTest.php
index 616fb8a..7750048 100644
--- a/tests/src/Functional/PdfWebformPopulationTest.php
+++ b/tests/src/Functional/PdfWebformPopulationTest.php
@@ -59,7 +59,7 @@ class PdfWebformPopulationTest extends FillPdfTestBase {
     // Create a test submission for our Contact form.
     $contact_form = Webform::load('fillpdf_contact');
     $contact_form_test_route = Url::fromRoute('entity.webform.test_form', ['webform' => $contact_form->id()]);
-    $this->drupalPostForm($contact_form_test_route, [], t('Send message'));
+    $this->drupalPostForm($contact_form_test_route, [], $this->t('Send message'));
 
     // Load the submission.
     $this->testSubmission = WebformSubmission::load($this->getLastSubmissionId($contact_form));
-- 
GitLab