From 95579a7044e628ddf6b7b8efcf8d9b129580461a Mon Sep 17 00:00:00 2001 From: Lee Rowlands <lee.rowlands@previousnext.com.au> Date: Fri, 3 Jan 2025 11:15:51 +1000 Subject: [PATCH] Issue #3464591 by quietone, longwave: Fix DrupalPractice.Objects.GlobalFunction in test Forms --- .../src/Form/NestedEntityTestForm.php | 4 +- .../tests/file_test/src/Form/FileTestForm.php | 14 ++++--- ...ingsTrayFormAnnotationIsClassBlockForm.php | 5 ++- .../batch_test/src/Form/BatchTestMockForm.php | 4 +- .../src/Form/DatabaseTestForm.php | 8 ++-- .../src/Form/FormTestCheckboxForm.php | 2 +- .../Form/FormTestCheckboxTypeJugglingForm.php | 2 +- .../src/Form/FormTestCheckboxesZeroForm.php | 6 +-- .../src/Form/FormTestClickedButtonForm.php | 2 +- .../src/Form/FormTestDisabledElementsForm.php | 2 +- .../src/Form/FormTestEmptySelectForm.php | 2 +- ...rmTestFormStateValuesCleanAdvancedForm.php | 6 +-- .../Form/FormTestFormStateValuesCleanForm.php | 8 ++-- .../src/Form/FormTestInputForgeryForm.php | 4 +- .../form_test/src/Form/FormTestLabelForm.php | 38 +++++++++---------- .../src/Form/FormTestLanguageSelectForm.php | 10 ++--- .../FormTestLimitValidationErrorsForm.php | 10 ++--- .../src/Form/FormTestProgrammaticForm.php | 4 +- .../FormTestRebuildPreserveValuesForm.php | 12 +++--- .../src/Form/FormTestRedirectForm.php | 8 ++-- .../src/Form/FormTestStatePersistForm.php | 2 +- .../src/Form/FormTestTableSelectFormBase.php | 4 +- .../src/Form/FormTestValidateRequiredForm.php | 6 +-- .../Form/FormTestVerticalTabsAccessForm.php | 36 +++++++++--------- .../src/Form/FormTestVerticalTabsForm.php | 4 +- .../src/Form/IncorrectConfigTargetForm.php | 2 +- .../src/Form/TreeConfigTargetForm.php | 6 +-- .../src/Form/ViewsTestDataErrorForm.php | 7 +++- core/phpcs.xml.dist | 1 + 29 files changed, 114 insertions(+), 105 deletions(-) diff --git a/core/modules/field/tests/modules/field_test/src/Form/NestedEntityTestForm.php b/core/modules/field/tests/modules/field_test/src/Form/NestedEntityTestForm.php index 6e63feee306b..ccd88b412d2c 100644 --- a/core/modules/field/tests/modules/field_test/src/Form/NestedEntityTestForm.php +++ b/core/modules/field/tests/modules/field_test/src/Form/NestedEntityTestForm.php @@ -40,7 +40,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ?EntityIn $form_state->set('form_display_2', $form_display_2); $form['entity_2'] = [ '#type' => 'details', - '#title' => t('Second entity'), + '#title' => $this->t('Second entity'), '#tree' => TRUE, '#parents' => ['entity_2'], '#weight' => 50, @@ -60,7 +60,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ?EntityIn $form['save'] = [ '#type' => 'submit', - '#value' => t('Save'), + '#value' => $this->t('Save'), '#weight' => 100, ]; diff --git a/core/modules/file/tests/file_test/src/Form/FileTestForm.php b/core/modules/file/tests/file_test/src/Form/FileTestForm.php index f7164474bebc..d021a538f44c 100644 --- a/core/modules/file/tests/file_test/src/Form/FileTestForm.php +++ b/core/modules/file/tests/file_test/src/Form/FileTestForm.php @@ -8,12 +8,14 @@ use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\FormInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * File test form class. */ class FileTestForm implements FormInterface { use FileTestFormTrait; + use StringTranslationTrait; /** * {@inheritdoc} @@ -31,7 +33,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['file_test_upload'] = [ '#type' => 'file', - '#title' => t('Upload a file'), + '#title' => $this->t('Upload a file'), ]; return $form; @@ -83,13 +85,13 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $file = file_save_upload('file_test_upload', $validators, $destination, 0, static::fileExistsFromName($form_state->getValue('file_test_replace'))); if ($file) { $form_state->setValue('file_test_upload', $file); - \Drupal::messenger()->addStatus(t('File @filepath was uploaded.', ['@filepath' => $file->getFileUri()])); - \Drupal::messenger()->addStatus(t('File name is @filename.', ['@filename' => $file->getFilename()])); - \Drupal::messenger()->addStatus(t('File MIME type is @mimetype.', ['@mimetype' => $file->getMimeType()])); - \Drupal::messenger()->addStatus(t('You WIN!')); + \Drupal::messenger()->addStatus($this->t('File @filepath was uploaded.', ['@filepath' => $file->getFileUri()])); + \Drupal::messenger()->addStatus($this->t('File name is @filename.', ['@filename' => $file->getFilename()])); + \Drupal::messenger()->addStatus($this->t('File MIME type is @mimetype.', ['@mimetype' => $file->getMimeType()])); + \Drupal::messenger()->addStatus($this->t('You WIN!')); } elseif ($file === FALSE) { - \Drupal::messenger()->addError(t('Epic upload FAIL!')); + \Drupal::messenger()->addError($this->t('Epic upload FAIL!')); } } diff --git a/core/modules/settings_tray/tests/modules/settings_tray_test/src/Form/SettingsTrayFormAnnotationIsClassBlockForm.php b/core/modules/settings_tray/tests/modules/settings_tray_test/src/Form/SettingsTrayFormAnnotationIsClassBlockForm.php index 1d18f6acf52c..e2992dad6218 100644 --- a/core/modules/settings_tray/tests/modules/settings_tray_test/src/Form/SettingsTrayFormAnnotationIsClassBlockForm.php +++ b/core/modules/settings_tray/tests/modules/settings_tray_test/src/Form/SettingsTrayFormAnnotationIsClassBlockForm.php @@ -6,12 +6,15 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginFormBase; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * @see \Drupal\settings_tray_test\Plugin\Block\SettingsTrayFormAnnotationIsClassBlock */ class SettingsTrayFormAnnotationIsClassBlockForm extends PluginFormBase { + use StringTranslationTrait; + /** * The block plugin. * @@ -27,7 +30,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form['some_setting'] = [ '#type' => 'select', - '#title' => t('Some setting'), + '#title' => $this->t('Some setting'), '#options' => [ 'a' => 'A', 'b' => 'B', diff --git a/core/modules/system/tests/modules/batch_test/src/Form/BatchTestMockForm.php b/core/modules/system/tests/modules/batch_test/src/Form/BatchTestMockForm.php index 52f353833b06..481ecc127c6a 100644 --- a/core/modules/system/tests/modules/batch_test/src/Form/BatchTestMockForm.php +++ b/core/modules/system/tests/modules/batch_test/src/Form/BatchTestMockForm.php @@ -26,12 +26,12 @@ public function getFormId() { */ public function buildForm(array $form, FormStateInterface $form_state) { $form['test_value'] = [ - '#title' => t('Test value'), + '#title' => $this->t('Test value'), '#type' => 'textfield', ]; $form['submit'] = [ '#type' => 'submit', - '#value' => t('Submit'), + '#value' => $this->t('Submit'), ]; return $form; diff --git a/core/modules/system/tests/modules/database_test/src/Form/DatabaseTestForm.php b/core/modules/system/tests/modules/database_test/src/Form/DatabaseTestForm.php index 9b430bbb66a3..4e1d86bf05a0 100644 --- a/core/modules/system/tests/modules/database_test/src/Form/DatabaseTestForm.php +++ b/core/modules/system/tests/modules/database_test/src/Form/DatabaseTestForm.php @@ -30,8 +30,8 @@ public function getFormId() { */ public function buildForm(array $form, FormStateInterface $form_state) { $header = [ - 'username' => ['data' => t('Username'), 'field' => 'u.name'], - 'status' => ['data' => t('Status'), 'field' => 'u.status'], + 'username' => ['data' => $this->t('Username'), 'field' => 'u.name'], + 'status' => ['data' => $this->t('Status'), 'field' => 'u.status'], ]; $query = Database::getConnection()->select('users_field_data', 'u'); @@ -59,7 +59,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $options[$account->id()] = [ 'title' => ['data' => ['#title' => $account->getAccountName()]], 'username' => $account->getAccountName(), - 'status' => $account->isActive() ? t('active') : t('blocked'), + 'status' => $account->isActive() ? $this->t('active') : $this->t('blocked'), ]; } @@ -67,7 +67,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'tableselect', '#header' => $header, '#options' => $options, - '#empty' => t('No people available.'), + '#empty' => $this->t('No people available.'), ]; return $form; diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxForm.php index d3d50e9b637c..7433b5736064 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxForm.php @@ -84,7 +84,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['submit'] = [ '#type' => 'submit', - '#value' => t('Submit'), + '#value' => $this->t('Submit'), ]; return $form; diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxTypeJugglingForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxTypeJugglingForm.php index 6b1e642ec102..7ad0620124b2 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxTypeJugglingForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxTypeJugglingForm.php @@ -26,7 +26,7 @@ public function getFormId() { */ public function buildForm(array $form, FormStateInterface $form_state, $default_value = NULL, $return_value = NULL) { $form['checkbox'] = [ - '#title' => t('Checkbox'), + '#title' => $this->t('Checkbox'), '#type' => 'checkbox', '#return_value' => $return_value, '#default_value' => $default_value, diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxesZeroForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxesZeroForm.php index 780c7ea7f06e..d40097475e62 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxesZeroForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxesZeroForm.php @@ -28,18 +28,18 @@ public function getFormId() { public function buildForm(array $form, FormStateInterface $form_state, $json = TRUE) { $form_state->set('json', $json); $form['checkbox_off'] = [ - '#title' => t('Checkbox off'), + '#title' => $this->t('Checkbox off'), '#type' => 'checkboxes', '#options' => ['foo', 'bar', 'baz'], ]; $form['checkbox_zero_default'] = [ - '#title' => t('Zero default'), + '#title' => $this->t('Zero default'), '#type' => 'checkboxes', '#options' => ['foo', 'bar', 'baz'], '#default_value' => [0], ]; $form['checkbox_string_zero_default'] = [ - '#title' => t('Zero default (string)'), + '#title' => $this->t('Zero default (string)'), '#type' => 'checkboxes', '#options' => ['foo', 'bar', 'baz'], '#default_value' => ['0'], diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestClickedButtonForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestClickedButtonForm.php index 5a23cc5aac86..95338fa24036 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestClickedButtonForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestClickedButtonForm.php @@ -88,7 +88,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $first = */ public function validateForm(array &$form, FormStateInterface $form_state) { if ($triggering_element = $form_state->getTriggeringElement()) { - $this->messenger()->addStatus(t('The clicked button is %name.', ['%name' => $triggering_element['#name']])); + $this->messenger()->addStatus($this->t('The clicked button is %name.', ['%name' => $triggering_element['#name']])); } else { $this->messenger()->addStatus('There is no clicked button.'); diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestDisabledElementsForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestDisabledElementsForm.php index 2ada206e40f5..30317f64209b 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestDisabledElementsForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestDisabledElementsForm.php @@ -255,7 +255,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['submit'] = [ '#type' => 'submit', - '#value' => t('Submit'), + '#value' => $this->t('Submit'), ]; return $form; diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestEmptySelectForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestEmptySelectForm.php index debf2772a574..8eb220c5b55f 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestEmptySelectForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestEmptySelectForm.php @@ -27,7 +27,7 @@ public function getFormId() { public function buildForm(array $form, FormStateInterface $form_state) { $form['empty_select'] = [ '#type' => 'select', - '#title' => t('Empty Select'), + '#title' => $this->t('Empty Select'), '#multiple' => FALSE, '#options' => NULL, ]; diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestFormStateValuesCleanAdvancedForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestFormStateValuesCleanAdvancedForm.php index 0b579de00874..156b84f6438d 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestFormStateValuesCleanAdvancedForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestFormStateValuesCleanAdvancedForm.php @@ -28,13 +28,13 @@ public function buildForm(array $form, FormStateInterface $form_state) { // Build an example form containing a managed file and a submit form element. $form['image'] = [ '#type' => 'managed_file', - '#title' => t('Image'), + '#title' => $this->t('Image'), '#upload_location' => 'public://', '#default_value' => 0, ]; $form['submit'] = [ '#type' => 'submit', - '#value' => t('Submit'), + '#value' => $this->t('Submit'), ]; return $form; } @@ -44,7 +44,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { */ public function submitForm(array &$form, FormStateInterface $form_state) { $form_state->cleanValues(); - print t('You WIN!'); + print $this->t('You WIN!'); exit; } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestFormStateValuesCleanForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestFormStateValuesCleanForm.php index 8907153aac62..cca51e49da09 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestFormStateValuesCleanForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestFormStateValuesCleanForm.php @@ -29,11 +29,11 @@ public function buildForm(array $form, FormStateInterface $form_state) { // Build an example form containing multiple submit and button elements; not // only on the top-level. $form = ['#tree' => TRUE]; - $form['foo'] = ['#type' => 'submit', '#value' => t('Submit')]; - $form['bar'] = ['#type' => 'submit', '#value' => t('Submit')]; + $form['foo'] = ['#type' => 'submit', '#value' => $this->t('Submit')]; + $form['bar'] = ['#type' => 'submit', '#value' => $this->t('Submit')]; $form['beer'] = ['#type' => 'value', '#value' => 1000]; - $form['baz']['foo'] = ['#type' => 'button', '#value' => t('Submit')]; - $form['baz']['baz'] = ['#type' => 'submit', '#value' => t('Submit')]; + $form['baz']['foo'] = ['#type' => 'button', '#value' => $this->t('Submit')]; + $form['baz']['baz'] = ['#type' => 'submit', '#value' => $this->t('Submit')]; $form['baz']['beer'] = ['#type' => 'value', '#value' => 2000]; // Add an arbitrary element and manually set it to be cleaned. diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestInputForgeryForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestInputForgeryForm.php index 21f229a83470..b32bf75c88bf 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestInputForgeryForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestInputForgeryForm.php @@ -30,7 +30,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { // For testing that a user can't submit a value not matching one of the // allowed options. $form['checkboxes'] = [ - '#title' => t('Checkboxes'), + '#title' => $this->t('Checkboxes'), '#type' => 'checkboxes', '#options' => [ 'one' => 'One', @@ -39,7 +39,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; $form['submit'] = [ '#type' => 'submit', - '#value' => t('Submit'), + '#value' => $this->t('Submit'), ]; $form['#post_render'][] = [static::class, 'postRender']; diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestLabelForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestLabelForm.php index b238f5a02547..bbbf97247da2 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestLabelForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestLabelForm.php @@ -61,34 +61,34 @@ public function getFormId() { public function buildForm(array $form, FormStateInterface $form_state) { $form['form_checkboxes_test'] = [ '#type' => 'checkboxes', - '#title' => t('Checkboxes test'), + '#title' => $this->t('Checkboxes test'), '#options' => [ - 'first-checkbox' => t('First checkbox'), - 'second-checkbox' => t('Second checkbox'), - 'third-checkbox' => t('Third checkbox'), - '0' => t('0'), + 'first-checkbox' => $this->t('First checkbox'), + 'second-checkbox' => $this->t('Second checkbox'), + 'third-checkbox' => $this->t('Third checkbox'), + '0' => $this->t('0'), ], ]; $form['form_radios_test'] = [ '#type' => 'radios', - '#title' => t('Radios test'), + '#title' => $this->t('Radios test'), '#options' => [ - 'first-radio' => t('First radio'), - 'second-radio' => t('Second radio'), - 'third-radio' => t('Third radio'), - '0' => t('0'), + 'first-radio' => $this->t('First radio'), + 'second-radio' => $this->t('Second radio'), + 'third-radio' => $this->t('Third radio'), + '0' => $this->t('0'), ], // Test #field_prefix and #field_suffix placement. - '#field_prefix' => '<span id="form-test-radios-field-prefix">' . t('Radios #field_prefix element') . '</span>', - '#field_suffix' => '<span id="form-test-radios-field-suffix">' . t('Radios #field_suffix element') . '</span>', + '#field_prefix' => '<span id="form-test-radios-field-prefix">' . $this->t('Radios #field_prefix element') . '</span>', + '#field_suffix' => '<span id="form-test-radios-field-suffix">' . $this->t('Radios #field_suffix element') . '</span>', ]; $form['form_checkbox_test'] = [ '#type' => 'checkbox', - '#title' => t('Checkbox test'), + '#title' => $this->t('Checkbox test'), ]; $form['form_textfield_test_title_and_required'] = [ '#type' => 'textfield', - '#title' => t('Textfield test for required with title'), + '#title' => $this->t('Textfield test for required with title'), '#required' => TRUE, ]; $form['form_textfield_test_no_title_required'] = [ @@ -100,20 +100,20 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; $form['form_textfield_test_title'] = [ '#type' => 'textfield', - '#title' => t('Textfield test for title only'), + '#title' => $this->t('Textfield test for title only'), // Not required. // Test #prefix and #suffix placement. - '#prefix' => '<div id="form-test-textfield-title-prefix">' . t('Textfield #prefix element') . '</div>', - '#suffix' => '<div id="form-test-textfield-title-suffix">' . t('Textfield #suffix element') . '</div>', + '#prefix' => '<div id="form-test-textfield-title-prefix">' . $this->t('Textfield #prefix element') . '</div>', + '#suffix' => '<div id="form-test-textfield-title-suffix">' . $this->t('Textfield #suffix element') . '</div>', ]; $form['form_textfield_test_title_after'] = [ '#type' => 'textfield', - '#title' => t('Textfield test for title after element'), + '#title' => $this->t('Textfield test for title after element'), '#title_display' => 'after', ]; $form['form_textfield_test_title_invisible'] = [ '#type' => 'textfield', - '#title' => t('Textfield test for invisible title'), + '#title' => $this->t('Textfield test for invisible title'), '#title_display' => 'invisible', ]; // Textfield test for title set not to display. diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestLanguageSelectForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestLanguageSelectForm.php index b0df340b2038..9dc7e75be449 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestLanguageSelectForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestLanguageSelectForm.php @@ -28,30 +28,30 @@ public function getFormId() { */ public function buildForm(array $form, FormStateInterface $form_state) { $form['languages_all'] = [ - '#title' => t('Languages: All'), + '#title' => $this->t('Languages: All'), '#type' => 'language_select', '#languages' => LanguageInterface::STATE_ALL, '#default_value' => 'xx', ]; $form['languages_configurable'] = [ - '#title' => t('Languages: Configurable'), + '#title' => $this->t('Languages: Configurable'), '#type' => 'language_select', '#languages' => LanguageInterface::STATE_CONFIGURABLE, '#default_value' => 'en', ]; $form['languages_locked'] = [ - '#title' => t('Languages: Locked'), + '#title' => $this->t('Languages: Locked'), '#type' => 'language_select', '#languages' => LanguageInterface::STATE_LOCKED, ]; $form['languages_config_and_locked'] = [ - '#title' => t('Languages: Configurable and locked'), + '#title' => $this->t('Languages: Configurable and locked'), '#type' => 'language_select', '#languages' => LanguageInterface::STATE_CONFIGURABLE | LanguageInterface::STATE_LOCKED, '#default_value' => 'dummy_value', ]; $form['language_custom_options'] = [ - '#title' => t('Languages: Custom'), + '#title' => $this->t('Languages: Custom'), '#type' => 'language_select', '#languages' => LanguageInterface::STATE_CONFIGURABLE | LanguageInterface::STATE_LOCKED, '#options' => ['opt1' => 'First option', 'opt2' => 'Second option', 'opt3' => 'Third option'], diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestLimitValidationErrorsForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestLimitValidationErrorsForm.php index ce7bec14dc3d..b554d3838220 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestLimitValidationErrorsForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestLimitValidationErrorsForm.php @@ -63,23 +63,23 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'submit', '#limit_validation_errors' => [['test']], '#submit' => ['::partialSubmitForm'], - '#value' => t('Partial validate'), + '#value' => $this->t('Partial validate'), ]; $form['actions']['partial_numeric_index'] = [ '#type' => 'submit', '#limit_validation_errors' => [['test_numeric_index', 0]], '#submit' => ['::partialSubmitForm'], - '#value' => t('Partial validate (numeric index)'), + '#value' => $this->t('Partial validate (numeric index)'), ]; $form['actions']['substring'] = [ '#type' => 'submit', '#limit_validation_errors' => [['test_substring', 'foo']], '#submit' => ['::partialSubmitForm'], - '#value' => t('Partial validate (substring)'), + '#value' => $this->t('Partial validate (substring)'), ]; $form['actions']['full'] = [ '#type' => 'submit', - '#value' => t('Full validate'), + '#value' => $this->t('Full validate'), ]; return $form; } @@ -89,7 +89,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { */ public function elementValidateLimitValidationErrors($element, FormStateInterface $form_state) { if ($element['#value'] == 'invalid') { - $form_state->setError($element, t('@label element is invalid', ['@label' => $element['#title']])); + $form_state->setError($element, $this->t('@label element is invalid', ['@label' => $element['#title']])); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestProgrammaticForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestProgrammaticForm.php index 577d29b29129..d19a6646e28b 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestProgrammaticForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestProgrammaticForm.php @@ -31,7 +31,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; $form['checkboxes'] = [ - '#title' => t('Checkboxes'), + '#title' => $this->t('Checkboxes'), '#type' => 'checkboxes', '#options' => [ 1 => 'First checkbox', @@ -90,7 +90,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { */ public function validateForm(array &$form, FormStateInterface $form_state) { if ($form_state->isValueEmpty('textfield')) { - $form_state->setErrorByName('textfield', t('Textfield is required.')); + $form_state->setErrorByName('textfield', $this->t('Textfield is required.')); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestRebuildPreserveValuesForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestRebuildPreserveValuesForm.php index 82b50ddb1fc8..ebab3c5a76a4 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestRebuildPreserveValuesForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestRebuildPreserveValuesForm.php @@ -30,17 +30,17 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form = [ 'checkbox_1_default_off' => [ '#type' => 'checkbox', - '#title' => t('This checkbox defaults to unchecked'), + '#title' => $this->t('This checkbox defaults to unchecked'), '#default_value' => FALSE, ], 'checkbox_1_default_on' => [ '#type' => 'checkbox', - '#title' => t('This checkbox defaults to checked'), + '#title' => $this->t('This checkbox defaults to checked'), '#default_value' => TRUE, ], 'text_1' => [ '#type' => 'textfield', - '#title' => t('This textfield has a non-empty default value.'), + '#title' => $this->t('This textfield has a non-empty default value.'), '#default_value' => 'DEFAULT 1', ], ]; @@ -59,17 +59,17 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form += [ 'checkbox_2_default_off' => [ '#type' => 'checkbox', - '#title' => t('This checkbox defaults to unchecked'), + '#title' => $this->t('This checkbox defaults to unchecked'), '#default_value' => FALSE, ], 'checkbox_2_default_on' => [ '#type' => 'checkbox', - '#title' => t('This checkbox defaults to checked'), + '#title' => $this->t('This checkbox defaults to checked'), '#default_value' => TRUE, ], 'text_2' => [ '#type' => 'textfield', - '#title' => t('This textfield has a non-empty default value.'), + '#title' => $this->t('This textfield has a non-empty default value.'), '#default_value' => 'DEFAULT 2', ], ]; diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestRedirectForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestRedirectForm.php index dd048fd7b393..baf646acbbd9 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestRedirectForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestRedirectForm.php @@ -28,11 +28,11 @@ public function getFormId() { public function buildForm(array $form, FormStateInterface $form_state) { $form['redirection'] = [ '#type' => 'checkbox', - '#title' => t('Use redirection'), + '#title' => $this->t('Use redirection'), ]; $form['destination'] = [ '#type' => 'textfield', - '#title' => t('Redirect destination'), + '#title' => $this->t('Redirect destination'), '#states' => [ 'visible' => [ ':input[name="redirection"]' => ['checked' => TRUE], @@ -41,7 +41,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; $form['ignore_destination'] = [ '#type' => 'checkbox', - '#title' => t('Ignore destination query parameter'), + '#title' => $this->t('Ignore destination query parameter'), '#states' => [ 'visible' => [ ':input[name="redirection"]' => ['checked' => TRUE], @@ -50,7 +50,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; $form['submit'] = [ '#type' => 'submit', - '#value' => t('Submit'), + '#value' => $this->t('Submit'), ]; return $form; diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestStatePersistForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestStatePersistForm.php index f33b0e67e3bf..50314d017ee3 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestStatePersistForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestStatePersistForm.php @@ -35,7 +35,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['submit'] = [ '#type' => 'submit', - '#value' => t('Submit'), + '#value' => $this->t('Submit'), ]; return $form; } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectFormBase.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectFormBase.php index df570aa35c97..1420e4447439 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectFormBase.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectFormBase.php @@ -40,7 +40,7 @@ public function tableselectFormBuilder($form, FormStateInterface $form_state, $e '#header' => $header, '#options' => $options, '#multiple' => FALSE, - '#empty' => t('Empty text.'), + '#empty' => $this->t('Empty text.'), '#ajax' => [ 'callback' => '::tableselectAjaxCallback', 'wrapper' => 'tableselect-wrapper', @@ -49,7 +49,7 @@ public function tableselectFormBuilder($form, FormStateInterface $form_state, $e $form['submit'] = [ '#type' => 'submit', - '#value' => t('Submit'), + '#value' => $this->t('Submit'), ]; return $form; diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestValidateRequiredForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestValidateRequiredForm.php index 2ba6935f2f5b..cb669372fa91 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestValidateRequiredForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestValidateRequiredForm.php @@ -32,14 +32,14 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'textfield', '#title' => 'Name', '#required' => TRUE, - '#required_error' => t('Enter a name.'), + '#required_error' => $this->t('Enter a name.'), ]; $form['checkboxes'] = [ '#type' => 'checkboxes', '#title' => 'Checkboxes', '#options' => $options, '#required' => TRUE, - '#form_test_required_error' => t('Choose at least one option.'), + '#form_test_required_error' => $this->t('Choose at least one option.'), '#element_validate' => $validate, ]; $form['select'] = [ @@ -47,7 +47,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#title' => 'Select', '#options' => $options, '#required' => TRUE, - '#form_test_required_error' => t('Select something.'), + '#form_test_required_error' => $this->t('Select something.'), '#element_validate' => $validate, ]; $form['radios'] = [ diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabsAccessForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabsAccessForm.php index 5ae05f91c896..bad0674aa28a 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabsAccessForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabsAccessForm.php @@ -30,34 +30,34 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; $form['tab1'] = [ '#type' => 'fieldset', - '#title' => t('Tab 1'), + '#title' => $this->t('Tab 1'), '#collapsible' => TRUE, '#group' => 'vertical_tabs1', ]; $form['tab1']['field1'] = [ - '#title' => t('Field 1'), + '#title' => $this->t('Field 1'), '#type' => 'checkbox', '#default_value' => TRUE, ]; $form['tab2'] = [ '#type' => 'fieldset', - '#title' => t('Tab 2'), + '#title' => $this->t('Tab 2'), '#collapsible' => TRUE, '#group' => 'vertical_tabs1', ]; $form['tab2']['field2'] = [ - '#title' => t('Field 2'), + '#title' => $this->t('Field 2'), '#type' => 'textfield', '#default_value' => 'field2', ]; $form['fieldset1'] = [ '#type' => 'fieldset', - '#title' => t('Fieldset'), + '#title' => $this->t('Fieldset'), ]; $form['fieldset1']['field3'] = [ '#type' => 'checkbox', - '#title' => t('Field 3'), + '#title' => $this->t('Field 3'), '#default_value' => TRUE, ]; @@ -66,7 +66,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; $form['container']['field4'] = [ '#type' => 'checkbox', - '#title' => t('Field 4'), + '#title' => $this->t('Field 4'), '#default_value' => TRUE, ]; $form['container']['sub_container'] = [ @@ -74,7 +74,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; $form['container']['sub_container']['field5'] = [ '#type' => 'checkbox', - '#title' => t('Field 5'), + '#title' => $this->t('Field 5'), '#default_value' => TRUE, ]; @@ -83,12 +83,12 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; $form['tab3'] = [ '#type' => 'fieldset', - '#title' => t('Tab 3'), + '#title' => $this->t('Tab 3'), '#collapsible' => TRUE, '#group' => 'vertical_tabs2', ]; $form['tab3']['field6'] = [ - '#title' => t('Field 6'), + '#title' => $this->t('Field 6'), '#type' => 'checkbox', '#default_value' => TRUE, ]; @@ -98,7 +98,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; $form['actions']['submit'] = [ '#type' => 'submit', - '#value' => t('Submit'), + '#value' => $this->t('Submit'), ]; return $form; } @@ -109,22 +109,22 @@ public function buildForm(array $form, FormStateInterface $form_state) { public function validateForm(array &$form, FormStateInterface $form_state) { $values = $form_state->getValues(); if (empty($values['field1'])) { - $form_state->setErrorByName('tab1][field1', t('This checkbox inside a vertical tab does not have its default value.')); + $form_state->setErrorByName('tab1][field1', $this->t('This checkbox inside a vertical tab does not have its default value.')); } if ($values['field2'] != 'field2') { - $form_state->setErrorByName('tab2][field2', t('This textfield inside a vertical tab does not have its default value.')); + $form_state->setErrorByName('tab2][field2', $this->t('This textfield inside a vertical tab does not have its default value.')); } if (empty($values['field3'])) { - $form_state->setErrorByName('fieldset][field3', t('This checkbox inside a fieldset does not have its default value.')); + $form_state->setErrorByName('fieldset][field3', $this->t('This checkbox inside a fieldset does not have its default value.')); } if (empty($values['field4'])) { - $form_state->setErrorByName('container][field4', t('This checkbox inside a container does not have its default value.')); + $form_state->setErrorByName('container][field4', $this->t('This checkbox inside a container does not have its default value.')); } if (empty($values['field5'])) { - $form_state->setErrorByName('container][sub_container][field5', t('This checkbox inside a nested container does not have its default value.')); + $form_state->setErrorByName('container][sub_container][field5', $this->t('This checkbox inside a nested container does not have its default value.')); } if (empty($values['field5'])) { - $form_state->setErrorByName('tab3][field6', t('This checkbox inside a vertical tab whose fieldset access is allowed does not have its default value.')); + $form_state->setErrorByName('tab3][field6', $this->t('This checkbox inside a vertical tab whose fieldset access is allowed does not have its default value.')); } } @@ -132,7 +132,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $this->messenger()->addStatus(t('The form submitted correctly.')); + $this->messenger()->addStatus($this->t('The form submitted correctly.')); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabsForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabsForm.php index c00956bdce7c..878aa6fbed82 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabsForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestVerticalTabsForm.php @@ -36,12 +36,12 @@ public function buildForm(array $form, FormStateInterface $form_state) { for ($i = 1; $i <= $tab_count; $i++) { $form['tab' . $i] = [ '#type' => 'fieldset', - '#title' => t('Tab @num', ['@num' => $i]), + '#title' => $this->t('Tab @num', ['@num' => $i]), '#group' => 'vertical_tabs', '#access' => \Drupal::currentUser()->hasPermission('access vertical_tab_test tabs'), ]; $form['tab' . $i]['field' . $i] = [ - '#title' => t('Field @num', ['@num' => $i]), + '#title' => $this->t('Field @num', ['@num' => $i]), '#type' => 'textfield', ]; diff --git a/core/modules/system/tests/modules/form_test/src/Form/IncorrectConfigTargetForm.php b/core/modules/system/tests/modules/form_test/src/Form/IncorrectConfigTargetForm.php index 8ce44f43f6b5..9504b090db19 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/IncorrectConfigTargetForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/IncorrectConfigTargetForm.php @@ -29,7 +29,7 @@ public function getFormId() { public function buildForm(array $form, FormStateInterface $form_state) { $form['missing_key'] = [ '#type' => 'textfield', - '#title' => t('Missing key'), + '#title' => $this->t('Missing key'), '#config_target' => 'form_test.object:does_not_exist', ]; return parent::buildForm($form, $form_state); diff --git a/core/modules/system/tests/modules/form_test/src/Form/TreeConfigTargetForm.php b/core/modules/system/tests/modules/form_test/src/Form/TreeConfigTargetForm.php index 2bbe62c5c3e6..faf1d2b8db30 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/TreeConfigTargetForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/TreeConfigTargetForm.php @@ -32,17 +32,17 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#open' => TRUE, '#tree' => TRUE, '#input' => TRUE, - '#title' => t('Vegetable preferences'), + '#title' => $this->t('Vegetable preferences'), ]; $form['vegetables']['favorite'] = [ '#type' => 'textfield', - '#title' => t('Favorite'), + '#title' => $this->t('Favorite'), '#default_value' => 'Potato', '#config_target' => 'form_test.object:favorite_vegetable', ]; $form['vegetables']['nemesis'] = [ '#type' => 'textfield', - '#title' => t('Nemesis'), + '#title' => $this->t('Nemesis'), '#config_target' => 'form_test.object:nemesis_vegetable', ]; // Since form_test.object contains translatable values, it must specify a diff --git a/core/modules/views/tests/modules/views_test_data/src/Form/ViewsTestDataErrorForm.php b/core/modules/views/tests/modules/views_test_data/src/Form/ViewsTestDataErrorForm.php index d69b4bba04fd..58d7398add29 100644 --- a/core/modules/views/tests/modules/views_test_data/src/Form/ViewsTestDataErrorForm.php +++ b/core/modules/views/tests/modules/views_test_data/src/Form/ViewsTestDataErrorForm.php @@ -6,12 +6,15 @@ use Drupal\Core\Form\FormInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Implements a test form that has a validation error. */ class ViewsTestDataErrorForm implements FormInterface { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -28,7 +31,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; $form['submit'] = [ '#type' => 'submit', - '#value' => t('Submit'), + '#value' => $this->t('Submit'), ]; return $form; @@ -38,7 +41,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - $form_state->setErrorByName('text', t('Form validation error')); + $form_state->setErrorByName('text', $this->t('Form validation error')); } /** diff --git a/core/phpcs.xml.dist b/core/phpcs.xml.dist index bcef3985d1a2..ae70a1eb056f 100644 --- a/core/phpcs.xml.dist +++ b/core/phpcs.xml.dist @@ -184,6 +184,7 @@ <rule ref="DrupalPractice.Objects.GlobalFunction"> <include-pattern>*/Plugin/*</include-pattern> <include-pattern>*/ListBuilder/*</include-pattern> + <include-pattern>*/tests/*/Form/*</include-pattern> </rule> <!-- Generic sniffs --> -- GitLab