diff --git a/core/lib/Drupal/Core/Form/SubformState.php b/core/lib/Drupal/Core/Form/SubformState.php index 50f3911..14cfd10 100644 --- a/core/lib/Drupal/Core/Form/SubformState.php +++ b/core/lib/Drupal/Core/Form/SubformState.php @@ -98,7 +98,12 @@ protected function getParents($property) { */ public function &getValues() { $exists = NULL; - $values = &NestedArray::getValue(parent::getValues(), $this->getParents('#parents'), $exists); + if ($this->isProcessingInput()) { + $values = &NestedArray::getValue(parent::getValues(), $this->getParents('#parents'), $exists); + } + else { + @trigger_error("Please don't.", E_USER_DEPRECATED); + } if (!$exists) { $values = []; } diff --git a/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php b/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php index ec2ac8b..f485a6b 100644 --- a/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php +++ b/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php @@ -62,10 +62,12 @@ class SubformStateTest extends UnitTestCase { * * @param string[] $parents * @param string $expected + * @param bool $is_processing_input */ - public function testGetValues(array $parents, $expected) { + public function testGetValues(array $parents, $expected, $is_processing_input = TRUE) { $parent_form_state = new FormState(); $parent_form_state->setValues($this->formStateValues); + $parent_form_state->setProcessInput($is_processing_input); $subform = NestedArray::getValue($this->parentForm, $parents); $subform_state = SubformState::createForSubform($subform, $this->parentForm, $parent_form_state); @@ -73,9 +75,10 @@ public function testGetValues(array $parents, $expected) { $this->assertSame($expected, $subform_state_values); // Modify the retrieved values and confirm they are modified by reference in - // the parent form state. + // the parent form state when input is being processed. $subform_state_values['fish'] = 'Jim'; - $this->assertSame($subform_state_values, $subform_state->getValues()); + $subform_expected = $is_processing_input ? $subform_state_values : []; + $this->assertSame($subform_expected, $subform_state->getValues()); } /** @@ -87,6 +90,11 @@ public function providerGetValues() { ['dog'], $this->formStateValues['dog'], ]; + $data['not_processing_input'] = [ + ['dog'], + [], + FALSE, + ]; return $data; } @@ -131,6 +139,7 @@ public function providerGetValuesBroken() { public function testGetValue($parents, $key, $expected, $default = NULL) { $parent_form_state = new FormState(); $parent_form_state->setValues($this->formStateValues); + $parent_form_state->setProcessInput(); $subform = NestedArray::getValue($this->parentForm, $parents); $subform_state = SubformState::createForSubform($subform, $this->parentForm, $parent_form_state); @@ -190,6 +199,7 @@ public function providerTestGetValueBroken() { public function testSetValues($parents, $new_values, $expected) { $parent_form_state = new FormState(); $parent_form_state->setValues($this->formStateValues); + $parent_form_state->setProcessInput(); $subform = NestedArray::getValue($this->parentForm, $parents); $subform_state = SubformState::createForSubform($subform, $this->parentForm, $parent_form_state);