diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index b506079..bceb815 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -675,9 +675,7 @@ function content_translation_element_info_alter(&$type) { */ function content_translation_enable_widget($entity_type, $bundle, array &$form, FormStateInterface $form_state) { $key = $form_state->get(['content_translation', 'key']); - if (!$context = $form_state->get(['language', $key])) { - $context = []; - } + $context = $form_state->get(['language', $key]) ?: []; $context += ['entity_type' => $entity_type, 'bundle' => $bundle]; $form_state->set(['language', $key], $context); $element = content_translation_language_configuration_element_process(array('#name' => $key), $form_state, $form); diff --git a/core/modules/system/src/Tests/Form/FormTest.php b/core/modules/system/src/Tests/Form/FormTest.php index cfcc299..a377e6e 100644 --- a/core/modules/system/src/Tests/Form/FormTest.php +++ b/core/modules/system/src/Tests/Form/FormTest.php @@ -112,7 +112,7 @@ function testRequiredFields() { $user_input['form_id'] = $form_id; $form_state->setUserInput($user_input); $form_state->setFormObject(new StubForm($form_id, $form)); - $form_state->setMethod('post'); + $form_state->setMethod('POST'); // The form token CSRF protection should not interfere with this test, // so we bypass it by setting the token to FALSE. $form['#token'] = FALSE; diff --git a/core/modules/system/src/Tests/Form/ProgrammaticTest.php b/core/modules/system/src/Tests/Form/ProgrammaticTest.php index be44907..ef8130c 100644 --- a/core/modules/system/src/Tests/Form/ProgrammaticTest.php +++ b/core/modules/system/src/Tests/Form/ProgrammaticTest.php @@ -86,6 +86,7 @@ private function submitForm($values, $valid_input) { // We check submitted values only if we have a valid input. if ($valid_input) { + // Fetching the values that were set in the submission handler. $stored_values = $form_state->get('programmatic_form_submit'); foreach ($values as $key => $value) { $this->assertEqual($stored_values[$key], $value, format_string('Submission handler correctly executed: %stored_key is %stored_value', array('%stored_key' => $key, '%stored_value' => print_r($value, TRUE)))); diff --git a/core/modules/system/src/Tests/Form/TriggeringElementTest.php b/core/modules/system/src/Tests/Form/TriggeringElementTest.php index 89bdd94..24cc2d2 100644 --- a/core/modules/system/src/Tests/Form/TriggeringElementTest.php +++ b/core/modules/system/src/Tests/Form/TriggeringElementTest.php @@ -10,7 +10,7 @@ use Drupal\simpletest\WebTestBase; /** - * Tests that FAPI correctly determines the triggering_element. + * Tests that FAPI correctly determines the triggering element. * * @group Form */ @@ -36,22 +36,22 @@ function testNoButtonInfoInPost() { // Ensure submitting a form with no buttons results in no triggering element // and the form submit handler not running. $this->drupalPostForm($path, $edit, NULL, array(), array(), $form_html_id); - $this->assertText('There is no clicked button.', '$form_state[\'triggering_element\'] set to NULL.'); + $this->assertText('There is no clicked button.', '$form_state->getTriggeringElement() set to NULL.'); $this->assertNoText('Submit handler for form_test_clicked_button executed.', 'Form submit handler did not execute.'); // Ensure submitting a form with one or more submit buttons results in the // triggering element being set to the first one the user has access to. An // argument with 'r' in it indicates a restricted (#access=FALSE) button. $this->drupalPostForm($path . '/s', $edit, NULL, array(), array(), $form_html_id); - $this->assertText('The clicked button is button1.', '$form_state[\'triggering_element\'] set to only button.'); + $this->assertText('The clicked button is button1.', '$form_state->getTriggeringElement() set to only button.'); $this->assertText('Submit handler for form_test_clicked_button executed.', 'Form submit handler executed.'); $this->drupalPostForm($path . '/s/s', $edit, NULL, array(), array(), $form_html_id); - $this->assertText('The clicked button is button1.', '$form_state[\'triggering_element\'] set to first button.'); + $this->assertText('The clicked button is button1.', '$form_state->getTriggeringElement() set to first button.'); $this->assertText('Submit handler for form_test_clicked_button executed.', 'Form submit handler executed.'); $this->drupalPostForm($path . '/rs/s', $edit, NULL, array(), array(), $form_html_id); - $this->assertText('The clicked button is button2.', '$form_state[\'triggering_element\'] set to first available button.'); + $this->assertText('The clicked button is button2.', '$form_state->getTriggeringElement() set to first available button.'); $this->assertText('Submit handler for form_test_clicked_button executed.', 'Form submit handler executed.'); // Ensure submitting a form with buttons of different types results in the @@ -59,15 +59,15 @@ function testNoButtonInfoInPost() { // the FAPI 'button' type, this should result in the submit handler not // executing. The types are 's'(ubmit), 'b'(utton), and 'i'(mage_button). $this->drupalPostForm($path . '/s/b/i', $edit, NULL, array(), array(), $form_html_id); - $this->assertText('The clicked button is button1.', '$form_state[\'triggering_element\'] set to first button.'); + $this->assertText('The clicked button is button1.', '$form_state->getTriggeringElement() set to first button.'); $this->assertText('Submit handler for form_test_clicked_button executed.', 'Form submit handler executed.'); $this->drupalPostForm($path . '/b/s/i', $edit, NULL, array(), array(), $form_html_id); - $this->assertText('The clicked button is button1.', '$form_state[\'triggering_element\'] set to first button.'); + $this->assertText('The clicked button is button1.', '$form_state->getTriggeringElement() set to first button.'); $this->assertNoText('Submit handler for form_test_clicked_button executed.', 'Form submit handler did not execute.'); $this->drupalPostForm($path . '/i/s/b', $edit, NULL, array(), array(), $form_html_id); - $this->assertText('The clicked button is button1.', '$form_state[\'triggering_element\'] set to first button.'); + $this->assertText('The clicked button is button1.', '$form_state->getTriggeringElement() set to first button.'); $this->assertText('Submit handler for form_test_clicked_button executed.', 'Form submit handler executed.'); } @@ -95,7 +95,7 @@ function testAttemptAccessControlBypass() { // Do this with both a negative and positive assertion, because negative // assertions alone can be brittle. See testNoButtonInfoInPost() for why the //triggering element gets set to 'button2'. - $this->assertNoText('The clicked button is button1.', '$form_state[\'triggering_element\'] not set to a restricted button.'); - $this->assertText('The clicked button is button2.', '$form_state[\'triggering_element\'] not set to a restricted button.'); + $this->assertNoText('The clicked button is button1.', '$form_state->getTriggeringElement() not set to a restricted button.'); + $this->assertText('The clicked button is button2.', '$form_state->getTriggeringElement() not set to a restricted button.'); } } diff --git a/core/modules/system/tests/modules/batch_test/src/Form/BatchTestMultiStepForm.php b/core/modules/system/tests/modules/batch_test/src/Form/BatchTestMultiStepForm.php index 19bf6d3..8d40948 100644 --- a/core/modules/system/tests/modules/batch_test/src/Form/BatchTestMultiStepForm.php +++ b/core/modules/system/tests/modules/batch_test/src/Form/BatchTestMultiStepForm.php @@ -60,8 +60,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } if ($step < 2) { - $step++; - $form_state->set('step', $step); + $form_state->set('step', ++$step); $form_state->setRebuild(); } diff --git a/core/modules/user/src/Form/UserLoginForm.php b/core/modules/user/src/Form/UserLoginForm.php index 3f702d1..e1275a4 100644 --- a/core/modules/user/src/Form/UserLoginForm.php +++ b/core/modules/user/src/Form/UserLoginForm.php @@ -184,8 +184,9 @@ public function validateAuthentication(array &$form, FormStateInterface $form_st } } // We are not limited by flood control, so try to authenticate. - // Store uid in form state as a flag for self::validateFinal(). - $form_state->set('uid', $this->userAuth->authenticate($form_state->getValue('name'), $password)); + // Store $uid in form state as a flag for self::validateFinal(). + $uid = $this->userAuth->authenticate($form_state->getValue('name'), $password); + $form_state->set('uid', $uid); } } diff --git a/core/modules/user/src/Tests/UserAccountFormFieldsTest.php b/core/modules/user/src/Tests/UserAccountFormFieldsTest.php index 152a462..df01adc 100644 --- a/core/modules/user/src/Tests/UserAccountFormFieldsTest.php +++ b/core/modules/user/src/Tests/UserAccountFormFieldsTest.php @@ -31,8 +31,9 @@ class UserAccountFormFieldsTest extends DrupalUnitTestBase { function testInstallConfigureForm() { require_once DRUPAL_ROOT . '/core/includes/install.core.inc'; require_once DRUPAL_ROOT . '/core/includes/install.inc'; + $install_state = install_state_defaults(); $form_state = new FormState(); - $form_state->addBuildInfo('args', [install_state_defaults()]); + $form_state->addBuildInfo('args', [&$install_state]); $form = $this->container->get('form_builder') ->buildForm('Drupal\Core\Installer\Form\SiteConfigureForm', $form_state); diff --git a/core/modules/views_ui/src/ViewUI.php b/core/modules/views_ui/src/ViewUI.php index f3f22a3..203374c 100644 --- a/core/modules/views_ui/src/ViewUI.php +++ b/core/modules/views_ui/src/ViewUI.php @@ -364,7 +364,7 @@ public function getStandardButtons(&$form, FormStateInterface $form_state, $form $cancel_submit = function_exists($form_id . '_cancel') ? $form_id . '_cancel' : array($this, 'standardCancel'); $form['actions']['cancel'] = array( '#type' => 'submit', - '#value' => !$form_state->has('ok_button') ? t('Cancel') : t('Ok'), + '#value' => !$form_state->get('ok_button') ? t('Cancel') : t('Ok'), '#submit' => array($cancel_submit), '#validate' => array(), '#ajax' => array(