diff --git a/core/lib/Drupal/Core/Form/FormState.php b/core/lib/Drupal/Core/Form/FormState.php index c37269a..b15eb38 100644 --- a/core/lib/Drupal/Core/Form/FormState.php +++ b/core/lib/Drupal/Core/Form/FormState.php @@ -1212,7 +1212,7 @@ protected function moduleLoadInclude($module, $type, $name = NULL) { /** * {@inheritdoc} */ - public function getFormStateForSubform(array $element) { + public function getSubFormState(array $element) { return SubFormState::createForSubform($element, $this); } diff --git a/core/lib/Drupal/Core/Form/FormStateInterface.php b/core/lib/Drupal/Core/Form/FormStateInterface.php index a396440..1ac1e6d 100644 --- a/core/lib/Drupal/Core/Form/FormStateInterface.php +++ b/core/lib/Drupal/Core/Form/FormStateInterface.php @@ -1106,6 +1106,6 @@ public function cleanValues(); * * @return \Drupal\Core\Form\FormStateInterface */ - public function getFormStateForSubform(array $subform); + public function getSubFormState(array $subform); } diff --git a/core/lib/Drupal/Core/Form/SubFormState.php b/core/lib/Drupal/Core/Form/SubFormState.php index 746dfc7..9fe3df6 100644 --- a/core/lib/Drupal/Core/Form/SubFormState.php +++ b/core/lib/Drupal/Core/Form/SubFormState.php @@ -76,7 +76,7 @@ protected function getSubFormProperty($property) { * @return string[] * The parent keys (#array_parents). */ - protected function getSubFormParents() { + protected function getArrayParents() { return $this->getSubFormProperty('#array_parents'); } @@ -86,7 +86,7 @@ protected function getSubFormParents() { * @return string[] * The parent keys (#parents). */ - protected function getSubFormStateParents() { + protected function getParents() { return $this->getSubFormProperty('#parents'); } @@ -95,7 +95,7 @@ protected function getSubFormStateParents() { */ public function &getValues() { $exists = NULL; - $values = &NestedArray::getValue(parent::getValues(), $this->getSubFormStateParents(), $exists); + $values = &NestedArray::getValue(parent::getValues(), $this->getParents(), $exists); if (!$exists) { $values = []; } @@ -110,7 +110,7 @@ public function &getValues() { /** * {@inheritdoc} */ - public function getFormStateForSubform(array $element) { + public function getSubFormState(array $element) { return static::createForSubform($element, $this); } diff --git a/core/lib/Drupal/Core/Plugin/PluginFormInterface.php b/core/lib/Drupal/Core/Plugin/PluginFormInterface.php index 043f405..6c9a98c 100644 --- a/core/lib/Drupal/Core/Plugin/PluginFormInterface.php +++ b/core/lib/Drupal/Core/Plugin/PluginFormInterface.php @@ -35,7 +35,7 @@ * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. Calling code should pass on a sub form * state created through - * \Drupal\Core\Form\FormStateInterface::createFormFormElement(). + * \Drupal\Core\Form\FormStateInterface::getSubFormState(). * * @return array * The form structure. @@ -51,7 +51,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. Calling code should pass on a sub form * state created through - * \Drupal\Core\Form\FormStateInterface::createFormFormElement(). + * \Drupal\Core\Form\FormStateInterface::getSubFormState(). */ public function validateConfigurationForm(array &$form, FormStateInterface $form_state); @@ -64,7 +64,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. Calling code should pass on a sub form * state created through - * \Drupal\Core\Form\FormStateInterface::createFormFormElement(). + * \Drupal\Core\Form\FormStateInterface::getSubFormState(). */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state); diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index 0c3287f..388d091 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -126,7 +126,7 @@ public function form(array $form, FormStateInterface $form_state) { $form['#tree'] = TRUE; $form['settings'] = []; - $subform_state = $form_state->getFormStateForSubform($form['settings']); + $subform_state = $form_state->getSubFormState($form['settings']); $form['settings'] = $entity->getPlugin()->buildConfigurationForm($form['settings'], $subform_state); $form['visibility'] = $this->buildVisibilityInterface([], $form_state); @@ -287,7 +287,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { // The Block Entity form puts all block plugin form elements in the // settings form element, so just pass that to the block for validation. - $this->entity->getPlugin()->validateConfigurationForm($form['settings'], $form_state->getFormStateForSubform($form['settings'])); + $this->entity->getPlugin()->validateConfigurationForm($form['settings'], $form_state->getSubFormState($form['settings'])); $this->validateVisibility($form, $form_state); } @@ -311,7 +311,7 @@ protected function validateVisibility(array $form, FormStateInterface $form_stat // Allow the condition to validate the form. $condition = $form_state->get(['conditions', $condition_id]); - $condition->validateConfigurationForm($form['visibility'][$condition_id], $form_state->getFormStateForSubform($form['visibility'][$condition_id])); + $condition->validateConfigurationForm($form['visibility'][$condition_id], $form_state->getSubFormState($form['visibility'][$condition_id])); } } @@ -324,13 +324,13 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $entity = $this->entity; // The Block Entity form puts all block plugin form elements in the // settings form element, so just pass that to the block for submission. - $entity->getPlugin()->submitConfigurationForm($form['settings'], $form_state->getFormStateForSubform($form['settings'])); + $entity->getPlugin()->submitConfigurationForm($form['settings'], $form_state->getSubFormState($form['settings'])); // Submit visibility condition settings. foreach ($form_state->getValue('visibility') as $condition_id => $values) { // Allow the condition to submit the form. $condition = $form_state->get(['conditions', $condition_id]); - $condition->submitConfigurationForm($form['visibility'][$condition_id], $form_state->getFormStateForSubform($form['visibility'][$condition_id])); + $condition->submitConfigurationForm($form['visibility'][$condition_id], $form_state->getSubFormState($form['visibility'][$condition_id])); if ($condition instanceof ContextAwarePluginInterface) { $context_mapping = isset($values['context_mapping']) ? $values['context_mapping'] : []; diff --git a/core/modules/image/src/Form/ImageEffectFormBase.php b/core/modules/image/src/Form/ImageEffectFormBase.php index d3c0396..def903f 100644 --- a/core/modules/image/src/Form/ImageEffectFormBase.php +++ b/core/modules/image/src/Form/ImageEffectFormBase.php @@ -79,7 +79,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ImageStyl ); $form['data'] = []; - $subform_state = $form_state->getFormStateForSubform($form['data']); + $subform_state = $form_state->getSubFormState($form['data']); $form['data'] = $this->imageEffect->buildConfigurationForm($form['data'], $subform_state); $form['data']['#tree'] = TRUE; @@ -109,7 +109,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ImageStyl public function validateForm(array &$form, FormStateInterface $form_state) { // The image effect configuration is stored in the 'data' key in the form, // pass that through for validation. - $this->imageEffect->validateConfigurationForm($form, $form_state->getFormStateForSubform($form['data'])); + $this->imageEffect->validateConfigurationForm($form['data'], $form_state->getSubFormState($form['data'])); } /** @@ -120,7 +120,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // The image effect configuration is stored in the 'data' key in the form, // pass that through for submission. - $this->imageEffect->submitConfigurationForm($form, $form_state->getFormStateForSubform($form['data'])); + $this->imageEffect->submitConfigurationForm($form['data'], $form_state->getSubFormState($form['data'])); $this->imageEffect->setWeight($form_state->getValue('weight')); if (!$this->imageEffect->getUuid()) { diff --git a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php index fd98431..71d1097 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php @@ -420,9 +420,9 @@ public function testCleanValues($form_state) { } /** - * @covers ::getFormStateForSubform + * @covers ::getSubFormState */ - public function testGetFormStateForSubform() { + public function testGetSubFormState() { $form_state = new FormState(); $element = [ '#parents' => ['foo'], @@ -430,7 +430,7 @@ public function testGetFormStateForSubform() { 'bar' => [], ]; - $sub_form_state = $form_state->getFormStateForSubform($element); + $sub_form_state = $form_state->getSubFormState($element); $this->assertNotSame($form_state, $sub_form_state); $this->assertInstanceOf(FormStateInterface::class, $sub_form_state); } diff --git a/core/tests/Drupal/Tests/Core/Form/SubFormStateTest.php b/core/tests/Drupal/Tests/Core/Form/SubFormStateTest.php index 2836324..d516d9a 100644 --- a/core/tests/Drupal/Tests/Core/Form/SubFormStateTest.php +++ b/core/tests/Drupal/Tests/Core/Form/SubFormStateTest.php @@ -51,9 +51,9 @@ class SubFormStateTest extends UnitTestCase { ]; /** - * @covers ::getFormStateForSubform + * @covers ::getSubFormState */ - public function testGetFormStateForSubform() { + public function testGetSubFormState() { $form_state = new FormState(); $element = [ '#parents' => ['foo'], @@ -61,13 +61,15 @@ public function testGetFormStateForSubform() { 'bar' => [], ]; - $sub_form_state = $form_state->getFormStateForSubform($element); + $sub_form_state = $form_state->getSubFormState($element); $this->assertNotSame($form_state, $sub_form_state); $this->assertInstanceOf(FormStateInterface::class, $sub_form_state); } /** * @covers ::getValues + * @covers ::getParents + * @covers ::getSubFormProperty * * @dataProvider providerTestGetValues * @@ -79,7 +81,7 @@ public function testGetValues(array $parents, $expected) { $form_state->setValues($this->initialValues); $element = NestedArray::getValue($this->element, $parents); - $sub_form_state = $form_state->getFormStateForSubform($element); + $sub_form_state = $form_state->getSubFormState($element); $sub_values = $sub_form_state->getValues(); $this->assertSame($expected, $sub_values); } @@ -88,13 +90,19 @@ public function testGetValues(array $parents, $expected) { * Provides data to self::testGetValues(). */ public function providerTestGetValues() { - return [ - [['dog'], $this->initialValues['dog']], + $data = []; + $data['exist'] = [ + ['dog'], + $this->initialValues['dog'], ]; + + return $data; } /** * @covers ::getValues + * @covers ::getParents + * @covers ::getSubFormProperty * * @dataProvider providerTestGetValuesBroken * @@ -111,10 +119,17 @@ public function testGetValuesBroken(array $parents, $expected) { * Provides data to self::testGetValuesBroken(). */ public function providerTestGetValuesBroken() { - return [ - [['foo'], $this->initialValues['foo']], - [['dog', 'name'], 'Dodger'], + $data = []; + $data['exist'] = [ + ['foo'], + $this->initialValues['foo'], + ]; + $data['nested'] = [ + ['dog', 'name'], + 'Dodger', ]; + + return $data; } /** @@ -127,7 +142,7 @@ public function testGetValue($parents, $key, $expected, $default = NULL) { $form_state->setValues($this->initialValues); $element = NestedArray::getValue($this->element, $parents); - $sub_form_state = $form_state->getFormStateForSubform($element); + $sub_form_state = $form_state->getSubFormState($element); $sub_values = $sub_form_state->getValue($key, $default); $this->assertSame($expected, $sub_values); } @@ -136,9 +151,14 @@ public function testGetValue($parents, $key, $expected, $default = NULL) { * Provides data to self::testGetValue(). */ public function providerTestGetValue() { - return [ - [['dog'], 'name', 'Dodger'], + $data = []; + $data['exist'] = [ + ['dog'], + 'name', + 'Dodger', ]; + + return $data; } /** @@ -156,9 +176,14 @@ public function testGetValueBroken(array $parents, $key, $expected, $default = N * Provides data to self::testGetValueBroken(). */ public function providerTestGetValueBroken() { - return [ - [['dog', 'name'], NULL, 'Dodger'], + $data = []; + $data['nested'] = [ + ['dog', 'name'], + NULL, + 'Dodger', ]; + + return $data; } /** @@ -171,7 +196,7 @@ public function testSetValues($parents, $new_values, $expected) { $form_state->setValues($this->initialValues); $element = NestedArray::getValue($this->element, $parents); - $sub_form_state = $form_state->getFormStateForSubform($element); + $sub_form_state = $form_state->getSubFormState($element); $sub_form_state->setValues($new_values); $this->assertSame($expected, $form_state->getValues()); } @@ -180,12 +205,16 @@ public function testSetValues($parents, $new_values, $expected) { * Provides data to self::testSetValues(). */ public function providerTestSetValues() { - return [ - [['dog'], [], [ + $data = []; + $data['exist'] = [ + ['dog'], + [], + [ 'foo' => 'bar', 'dog' => [], - ]], + ], ]; + return $data; } /**