Skip to content
Snippets Groups Projects
Verified Commit 95579a70 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3464591 by quietone, longwave: Fix DrupalPractice.Objects.GlobalFunction in test Forms

parent 841720cf
No related branches found
No related tags found
No related merge requests found
Showing
with 78 additions and 73 deletions
...@@ -40,7 +40,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ?EntityIn ...@@ -40,7 +40,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ?EntityIn
$form_state->set('form_display_2', $form_display_2); $form_state->set('form_display_2', $form_display_2);
$form['entity_2'] = [ $form['entity_2'] = [
'#type' => 'details', '#type' => 'details',
'#title' => t('Second entity'), '#title' => $this->t('Second entity'),
'#tree' => TRUE, '#tree' => TRUE,
'#parents' => ['entity_2'], '#parents' => ['entity_2'],
'#weight' => 50, '#weight' => 50,
...@@ -60,7 +60,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ?EntityIn ...@@ -60,7 +60,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ?EntityIn
$form['save'] = [ $form['save'] = [
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Save'), '#value' => $this->t('Save'),
'#weight' => 100, '#weight' => 100,
]; ];
......
...@@ -8,12 +8,14 @@ ...@@ -8,12 +8,14 @@
use Drupal\Core\File\FileSystemInterface; use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Form\FormInterface; use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/** /**
* File test form class. * File test form class.
*/ */
class FileTestForm implements FormInterface { class FileTestForm implements FormInterface {
use FileTestFormTrait; use FileTestFormTrait;
use StringTranslationTrait;
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -31,7 +33,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -31,7 +33,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form['file_test_upload'] = [ $form['file_test_upload'] = [
'#type' => 'file', '#type' => 'file',
'#title' => t('Upload a file'), '#title' => $this->t('Upload a file'),
]; ];
return $form; return $form;
...@@ -83,13 +85,13 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ...@@ -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'))); $file = file_save_upload('file_test_upload', $validators, $destination, 0, static::fileExistsFromName($form_state->getValue('file_test_replace')));
if ($file) { if ($file) {
$form_state->setValue('file_test_upload', $file); $form_state->setValue('file_test_upload', $file);
\Drupal::messenger()->addStatus(t('File @filepath was uploaded.', ['@filepath' => $file->getFileUri()])); \Drupal::messenger()->addStatus($this->t('File @filepath was uploaded.', ['@filepath' => $file->getFileUri()]));
\Drupal::messenger()->addStatus(t('File name is @filename.', ['@filename' => $file->getFilename()])); \Drupal::messenger()->addStatus($this->t('File name is @filename.', ['@filename' => $file->getFilename()]));
\Drupal::messenger()->addStatus(t('File MIME type is @mimetype.', ['@mimetype' => $file->getMimeType()])); \Drupal::messenger()->addStatus($this->t('File MIME type is @mimetype.', ['@mimetype' => $file->getMimeType()]));
\Drupal::messenger()->addStatus(t('You WIN!')); \Drupal::messenger()->addStatus($this->t('You WIN!'));
} }
elseif ($file === FALSE) { elseif ($file === FALSE) {
\Drupal::messenger()->addError(t('Epic upload FAIL!')); \Drupal::messenger()->addError($this->t('Epic upload FAIL!'));
} }
} }
......
...@@ -6,12 +6,15 @@ ...@@ -6,12 +6,15 @@
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\PluginFormBase; use Drupal\Core\Plugin\PluginFormBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/** /**
* @see \Drupal\settings_tray_test\Plugin\Block\SettingsTrayFormAnnotationIsClassBlock * @see \Drupal\settings_tray_test\Plugin\Block\SettingsTrayFormAnnotationIsClassBlock
*/ */
class SettingsTrayFormAnnotationIsClassBlockForm extends PluginFormBase { class SettingsTrayFormAnnotationIsClassBlockForm extends PluginFormBase {
use StringTranslationTrait;
/** /**
* The block plugin. * The block plugin.
* *
...@@ -27,7 +30,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta ...@@ -27,7 +30,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
$form['some_setting'] = [ $form['some_setting'] = [
'#type' => 'select', '#type' => 'select',
'#title' => t('Some setting'), '#title' => $this->t('Some setting'),
'#options' => [ '#options' => [
'a' => 'A', 'a' => 'A',
'b' => 'B', 'b' => 'B',
......
...@@ -26,12 +26,12 @@ public function getFormId() { ...@@ -26,12 +26,12 @@ public function getFormId() {
*/ */
public function buildForm(array $form, FormStateInterface $form_state) { public function buildForm(array $form, FormStateInterface $form_state) {
$form['test_value'] = [ $form['test_value'] = [
'#title' => t('Test value'), '#title' => $this->t('Test value'),
'#type' => 'textfield', '#type' => 'textfield',
]; ];
$form['submit'] = [ $form['submit'] = [
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Submit'), '#value' => $this->t('Submit'),
]; ];
return $form; return $form;
......
...@@ -30,8 +30,8 @@ public function getFormId() { ...@@ -30,8 +30,8 @@ public function getFormId() {
*/ */
public function buildForm(array $form, FormStateInterface $form_state) { public function buildForm(array $form, FormStateInterface $form_state) {
$header = [ $header = [
'username' => ['data' => t('Username'), 'field' => 'u.name'], 'username' => ['data' => $this->t('Username'), 'field' => 'u.name'],
'status' => ['data' => t('Status'), 'field' => 'u.status'], 'status' => ['data' => $this->t('Status'), 'field' => 'u.status'],
]; ];
$query = Database::getConnection()->select('users_field_data', 'u'); $query = Database::getConnection()->select('users_field_data', 'u');
...@@ -59,7 +59,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -59,7 +59,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$options[$account->id()] = [ $options[$account->id()] = [
'title' => ['data' => ['#title' => $account->getAccountName()]], 'title' => ['data' => ['#title' => $account->getAccountName()]],
'username' => $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) { ...@@ -67,7 +67,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'tableselect', '#type' => 'tableselect',
'#header' => $header, '#header' => $header,
'#options' => $options, '#options' => $options,
'#empty' => t('No people available.'), '#empty' => $this->t('No people available.'),
]; ];
return $form; return $form;
......
...@@ -84,7 +84,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -84,7 +84,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form['submit'] = [ $form['submit'] = [
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Submit'), '#value' => $this->t('Submit'),
]; ];
return $form; return $form;
......
...@@ -26,7 +26,7 @@ public function getFormId() { ...@@ -26,7 +26,7 @@ public function getFormId() {
*/ */
public function buildForm(array $form, FormStateInterface $form_state, $default_value = NULL, $return_value = NULL) { public function buildForm(array $form, FormStateInterface $form_state, $default_value = NULL, $return_value = NULL) {
$form['checkbox'] = [ $form['checkbox'] = [
'#title' => t('Checkbox'), '#title' => $this->t('Checkbox'),
'#type' => 'checkbox', '#type' => 'checkbox',
'#return_value' => $return_value, '#return_value' => $return_value,
'#default_value' => $default_value, '#default_value' => $default_value,
......
...@@ -28,18 +28,18 @@ public function getFormId() { ...@@ -28,18 +28,18 @@ public function getFormId() {
public function buildForm(array $form, FormStateInterface $form_state, $json = TRUE) { public function buildForm(array $form, FormStateInterface $form_state, $json = TRUE) {
$form_state->set('json', $json); $form_state->set('json', $json);
$form['checkbox_off'] = [ $form['checkbox_off'] = [
'#title' => t('Checkbox off'), '#title' => $this->t('Checkbox off'),
'#type' => 'checkboxes', '#type' => 'checkboxes',
'#options' => ['foo', 'bar', 'baz'], '#options' => ['foo', 'bar', 'baz'],
]; ];
$form['checkbox_zero_default'] = [ $form['checkbox_zero_default'] = [
'#title' => t('Zero default'), '#title' => $this->t('Zero default'),
'#type' => 'checkboxes', '#type' => 'checkboxes',
'#options' => ['foo', 'bar', 'baz'], '#options' => ['foo', 'bar', 'baz'],
'#default_value' => [0], '#default_value' => [0],
]; ];
$form['checkbox_string_zero_default'] = [ $form['checkbox_string_zero_default'] = [
'#title' => t('Zero default (string)'), '#title' => $this->t('Zero default (string)'),
'#type' => 'checkboxes', '#type' => 'checkboxes',
'#options' => ['foo', 'bar', 'baz'], '#options' => ['foo', 'bar', 'baz'],
'#default_value' => ['0'], '#default_value' => ['0'],
......
...@@ -88,7 +88,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $first = ...@@ -88,7 +88,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $first =
*/ */
public function validateForm(array &$form, FormStateInterface $form_state) { public function validateForm(array &$form, FormStateInterface $form_state) {
if ($triggering_element = $form_state->getTriggeringElement()) { 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 { else {
$this->messenger()->addStatus('There is no clicked button.'); $this->messenger()->addStatus('There is no clicked button.');
......
...@@ -255,7 +255,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -255,7 +255,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form['submit'] = [ $form['submit'] = [
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Submit'), '#value' => $this->t('Submit'),
]; ];
return $form; return $form;
......
...@@ -27,7 +27,7 @@ public function getFormId() { ...@@ -27,7 +27,7 @@ public function getFormId() {
public function buildForm(array $form, FormStateInterface $form_state) { public function buildForm(array $form, FormStateInterface $form_state) {
$form['empty_select'] = [ $form['empty_select'] = [
'#type' => 'select', '#type' => 'select',
'#title' => t('Empty Select'), '#title' => $this->t('Empty Select'),
'#multiple' => FALSE, '#multiple' => FALSE,
'#options' => NULL, '#options' => NULL,
]; ];
......
...@@ -28,13 +28,13 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -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. // Build an example form containing a managed file and a submit form element.
$form['image'] = [ $form['image'] = [
'#type' => 'managed_file', '#type' => 'managed_file',
'#title' => t('Image'), '#title' => $this->t('Image'),
'#upload_location' => 'public://', '#upload_location' => 'public://',
'#default_value' => 0, '#default_value' => 0,
]; ];
$form['submit'] = [ $form['submit'] = [
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Submit'), '#value' => $this->t('Submit'),
]; ];
return $form; return $form;
} }
...@@ -44,7 +44,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -44,7 +44,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
*/ */
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->cleanValues(); $form_state->cleanValues();
print t('You WIN!'); print $this->t('You WIN!');
exit; exit;
} }
......
...@@ -29,11 +29,11 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -29,11 +29,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
// Build an example form containing multiple submit and button elements; not // Build an example form containing multiple submit and button elements; not
// only on the top-level. // only on the top-level.
$form = ['#tree' => TRUE]; $form = ['#tree' => TRUE];
$form['foo'] = ['#type' => 'submit', '#value' => t('Submit')]; $form['foo'] = ['#type' => 'submit', '#value' => $this->t('Submit')];
$form['bar'] = ['#type' => 'submit', '#value' => t('Submit')]; $form['bar'] = ['#type' => 'submit', '#value' => $this->t('Submit')];
$form['beer'] = ['#type' => 'value', '#value' => 1000]; $form['beer'] = ['#type' => 'value', '#value' => 1000];
$form['baz']['foo'] = ['#type' => 'button', '#value' => t('Submit')]; $form['baz']['foo'] = ['#type' => 'button', '#value' => $this->t('Submit')];
$form['baz']['baz'] = ['#type' => 'submit', '#value' => t('Submit')]; $form['baz']['baz'] = ['#type' => 'submit', '#value' => $this->t('Submit')];
$form['baz']['beer'] = ['#type' => 'value', '#value' => 2000]; $form['baz']['beer'] = ['#type' => 'value', '#value' => 2000];
// Add an arbitrary element and manually set it to be cleaned. // Add an arbitrary element and manually set it to be cleaned.
......
...@@ -30,7 +30,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -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 // For testing that a user can't submit a value not matching one of the
// allowed options. // allowed options.
$form['checkboxes'] = [ $form['checkboxes'] = [
'#title' => t('Checkboxes'), '#title' => $this->t('Checkboxes'),
'#type' => 'checkboxes', '#type' => 'checkboxes',
'#options' => [ '#options' => [
'one' => 'One', 'one' => 'One',
...@@ -39,7 +39,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -39,7 +39,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
]; ];
$form['submit'] = [ $form['submit'] = [
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Submit'), '#value' => $this->t('Submit'),
]; ];
$form['#post_render'][] = [static::class, 'postRender']; $form['#post_render'][] = [static::class, 'postRender'];
......
...@@ -61,34 +61,34 @@ public function getFormId() { ...@@ -61,34 +61,34 @@ public function getFormId() {
public function buildForm(array $form, FormStateInterface $form_state) { public function buildForm(array $form, FormStateInterface $form_state) {
$form['form_checkboxes_test'] = [ $form['form_checkboxes_test'] = [
'#type' => 'checkboxes', '#type' => 'checkboxes',
'#title' => t('Checkboxes test'), '#title' => $this->t('Checkboxes test'),
'#options' => [ '#options' => [
'first-checkbox' => t('First checkbox'), 'first-checkbox' => $this->t('First checkbox'),
'second-checkbox' => t('Second checkbox'), 'second-checkbox' => $this->t('Second checkbox'),
'third-checkbox' => t('Third checkbox'), 'third-checkbox' => $this->t('Third checkbox'),
'0' => t('0'), '0' => $this->t('0'),
], ],
]; ];
$form['form_radios_test'] = [ $form['form_radios_test'] = [
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Radios test'), '#title' => $this->t('Radios test'),
'#options' => [ '#options' => [
'first-radio' => t('First radio'), 'first-radio' => $this->t('First radio'),
'second-radio' => t('Second radio'), 'second-radio' => $this->t('Second radio'),
'third-radio' => t('Third radio'), 'third-radio' => $this->t('Third radio'),
'0' => t('0'), '0' => $this->t('0'),
], ],
// Test #field_prefix and #field_suffix placement. // Test #field_prefix and #field_suffix placement.
'#field_prefix' => '<span id="form-test-radios-field-prefix">' . t('Radios #field_prefix 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">' . t('Radios #field_suffix element') . '</span>', '#field_suffix' => '<span id="form-test-radios-field-suffix">' . $this->t('Radios #field_suffix element') . '</span>',
]; ];
$form['form_checkbox_test'] = [ $form['form_checkbox_test'] = [
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Checkbox test'), '#title' => $this->t('Checkbox test'),
]; ];
$form['form_textfield_test_title_and_required'] = [ $form['form_textfield_test_title_and_required'] = [
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Textfield test for required with title'), '#title' => $this->t('Textfield test for required with title'),
'#required' => TRUE, '#required' => TRUE,
]; ];
$form['form_textfield_test_no_title_required'] = [ $form['form_textfield_test_no_title_required'] = [
...@@ -100,20 +100,20 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -100,20 +100,20 @@ public function buildForm(array $form, FormStateInterface $form_state) {
]; ];
$form['form_textfield_test_title'] = [ $form['form_textfield_test_title'] = [
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Textfield test for title only'), '#title' => $this->t('Textfield test for title only'),
// Not required. // Not required.
// Test #prefix and #suffix placement. // Test #prefix and #suffix placement.
'#prefix' => '<div id="form-test-textfield-title-prefix">' . t('Textfield #prefix element') . '</div>', '#prefix' => '<div id="form-test-textfield-title-prefix">' . $this->t('Textfield #prefix element') . '</div>',
'#suffix' => '<div id="form-test-textfield-title-suffix">' . t('Textfield #suffix element') . '</div>', '#suffix' => '<div id="form-test-textfield-title-suffix">' . $this->t('Textfield #suffix element') . '</div>',
]; ];
$form['form_textfield_test_title_after'] = [ $form['form_textfield_test_title_after'] = [
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Textfield test for title after element'), '#title' => $this->t('Textfield test for title after element'),
'#title_display' => 'after', '#title_display' => 'after',
]; ];
$form['form_textfield_test_title_invisible'] = [ $form['form_textfield_test_title_invisible'] = [
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Textfield test for invisible title'), '#title' => $this->t('Textfield test for invisible title'),
'#title_display' => 'invisible', '#title_display' => 'invisible',
]; ];
// Textfield test for title set not to display. // Textfield test for title set not to display.
......
...@@ -28,30 +28,30 @@ public function getFormId() { ...@@ -28,30 +28,30 @@ public function getFormId() {
*/ */
public function buildForm(array $form, FormStateInterface $form_state) { public function buildForm(array $form, FormStateInterface $form_state) {
$form['languages_all'] = [ $form['languages_all'] = [
'#title' => t('Languages: All'), '#title' => $this->t('Languages: All'),
'#type' => 'language_select', '#type' => 'language_select',
'#languages' => LanguageInterface::STATE_ALL, '#languages' => LanguageInterface::STATE_ALL,
'#default_value' => 'xx', '#default_value' => 'xx',
]; ];
$form['languages_configurable'] = [ $form['languages_configurable'] = [
'#title' => t('Languages: Configurable'), '#title' => $this->t('Languages: Configurable'),
'#type' => 'language_select', '#type' => 'language_select',
'#languages' => LanguageInterface::STATE_CONFIGURABLE, '#languages' => LanguageInterface::STATE_CONFIGURABLE,
'#default_value' => 'en', '#default_value' => 'en',
]; ];
$form['languages_locked'] = [ $form['languages_locked'] = [
'#title' => t('Languages: Locked'), '#title' => $this->t('Languages: Locked'),
'#type' => 'language_select', '#type' => 'language_select',
'#languages' => LanguageInterface::STATE_LOCKED, '#languages' => LanguageInterface::STATE_LOCKED,
]; ];
$form['languages_config_and_locked'] = [ $form['languages_config_and_locked'] = [
'#title' => t('Languages: Configurable and locked'), '#title' => $this->t('Languages: Configurable and locked'),
'#type' => 'language_select', '#type' => 'language_select',
'#languages' => LanguageInterface::STATE_CONFIGURABLE | LanguageInterface::STATE_LOCKED, '#languages' => LanguageInterface::STATE_CONFIGURABLE | LanguageInterface::STATE_LOCKED,
'#default_value' => 'dummy_value', '#default_value' => 'dummy_value',
]; ];
$form['language_custom_options'] = [ $form['language_custom_options'] = [
'#title' => t('Languages: Custom'), '#title' => $this->t('Languages: Custom'),
'#type' => 'language_select', '#type' => 'language_select',
'#languages' => LanguageInterface::STATE_CONFIGURABLE | LanguageInterface::STATE_LOCKED, '#languages' => LanguageInterface::STATE_CONFIGURABLE | LanguageInterface::STATE_LOCKED,
'#options' => ['opt1' => 'First option', 'opt2' => 'Second option', 'opt3' => 'Third option'], '#options' => ['opt1' => 'First option', 'opt2' => 'Second option', 'opt3' => 'Third option'],
......
...@@ -63,23 +63,23 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -63,23 +63,23 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'submit', '#type' => 'submit',
'#limit_validation_errors' => [['test']], '#limit_validation_errors' => [['test']],
'#submit' => ['::partialSubmitForm'], '#submit' => ['::partialSubmitForm'],
'#value' => t('Partial validate'), '#value' => $this->t('Partial validate'),
]; ];
$form['actions']['partial_numeric_index'] = [ $form['actions']['partial_numeric_index'] = [
'#type' => 'submit', '#type' => 'submit',
'#limit_validation_errors' => [['test_numeric_index', 0]], '#limit_validation_errors' => [['test_numeric_index', 0]],
'#submit' => ['::partialSubmitForm'], '#submit' => ['::partialSubmitForm'],
'#value' => t('Partial validate (numeric index)'), '#value' => $this->t('Partial validate (numeric index)'),
]; ];
$form['actions']['substring'] = [ $form['actions']['substring'] = [
'#type' => 'submit', '#type' => 'submit',
'#limit_validation_errors' => [['test_substring', 'foo']], '#limit_validation_errors' => [['test_substring', 'foo']],
'#submit' => ['::partialSubmitForm'], '#submit' => ['::partialSubmitForm'],
'#value' => t('Partial validate (substring)'), '#value' => $this->t('Partial validate (substring)'),
]; ];
$form['actions']['full'] = [ $form['actions']['full'] = [
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Full validate'), '#value' => $this->t('Full validate'),
]; ];
return $form; return $form;
} }
...@@ -89,7 +89,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -89,7 +89,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
*/ */
public function elementValidateLimitValidationErrors($element, FormStateInterface $form_state) { public function elementValidateLimitValidationErrors($element, FormStateInterface $form_state) {
if ($element['#value'] == 'invalid') { 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']]));
} }
} }
......
...@@ -31,7 +31,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -31,7 +31,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
]; ];
$form['checkboxes'] = [ $form['checkboxes'] = [
'#title' => t('Checkboxes'), '#title' => $this->t('Checkboxes'),
'#type' => 'checkboxes', '#type' => 'checkboxes',
'#options' => [ '#options' => [
1 => 'First checkbox', 1 => 'First checkbox',
...@@ -90,7 +90,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -90,7 +90,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
*/ */
public function validateForm(array &$form, FormStateInterface $form_state) { public function validateForm(array &$form, FormStateInterface $form_state) {
if ($form_state->isValueEmpty('textfield')) { if ($form_state->isValueEmpty('textfield')) {
$form_state->setErrorByName('textfield', t('Textfield is required.')); $form_state->setErrorByName('textfield', $this->t('Textfield is required.'));
} }
} }
......
...@@ -30,17 +30,17 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -30,17 +30,17 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form = [ $form = [
'checkbox_1_default_off' => [ 'checkbox_1_default_off' => [
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('This checkbox defaults to unchecked'), '#title' => $this->t('This checkbox defaults to unchecked'),
'#default_value' => FALSE, '#default_value' => FALSE,
], ],
'checkbox_1_default_on' => [ 'checkbox_1_default_on' => [
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('This checkbox defaults to checked'), '#title' => $this->t('This checkbox defaults to checked'),
'#default_value' => TRUE, '#default_value' => TRUE,
], ],
'text_1' => [ 'text_1' => [
'#type' => 'textfield', '#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', '#default_value' => 'DEFAULT 1',
], ],
]; ];
...@@ -59,17 +59,17 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -59,17 +59,17 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form += [ $form += [
'checkbox_2_default_off' => [ 'checkbox_2_default_off' => [
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('This checkbox defaults to unchecked'), '#title' => $this->t('This checkbox defaults to unchecked'),
'#default_value' => FALSE, '#default_value' => FALSE,
], ],
'checkbox_2_default_on' => [ 'checkbox_2_default_on' => [
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('This checkbox defaults to checked'), '#title' => $this->t('This checkbox defaults to checked'),
'#default_value' => TRUE, '#default_value' => TRUE,
], ],
'text_2' => [ 'text_2' => [
'#type' => 'textfield', '#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', '#default_value' => 'DEFAULT 2',
], ],
]; ];
......
...@@ -28,11 +28,11 @@ public function getFormId() { ...@@ -28,11 +28,11 @@ public function getFormId() {
public function buildForm(array $form, FormStateInterface $form_state) { public function buildForm(array $form, FormStateInterface $form_state) {
$form['redirection'] = [ $form['redirection'] = [
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Use redirection'), '#title' => $this->t('Use redirection'),
]; ];
$form['destination'] = [ $form['destination'] = [
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Redirect destination'), '#title' => $this->t('Redirect destination'),
'#states' => [ '#states' => [
'visible' => [ 'visible' => [
':input[name="redirection"]' => ['checked' => TRUE], ':input[name="redirection"]' => ['checked' => TRUE],
...@@ -41,7 +41,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -41,7 +41,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
]; ];
$form['ignore_destination'] = [ $form['ignore_destination'] = [
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Ignore destination query parameter'), '#title' => $this->t('Ignore destination query parameter'),
'#states' => [ '#states' => [
'visible' => [ 'visible' => [
':input[name="redirection"]' => ['checked' => TRUE], ':input[name="redirection"]' => ['checked' => TRUE],
...@@ -50,7 +50,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ...@@ -50,7 +50,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
]; ];
$form['submit'] = [ $form['submit'] = [
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Submit'), '#value' => $this->t('Submit'),
]; ];
return $form; return $form;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment