Commit ee6ddbe8 authored by alexpott's avatar alexpott

Issue #2332389 by tim.plunkett: Finish adding methods to FormStateInterface.

parent fe85f9be
...@@ -806,12 +806,9 @@ function install_tasks_to_display($install_state) { ...@@ -806,12 +806,9 @@ function install_tasks_to_display($install_state) {
function install_get_form($form_id, array &$install_state) { function install_get_form($form_id, array &$install_state) {
// Ensure the form will not redirect, since install_run_tasks() uses a custom // Ensure the form will not redirect, since install_run_tasks() uses a custom
// redirection logic. // redirection logic.
$form_state = new FormState(array( $form_state = (new FormState())
'build_info' => array( ->addBuildInfo('args', [&$install_state])
'args' => array(&$install_state), ->disableRedirect();
),
'no_redirect' => TRUE,
));
$form_builder = \Drupal::formBuilder(); $form_builder = \Drupal::formBuilder();
if ($install_state['interactive']) { if ($install_state['interactive']) {
$form = $form_builder->buildForm($form_id, $form_state); $form = $form_builder->buildForm($form_id, $form_state);
...@@ -827,7 +824,7 @@ function install_get_form($form_id, array &$install_state) { ...@@ -827,7 +824,7 @@ function install_get_form($form_id, array &$install_state) {
// values taken from the installation state. // values taken from the installation state.
$install_form_id = $form_builder->getFormId($form_id, $form_state); $install_form_id = $form_builder->getFormId($form_id, $form_state);
if (!empty($install_state['forms'][$install_form_id])) { if (!empty($install_state['forms'][$install_form_id])) {
$form_state->set('values', $install_state['forms'][$install_form_id]); $form_state->setValues($install_state['forms'][$install_form_id]);
} }
$form_builder->submitForm($form_id, $form_state); $form_builder->submitForm($form_id, $form_state);
......
...@@ -356,9 +356,8 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form ...@@ -356,9 +356,8 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
foreach ($this->getVisibilityConditions() as $condition_id => $condition) { foreach ($this->getVisibilityConditions() as $condition_id => $condition) {
// Allow the condition to validate the form. // Allow the condition to validate the form.
$condition_values = new FormState(array( $condition_values = (new FormState())
'values' => $form_state->getValue(array('visibility', $condition_id)), ->setValues($form_state->getValue(['visibility', $condition_id]));
));
$condition->validateConfigurationForm($form, $condition_values); $condition->validateConfigurationForm($form, $condition_values);
// Update the original form values. // Update the original form values.
$form_state->setValue(array('visibility', $condition_id), $condition_values['values']); $form_state->setValue(array('visibility', $condition_id), $condition_values['values']);
...@@ -389,9 +388,8 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s ...@@ -389,9 +388,8 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
$this->configuration['cache'] = $form_state->getValue('cache'); $this->configuration['cache'] = $form_state->getValue('cache');
foreach ($this->getVisibilityConditions() as $condition_id => $condition) { foreach ($this->getVisibilityConditions() as $condition_id => $condition) {
// Allow the condition to submit the form. // Allow the condition to submit the form.
$condition_values = new FormState(array( $condition_values = (new FormState())
'values' => $form_state->getValue(array('visibility', $condition_id)), ->setValues($form_state->getValue(['visibility', $condition_id]));
));
$condition->submitConfigurationForm($form, $condition_values); $condition->submitConfigurationForm($form, $condition_values);
// Update the original form values. // Update the original form values.
$form_state->setValue(array('visibility', $condition_id), $condition_values['values']); $form_state->setValue(array('visibility', $condition_id), $condition_values['values']);
......
...@@ -49,11 +49,7 @@ public function getForm(EntityInterface $entity, $operation = 'default', array $ ...@@ -49,11 +49,7 @@ public function getForm(EntityInterface $entity, $operation = 'default', array $
$form_object = $this->entityManager->getFormObject($entity->getEntityTypeId(), $operation); $form_object = $this->entityManager->getFormObject($entity->getEntityTypeId(), $operation);
$form_object->setEntity($entity); $form_object->setEntity($entity);
$form_state = new FormState($form_state_additions); $form_state = (new FormState())->setFormState($form_state_additions);
$form_state['build_info']['callback_object'] = $form_object;
$form_state['build_info']['base_form_id'] = $form_object->getBaseFormID();
$form_state['build_info'] += array('args' => array());
return $this->formBuilder->buildForm($form_object, $form_state); return $this->formBuilder->buildForm($form_object, $form_state);
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
/** /**
* Provides an interface for a Form that has a base form ID. * Provides an interface for a Form that has a base form ID.
* *
* This will become the $form_state['build_info']['base_form_id'] used to * This will become the $form_state->getBaseInfo()['base_form_id'] used to
* generate the name of hook_form_BASE_FORM_ID_alter(). * generate the name of hook_form_BASE_FORM_ID_alter().
*/ */
interface BaseFormIdInterface extends FormInterface { interface BaseFormIdInterface extends FormInterface {
......
This diff is collapsed.
...@@ -42,7 +42,7 @@ public function getFormId($form_arg, FormStateInterface &$form_state); ...@@ -42,7 +42,7 @@ public function getFormId($form_arg, FormStateInterface &$form_state);
* function. For example, the node_edit form requires that a node object is * function. For example, the node_edit form requires that a node object is
* passed in here when it is called. These are available to implementations * passed in here when it is called. These are available to implementations
* of hook_form_alter() and hook_form_FORM_ID_alter() as the array * of hook_form_alter() and hook_form_FORM_ID_alter() as the array
* $form_state['build_info']['args']. * $form_state->getBuildInfo()['args'].
* *
* @return array * @return array
* The form array. * The form array.
...@@ -79,10 +79,10 @@ public function buildForm($form_id, FormStateInterface &$form_state); ...@@ -79,10 +79,10 @@ public function buildForm($form_id, FormStateInterface &$form_state);
* This is the key function for making multi-step forms advance from step to * This is the key function for making multi-step forms advance from step to
* step. It is called by self::processForm() when all user input processing, * step. It is called by self::processForm() when all user input processing,
* including calling validation and submission handlers, for the request is * including calling validation and submission handlers, for the request is
* finished. If a validate or submit handler set $form_state['rebuild'] to * finished. If a validate or submit handler set $form_state->isRebuilding()
* TRUE, and if other conditions don't preempt a rebuild from happening, then * to TRUE, and if other conditions don't preempt a rebuild from happening,
* this function is called to generate a new $form, the next step in the form * then this function is called to generate a new $form, the next step in the
* workflow, to be returned for rendering. * form workflow, to be returned for rendering.
* *
* Ajax form submissions are almost always multi-step workflows, so that is * Ajax form submissions are almost always multi-step workflows, so that is
* one common use-case during which form rebuilding occurs. See * one common use-case during which form rebuilding occurs. See
...@@ -98,7 +98,7 @@ public function buildForm($form_id, FormStateInterface &$form_state); ...@@ -98,7 +98,7 @@ public function buildForm($form_id, FormStateInterface &$form_state);
* (optional) A previously built $form. Used to retain the #build_id and * (optional) A previously built $form. Used to retain the #build_id and
* #action properties in Ajax callbacks and similar partial form rebuilds. * #action properties in Ajax callbacks and similar partial form rebuilds.
* The only properties copied from $old_form are the ones which both exist * The only properties copied from $old_form are the ones which both exist
* in $old_form and for which $form_state['rebuild_info']['copy'][PROPERTY] * in $old_form and for which $form_state->getRebuildInfo()['copy'][PROPERTY]
* is TRUE. If $old_form is not passed, the entire $form is rebuilt freshly. * is TRUE. If $old_form is not passed, the entire $form is rebuilt freshly.
* 'rebuild_info' needs to be a separate top-level property next to * 'rebuild_info' needs to be a separate top-level property next to
* 'build_info', since the contained data must not be cached. * 'build_info', since the contained data must not be cached.
...@@ -148,8 +148,8 @@ public function rebuildForm($form_id, FormStateInterface &$form_state, $old_form ...@@ -148,8 +148,8 @@ public function rebuildForm($form_id, FormStateInterface &$form_state, $old_form
* @endcode * @endcode
* would be called via self::submitForm() as follows: * would be called via self::submitForm() as follows:
* @code * @code
* $form_state->set('values', $my_form_values); * $form_state->setValues($my_form_values);
* $form_state['build_info']['args'] = array(&$object); * $form_state->addBuildInfo('args', [&$object]);
* drupal_form_submit('mymodule_form', $form_state); * drupal_form_submit('mymodule_form', $form_state);
* @endcode * @endcode
* For example: * For example:
...@@ -161,7 +161,7 @@ public function rebuildForm($form_id, FormStateInterface &$form_state, $old_form ...@@ -161,7 +161,7 @@ public function rebuildForm($form_id, FormStateInterface &$form_state, $old_form
* $values['pass']['pass1'] = 'password'; * $values['pass']['pass1'] = 'password';
* $values['pass']['pass2'] = 'password'; * $values['pass']['pass2'] = 'password';
* $values['op'] = t('Create new account'); * $values['op'] = t('Create new account');
* $form_state->set('values', $values); * $form_state->setValues($values);
* drupal_form_submit('user_register_form', $form_state); * drupal_form_submit('user_register_form', $form_state);
* @endcode * @endcode
*/ */
...@@ -293,8 +293,8 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state); ...@@ -293,8 +293,8 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state);
* the next submission needs to be processed, a multi-step workflow is * the next submission needs to be processed, a multi-step workflow is
* needed. This is most commonly implemented with a submit handler setting * needed. This is most commonly implemented with a submit handler setting
* persistent data within $form_state based on *validated* values in * persistent data within $form_state based on *validated* values in
* $form_state->getValues() and setting $form_state['rebuild']. The form * $form_state->getValues() and checking $form_state->isRebuilding(). The
* building functions must then be implemented to use the $form_state data * form building functions must then be implemented to use the $form_state
* to rebuild the form with the structure appropriate for the new state. * to rebuild the form with the structure appropriate for the new state.
* - Where user input must affect the rendering of the form without affecting * - Where user input must affect the rendering of the form without affecting
* its structure, the necessary conditional rendering logic should reside * its structure, the necessary conditional rendering logic should reside
......
...@@ -95,8 +95,9 @@ protected function loadCachedFormState($form_build_id, FormStateInterface $form_ ...@@ -95,8 +95,9 @@ protected function loadCachedFormState($form_build_id, FormStateInterface $form_
// If the original form is contained in include files, load the files. // If the original form is contained in include files, load the files.
// @see \Drupal\Core\Form\FormStateInterface::loadInclude() // @see \Drupal\Core\Form\FormStateInterface::loadInclude()
$form_state['build_info'] += array('files' => array()); $build_info = $form_state->getBuildInfo();
foreach ($form_state['build_info']['files'] as $file) { $build_info += ['files' => []];
foreach ($build_info['files'] as $file) {
if (is_array($file)) { if (is_array($file)) {
$file += array('type' => 'inc', 'name' => $file['module']); $file += array('type' => 'inc', 'name' => $file['module']);
$this->moduleHandler->loadInclude($file['module'], $file['type'], $file['name']); $this->moduleHandler->loadInclude($file['module'], $file['type'], $file['name']);
...@@ -109,9 +110,10 @@ protected function loadCachedFormState($form_build_id, FormStateInterface $form_ ...@@ -109,9 +110,10 @@ protected function loadCachedFormState($form_build_id, FormStateInterface $form_
// for this request. // for this request.
// @todo Ensure we are not storing an excessively large string list // @todo Ensure we are not storing an excessively large string list
// in: https://www.drupal.org/node/2295823 // in: https://www.drupal.org/node/2295823
$form_state['build_info'] += array('safe_strings' => array()); $build_info += ['safe_strings' => []];
SafeMarkup::setMultiple($form_state['build_info']['safe_strings']); SafeMarkup::setMultiple($build_info['safe_strings']);
unset($form_state['build_info']['safe_strings']); unset($build_info['safe_strings']);
$form_state->setBuildInfo($build_info);
} }
} }
......
This diff is collapsed.
...@@ -48,7 +48,7 @@ public function __construct(RequestStack $request_stack, UrlGeneratorInterface $ ...@@ -48,7 +48,7 @@ public function __construct(RequestStack $request_stack, UrlGeneratorInterface $
* {@inheritdoc} * {@inheritdoc}
*/ */
public function doSubmitForm(&$form, FormStateInterface &$form_state) { public function doSubmitForm(&$form, FormStateInterface &$form_state) {
if (!$form_state['submitted']) { if (!$form_state->isSubmitted()) {
return; return;
} }
...@@ -63,7 +63,7 @@ public function doSubmitForm(&$form, FormStateInterface &$form_state) { ...@@ -63,7 +63,7 @@ public function doSubmitForm(&$form, FormStateInterface &$form_state) {
// Store $form_state information in the batch definition. // Store $form_state information in the batch definition.
$batch['form_state'] = $form_state; $batch['form_state'] = $form_state;
$batch['progressive'] = !$form_state['programmed']; $batch['progressive'] = !$form_state->isProgrammed();
$response = batch_process(); $response = batch_process();
if ($batch['progressive']) { if ($batch['progressive']) {
return $response; return $response;
...@@ -76,15 +76,15 @@ public function doSubmitForm(&$form, FormStateInterface &$form_state) { ...@@ -76,15 +76,15 @@ public function doSubmitForm(&$form, FormStateInterface &$form_state) {
} }
// Set a flag to indicate the the form has been processed and executed. // Set a flag to indicate the the form has been processed and executed.
$form_state['executed'] = TRUE; $form_state->setExecuted();
// If no response has been set, process the form redirect. // If no response has been set, process the form redirect.
if (!$form_state->has('response') && $redirect = $this->redirectForm($form_state)) { if (!$form_state->getResponse() && $redirect = $this->redirectForm($form_state)) {
$form_state->setResponse($redirect); $form_state->setResponse($redirect);
} }
// If there is a response was set, return it instead of continuing. // If there is a response was set, return it instead of continuing.
if (($response = $form_state->get('response')) && $response instanceof Response) { if (($response = $form_state->getResponse()) && $response instanceof Response) {
return $response; return $response;
} }
} }
...@@ -94,16 +94,11 @@ public function doSubmitForm(&$form, FormStateInterface &$form_state) { ...@@ -94,16 +94,11 @@ public function doSubmitForm(&$form, FormStateInterface &$form_state) {
*/ */
public function executeSubmitHandlers(&$form, FormStateInterface &$form_state) { public function executeSubmitHandlers(&$form, FormStateInterface &$form_state) {
// If there was a button pressed, use its handlers. // If there was a button pressed, use its handlers.
if (!empty($form_state['submit_handlers'])) { $handlers = $form_state->getSubmitHandlers();
$handlers = $form_state['submit_handlers'];
}
// Otherwise, check for a form-level handler. // Otherwise, check for a form-level handler.
elseif (!empty($form['#submit'])) { if (!$handlers && !empty($form['#submit'])) {
$handlers = $form['#submit']; $handlers = $form['#submit'];
} }
else {
$handlers = array();
}
foreach ($handlers as $callback) { foreach ($handlers as $callback) {
// Check if a previous _submit handler has set a batch, but make sure we // Check if a previous _submit handler has set a batch, but make sure we
......
...@@ -68,16 +68,11 @@ public function __construct(RequestStack $request_stack, TranslationInterface $s ...@@ -68,16 +68,11 @@ public function __construct(RequestStack $request_stack, TranslationInterface $s
*/ */
public function executeValidateHandlers(&$form, FormStateInterface &$form_state) { public function executeValidateHandlers(&$form, FormStateInterface &$form_state) {
// If there was a button pressed, use its handlers. // If there was a button pressed, use its handlers.
if (isset($form_state['validate_handlers'])) { $handlers = $form_state->getValidateHandlers();
$handlers = $form_state['validate_handlers'];
}
// Otherwise, check for a form-level handler. // Otherwise, check for a form-level handler.
elseif (isset($form['#validate'])) { if (!$handlers && isset($form['#validate'])) {
$handlers = $form['#validate']; $handlers = $form['#validate'];
} }
else {
$handlers = array();
}
foreach ($handlers as $callback) { foreach ($handlers as $callback) {
call_user_func_array($form_state->prepareCallback($callback), array(&$form, &$form_state)); call_user_func_array($form_state->prepareCallback($callback), array(&$form, &$form_state));
...@@ -90,12 +85,12 @@ public function executeValidateHandlers(&$form, FormStateInterface &$form_state) ...@@ -90,12 +85,12 @@ public function executeValidateHandlers(&$form, FormStateInterface &$form_state)
public function validateForm($form_id, &$form, FormStateInterface &$form_state) { public function validateForm($form_id, &$form, FormStateInterface &$form_state) {
// If this form is flagged to always validate, ensure that previous runs of // If this form is flagged to always validate, ensure that previous runs of
// validation are ignored. // validation are ignored.
if (!empty($form_state['must_validate'])) { if ($form_state->isValidationEnforced()) {
$form_state['validation_complete'] = FALSE; $form_state->setValidationComplete(FALSE);
} }
// If this form has completed validation, do not validate again. // If this form has completed validation, do not validate again.
if (!empty($form_state['validation_complete'])) { if ($form_state->isValidationComplete()) {
return; return;
} }
...@@ -138,9 +133,10 @@ public function validateForm($form_id, &$form, FormStateInterface &$form_state) ...@@ -138,9 +133,10 @@ public function validateForm($form_id, &$form, FormStateInterface &$form_state)
protected function handleErrorsWithLimitedValidation(&$form, FormStateInterface &$form_state, $form_id) { protected function handleErrorsWithLimitedValidation(&$form, FormStateInterface &$form_state, $form_id) {
// If validation errors are limited then remove any non validated form values, // If validation errors are limited then remove any non validated form values,
// so that only values that passed validation are left for submit callbacks. // so that only values that passed validation are left for submit callbacks.
if (isset($form_state['triggering_element']['#limit_validation_errors']) && $form_state['triggering_element']['#limit_validation_errors'] !== FALSE) { $triggering_element = $form_state->getTriggeringElement();
if (isset($triggering_element['#limit_validation_errors']) && $triggering_element['#limit_validation_errors'] !== FALSE) {
$values = array(); $values = array();
foreach ($form_state['triggering_element']['#limit_validation_errors'] as $section) { foreach ($triggering_element['#limit_validation_errors'] as $section) {
// If the section exists within $form_state->getValues(), even if the // If the section exists within $form_state->getValues(), even if the
// value is NULL, copy it to $values. // value is NULL, copy it to $values.
$section_exists = NULL; $section_exists = NULL;
...@@ -153,13 +149,13 @@ protected function handleErrorsWithLimitedValidation(&$form, FormStateInterface ...@@ -153,13 +149,13 @@ protected function handleErrorsWithLimitedValidation(&$form, FormStateInterface
// allow the value of the clicked button to be retained in its normal // allow the value of the clicked button to be retained in its normal
// $form_state->getValues() locations, even if these locations are not // $form_state->getValues() locations, even if these locations are not
// included in #limit_validation_errors. // included in #limit_validation_errors.
if (!empty($form_state['triggering_element']['#is_button'])) { if (!empty($triggering_element['#is_button'])) {
$button_value = $form_state['triggering_element']['#value']; $button_value = $triggering_element['#value'];
// Like all input controls, the button value may be in the location // Like all input controls, the button value may be in the location
// dictated by #parents. If it is, copy it to $values, but do not // dictated by #parents. If it is, copy it to $values, but do not
// override what may already be in $values. // override what may already be in $values.
$parents = $form_state['triggering_element']['#parents']; $parents = $triggering_element['#parents'];
if (!NestedArray::keyExists($values, $parents) && NestedArray::getValue($form_state->getValues(), $parents) === $button_value) { if (!NestedArray::keyExists($values, $parents) && NestedArray::getValue($form_state->getValues(), $parents) === $button_value) {
NestedArray::setValue($values, $parents, $button_value); NestedArray::setValue($values, $parents, $button_value);
} }
...@@ -168,12 +164,12 @@ protected function handleErrorsWithLimitedValidation(&$form, FormStateInterface ...@@ -168,12 +164,12 @@ protected function handleErrorsWithLimitedValidation(&$form, FormStateInterface
// $form_state->getValue(BUTTON_NAME). If it's still there, after // $form_state->getValue(BUTTON_NAME). If it's still there, after
// validation handlers have run, copy it to $values, but do not override // validation handlers have run, copy it to $values, but do not override
// what may already be in $values. // what may already be in $values.
$name = $form_state['triggering_element']['#name']; $name = $triggering_element['#name'];
if (!isset($values[$name]) && $form_state->getValue($name) === $button_value) { if (!isset($values[$name]) && $form_state->getValue($name) === $button_value) {
$values[$name] = $button_value; $values[$name] = $button_value;
} }
} }
$form_state->set('values', $values); $form_state->setValues($values);
} }
} }
...@@ -191,7 +187,7 @@ protected function finalizeValidation(&$form, FormStateInterface &$form_state, $ ...@@ -191,7 +187,7 @@ protected function finalizeValidation(&$form, FormStateInterface &$form_state, $
// After validation, loop through and assign each element its errors. // After validation, loop through and assign each element its errors.
$this->setElementErrorsFromFormState($form, $form_state); $this->setElementErrorsFromFormState($form, $form_state);
// Mark this form as validated. // Mark this form as validated.
$form_state['validation_complete'] = TRUE; $form_state->setValidationComplete();
} }
/** /**
...@@ -209,7 +205,7 @@ protected function finalizeValidation(&$form, FormStateInterface &$form_state, $ ...@@ -209,7 +205,7 @@ protected function finalizeValidation(&$form, FormStateInterface &$form_state, $
* an explicit copy of the values for the sake of simplicity. Validation * an explicit copy of the values for the sake of simplicity. Validation
* handlers can also $form_state to pass information on to submit handlers. * handlers can also $form_state to pass information on to submit handlers.
* For example: * For example:
* $form_state['data_for_submission'] = $data; * $form_state->set('data_for_submission', $data);
* This technique is useful when validation requires file parsing, * This technique is useful when validation requires file parsing,
* web service requests, or other expensive requests that should * web service requests, or other expensive requests that should
* not be repeated in the submission step. * not be repeated in the submission step.
...@@ -233,7 +229,7 @@ protected function doValidateForm(&$elements, FormStateInterface &$form_state, $ ...@@ -233,7 +229,7 @@ protected function doValidateForm(&$elements, FormStateInterface &$form_state, $
} }
// Set up the limited validation for errors. // Set up the limited validation for errors.
$form_state['limit_validation_errors'] = $this->determineLimitValidationErrors($form_state); $form_state->setLimitValidationErrors($this->determineLimitValidationErrors($form_state));
// Make sure a value is passed when the field is required. // Make sure a value is passed when the field is required.
if (isset($elements['#needs_validation']) && $elements['#required']) { if (isset($elements['#needs_validation']) && $elements['#required']) {
...@@ -293,7 +289,7 @@ protected function doValidateForm(&$elements, FormStateInterface &$form_state, $ ...@@ -293,7 +289,7 @@ protected function doValidateForm(&$elements, FormStateInterface &$form_state, $
// Done validating this element, so turn off error suppression. // Done validating this element, so turn off error suppression.
// self::doValidateForm() turns it on again when starting on the next // self::doValidateForm() turns it on again when starting on the next
// element, if it's still appropriate to do so. // element, if it's still appropriate to do so.
$form_state['limit_validation_errors'] = NULL; $form_state->setLimitValidationErrors(NULL);
} }
/** /**
...@@ -307,7 +303,7 @@ protected function doValidateForm(&$elements, FormStateInterface &$form_state, $ ...@@ -307,7 +303,7 @@ protected function doValidateForm(&$elements, FormStateInterface &$form_state, $
* an explicit copy of the values for the sake of simplicity. Validation * an explicit copy of the values for the sake of simplicity. Validation
* handlers can also $form_state to pass information on to submit handlers. * handlers can also $form_state to pass information on to submit handlers.
* For example: * For example:
* $form_state['data_for_submission'] = $data; * $form_state->set('data_for_submission', $data);
* This technique is useful when validation requires file parsing, * This technique is useful when validation requires file parsing,
* web service requests, or other expensive requests that should * web service requests, or other expensive requests that should
* not be repeated in the submission step. * not be repeated in the submission step.
...@@ -374,8 +370,9 @@ protected function determineLimitValidationErrors(FormStateInterface &$form_stat ...@@ -374,8 +370,9 @@ protected function determineLimitValidationErrors(FormStateInterface &$form_stat
// is ignored if submit handlers will run, but the element doesn't have a // is ignored if submit handlers will run, but the element doesn't have a
// #submit property, because it's too large a security risk to have any // #submit property, because it's too large a security risk to have any
// invalid user input when executing form-level submit handlers. // invalid user input when executing form-level submit handlers.
if (isset($form_state['triggering_element']['#limit_validation_errors']) && ($form_state['triggering_element']['#limit_validation_errors'] !== FALSE) && !($form_state['submitted'] && !isset($form_state['triggering_element']['#submit']))) { $triggering_element = $form_state->getTriggeringElement();
return $form_state['triggering_element']['#limit_validation_errors']; if (isset($triggering_element['#limit_validation_errors']) && ($triggering_element['#limit_validation_errors'] !== FALSE) && !($form_state->isSubmitted() && !isset($triggering_element['#submit']))) {
return $triggering_element['#limit_validation_errors'];
} }
// If submit handlers won't run (due to the submission having been // If submit handlers won't run (due to the submission having been
// triggered by an element whose #executes_submit_callback property isn't // triggered by an element whose #executes_submit_callback property isn't
...@@ -386,7 +383,7 @@ protected function determineLimitValidationErrors(FormStateInterface &$form_stat ...@@ -386,7 +383,7 @@ protected function determineLimitValidationErrors(FormStateInterface &$form_stat
// types, #limit_validation_errors defaults to FALSE (via // types, #limit_validation_errors defaults to FALSE (via
// system_element_info()), so that full validation is their default // system_element_info()), so that full validation is their default
// behavior. // behavior.
elseif (isset($form_state['triggering_element']) && !isset($form_state['triggering_element']['#limit_validation_errors']) && !$form_state['submitted']) { elseif ($triggering_element && !isset($triggering_element['#limit_validation_errors']) && !$form_state->isSubmitted()) {
return array(); return array();
} }
// As an extra security measure, explicitly turn off error suppression if // As an extra security measure, explicitly turn off error suppression if
......
...@@ -47,7 +47,7 @@ public function executeValidateHandlers(&$form, FormStateInterface &$form_state) ...@@ -47,7 +47,7 @@ public function executeValidateHandlers(&$form, FormStateInterface &$form_state)
* an explicit copy of the values for the sake of simplicity. Validation * an explicit copy of the values for the sake of simplicity. Validation
* handlers can also use $form_state to pass information on to submit * handlers can also use $form_state to pass information on to submit
* handlers. For example: * handlers. For example:
* $form_state['data_for_submission'] = $data; * $form_state->set('data_for_submission', $data);
* This technique is useful when validation requires file parsing, * This technique is useful when validation requires file parsing,
* web service requests, or other expensive requests that should * web service requests, or other expensive requests that should
* not be repeated in the submission step. * not be repeated in the submission step.
......
...@@ -74,7 +74,10 @@ protected function setUp() { ...@@ -74,7 +74,10 @@ protected function setUp() {
*/ */
public function testSettingsForm() { public function testSettingsForm() {
// Emulate a form state of a sumbitted form. // Emulate a form state of a sumbitted form.
$form_state = new FormState(array('values' => array('dummy_length' => '', 'aggregator_allowed_html_tags' => ''))); $form_state = (new FormState())->setValues([
'dummy_length' => '',
'aggregator_allowed_html_tags' => '',
]);
$test_processor = $this->getMock( $test_processor = $this->getMock(
'Drupal\aggregator_test\Plugin\aggregator\processor\TestProcessor', 'Drupal\aggregator_test\Plugin\aggregator\processor\TestProcessor',
......
...@@ -149,9 +149,7 @@ public function validate(array $form, FormStateInterface $form_state) { ...@@ -149,9 +149,7 @@ public function validate(array $form, FormStateInterface $form_state) {
// The Block Entity form puts all block plugin form elements in the // The Block Entity form puts all block plugin form elements in the
// settings form element, so just pass that to the block for validation. // settings form element, so just pass that to the block for validation.
$settings = new FormState(array( $settings = (new FormState())->setValues($form_state->getValue('settings'));
'values' => $form_state->getValue('settings')
));
// Call the plugin validate handler. // Call the plugin validate handler.
$this->entity->getPlugin()->validateConfigurationForm($form, $settings); $this->entity->getPlugin()->validateConfigurationForm($form, $settings);
// Update the original form values. // Update the original form values.
...@@ -168,9 +166,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ...@@ -168,9 +166,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// The Block Entity form puts all block plugin form elements in the // The Block Entity form puts all block plugin form elements in the
// settings form element, so just pass that to the block for submission. // settings form element, so just pass that to the block for submission.
// @todo Find a way to avoid this manipulation. // @todo Find a way to avoid this manipulation.
$settings = new FormState(array( $settings = (new FormState())->setValues($form_state->getValue('settings'));
'values' => $form_state->getValue('settings'),
));
// Call the plugin submit handler. // Call the plugin submit handler.
$entity->getPlugin()->submitConfigurationForm($form, $settings); $entity->getPlugin()->submitConfigurationForm($form, $settings);
......
...@@ -123,10 +123,10 @@ public function buildForm(array $form, FormStateInterface $form_state, $config_t ...@@ -123,10 +123,10 @@ public function buildForm(array $form, FormStateInterface $form_state, $config_t
'#suffix' => '</div>', '#suffix' => '</div>',
); );
if ($config_type && $config_name) { if ($config_type && $config_name) {
$fake_form_state = new FormState(array('values' => array( $fake_form_state = (new FormState())->setValues([
'config_type' => $config_type, 'config_type' => $config_type,
'config_name' => $config_name, 'config_name' => $config_name,
))); ]);
$form['export'] = $this->updateExport($form, $fake_form_state); $form['export'] = $this->updateExport($form, $fake_form_state);
} }
return $form; return $form;
......
...@@ -106,9 +106,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ImageStyl ...@@ -106,9 +106,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ImageStyl
public function validateForm(array &$form, FormStateInterface $form_state) { public function validateForm(array &$form, FormStateInterface $form_state) {
// The image effect configuration is stored in the 'data' key in the form, // The image effect configuration is stored in the 'data' key in the form,
// pass that through for validation. // pass that through for validation.
$effect_data = new FormState(array( $effect_data = (new FormState())->setValues($form_state->getValue('data'));
'values' => $form_state->getValue('data'),
));
$this->imageEffect->validateConfigurationForm($form, $effect_data); $this->imageEffect->validateConfigurationForm($form, $effect_data);
// Update the original form values. // Update the original form values.
$form_state->setValue('data', $effect_data['values']); $form_state->setValue('data', $effect_data['values']);
...@@ -122,9 +120,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ...@@ -122,9 +120,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// The image effect configuration is stored in the 'data' key in the form, // The image effect configuration is stored in the 'data' key in the form,
// pass that through for submission. // pass that through for submission.
$effect_data = new FormState(array( $effect_data = (new FormState())->setValues($form_state->getValue('data'));
'values' => $form_state->getValue('data'),
));
$this->imageEffect->submitConfigurationForm($form, $effect_data); $this->imageEffect->submitConfigurationForm($form, $effect_data);
// Update the original form values. // Update the original form values.
$form_state->setValue('data', $effect_data['values']); $form_state->setValue('data', $effect_data['values']);
......
...@@ -214,7 +214,10 @@ protected function buildOverviewForm(array &$form, FormStateInterface $form_stat ...@@ -214,7 +214,10 @@ protected function buildOverviewForm(array &$form, FormStateInterface $form_stat
// section. // section.
$form['#tree'] = TRUE; $form['#tree'] = TRUE;
$form['#theme'] = 'menu_overview_form'; $form['#theme'] = 'menu_overview_form';
$form_state->setIfNotExists('menu_overview_form_parents', array());
if (!$form_state->has('menu_overview_form_parents')) {
$form_state->set('menu_overview_form_parents', []);
}
$form['#attached']['css'] = array(drupal_get_path('module', 'menu') . '/css/menu.admin.css'); $form['#attached']['css'] = array(drupal_get_path('module', 'menu') . '/css/menu.admin.css');
......
...@@ -178,13 +178,10 @@ public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view ...@@ -178,13 +178,10 @@ public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view
$this->tempStoreFactory->get('quickedit')->set($entity->uuid(), $entity); $this->tempStoreFactory->get('quickedit')->set($entity->uuid(), $entity);
} }
$form_state = new FormState(array( $form_state = (new FormState())
'langcode' => $langcode, ->set('langcode', $langcode)
'no_redirect' => TRUE, ->disableRedirect()
'build_info' => array( ->addBuildInfo('args', [$entity, $field_name]);
'args' => array($entity, $field_name),
),
));
$form = $this->formBuilder()->buildForm('Drupal\quickedit\Form\QuickEditFieldForm', $form_state); $form = $this->formBuilder()->buildForm('Drupal\quickedit\Form\QuickEditFieldForm', $form_state);
if (!empty($form_state['executed'])) { if (!empty($form_state['executed'])) {
......
...@@ -271,7 +271,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ...@@ -271,7 +271,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
} }
$form_execute = array(); $form_execute = array();
$form_state_execute = new FormState(array('values' => array())); $form_state_execute = new FormState();
foreach ($classes as $class) { foreach ($classes as $class) {
$form_state_execute['values']['tests'][$class] = $class; $form_state_execute['values']['tests'][$class] = $class;
} }
......
...@@ -147,14 +147,13 @@ public function validateForm(array &$form, FormStateInterface $form_state) {} ...@@ -147,14 +147,13 @@ public function validateForm(array &$form, FormStateInterface $form_state) {}
* Tests that default handlers are added even if custom are specified. * Tests that default handlers are added even if custom are specified.
*/ */
public function testPathElement() {