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) {
function install_get_form($form_id, array &$install_state) {
// Ensure the form will not redirect, since install_run_tasks() uses a custom
// redirection logic.
$form_state = new FormState(array(
'build_info' => array(
'args' => array(&$install_state),
),
'no_redirect' => TRUE,
));
$form_state = (new FormState())
->addBuildInfo('args', [&$install_state])
->disableRedirect();
$form_builder = \Drupal::formBuilder();
if ($install_state['interactive']) {
$form = $form_builder->buildForm($form_id, $form_state);
......@@ -827,7 +824,7 @@ function install_get_form($form_id, array &$install_state) {
// values taken from the installation state.
$install_form_id = $form_builder->getFormId($form_id, $form_state);
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);
......
......@@ -356,9 +356,8 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
foreach ($this->getVisibilityConditions() as $condition_id => $condition) {
// Allow the condition to validate the form.
$condition_values = new FormState(array(
'values' => $form_state->getValue(array('visibility', $condition_id)),
));
$condition_values = (new FormState())
->setValues($form_state->getValue(['visibility', $condition_id]));
$condition->validateConfigurationForm($form, $condition_values);
// Update the original form values.
$form_state->setValue(array('visibility', $condition_id), $condition_values['values']);
......@@ -389,9 +388,8 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
$this->configuration['cache'] = $form_state->getValue('cache');
foreach ($this->getVisibilityConditions() as $condition_id => $condition) {
// Allow the condition to submit the form.
$condition_values = new FormState(array(
'values' => $form_state->getValue(array('visibility', $condition_id)),
));
$condition_values = (new FormState())
->setValues($form_state->getValue(['visibility', $condition_id]));
$condition->submitConfigurationForm($form, $condition_values);
// Update the original form values.
$form_state->setValue(array('visibility', $condition_id), $condition_values['values']);
......
......@@ -49,11 +49,7 @@ public function getForm(EntityInterface $entity, $operation = 'default', array $
$form_object = $this->entityManager->getFormObject($entity->getEntityTypeId(), $operation);
$form_object->setEntity($entity);
$form_state = new FormState($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());
$form_state = (new FormState())->setFormState($form_state_additions);
return $this->formBuilder->buildForm($form_object, $form_state);
}
......
......@@ -10,7 +10,7 @@
/**
* 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().
*/
interface BaseFormIdInterface extends FormInterface {
......
This diff is collapsed.
......@@ -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
* 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
* $form_state['build_info']['args'].
* $form_state->getBuildInfo()['args'].
*
* @return array
* The form array.
......@@ -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
* step. It is called by self::processForm() when all user input processing,
* including calling validation and submission handlers, for the request is
* finished. If a validate or submit handler set $form_state['rebuild'] to
* TRUE, and if other conditions don't preempt a rebuild from happening, then
* this function is called to generate a new $form, the next step in the form
* workflow, to be returned for rendering.
* finished. If a validate or submit handler set $form_state->isRebuilding()
* to TRUE, and if other conditions don't preempt a rebuild from happening,
* then this function is called to generate a new $form, the next step in the
* form workflow, to be returned for rendering.
*
* Ajax form submissions are almost always multi-step workflows, so that is
* one common use-case during which form rebuilding occurs. See
......@@ -98,7 +98,7 @@ public function buildForm($form_id, FormStateInterface &$form_state);
* (optional) A previously built $form. Used to retain the #build_id and
* #action properties in Ajax callbacks and similar partial form rebuilds.
* 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.
* 'rebuild_info' needs to be a separate top-level property next to
* 'build_info', since the contained data must not be cached.
......@@ -148,8 +148,8 @@ public function rebuildForm($form_id, FormStateInterface &$form_state, $old_form
* @endcode
* would be called via self::submitForm() as follows:
* @code
* $form_state->set('values', $my_form_values);
* $form_state['build_info']['args'] = array(&$object);
* $form_state->setValues($my_form_values);
* $form_state->addBuildInfo('args', [&$object]);
* drupal_form_submit('mymodule_form', $form_state);
* @endcode
* For example:
......@@ -161,7 +161,7 @@ public function rebuildForm($form_id, FormStateInterface &$form_state, $old_form
* $values['pass']['pass1'] = 'password';
* $values['pass']['pass2'] = 'password';
* $values['op'] = t('Create new account');
* $form_state->set('values', $values);
* $form_state->setValues($values);
* drupal_form_submit('user_register_form', $form_state);
* @endcode
*/
......@@ -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
* needed. This is most commonly implemented with a submit handler setting
* persistent data within $form_state based on *validated* values in
* $form_state->getValues() and setting $form_state['rebuild']. The form
* building functions must then be implemented to use the $form_state data
* $form_state->getValues() and checking $form_state->isRebuilding(). The
* form building functions must then be implemented to use the $form_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
* its structure, the necessary conditional rendering logic should reside
......
......@@ -95,8 +95,9 @@ protected function loadCachedFormState($form_build_id, FormStateInterface $form_
// If the original form is contained in include files, load the files.
// @see \Drupal\Core\Form\FormStateInterface::loadInclude()
$form_state['build_info'] += array('files' => array());
foreach ($form_state['build_info']['files'] as $file) {
$build_info = $form_state->getBuildInfo();
$build_info += ['files' => []];
foreach ($build_info['files'] as $file) {
if (is_array($file)) {
$file += array('type' => 'inc', 'name' => $file['module']);
$this->moduleHandler->loadInclude($file['module'], $file['type'], $file['name']);
......@@ -109,9 +110,10 @@ protected function loadCachedFormState($form_build_id, FormStateInterface $form_
// for this request.
// @todo Ensure we are not storing an excessively large string list
// in: https://www.drupal.org/node/2295823
$form_state['build_info'] += array('safe_strings' => array());
SafeMarkup::setMultiple($form_state['build_info']['safe_strings']);
unset($form_state['build_info']['safe_strings']);
$build_info += ['safe_strings' => []];
SafeMarkup::setMultiple($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 $
* {@inheritdoc}
*/
public function doSubmitForm(&$form, FormStateInterface &$form_state) {
if (!$form_state['submitted']) {
if (!$form_state->isSubmitted()) {
return;
}
......@@ -63,7 +63,7 @@ public function doSubmitForm(&$form, FormStateInterface &$form_state) {
// Store $form_state information in the batch definition.
$batch['form_state'] = $form_state;
$batch['progressive'] = !$form_state['programmed'];
$batch['progressive'] = !$form_state->isProgrammed();
$response = batch_process();
if ($batch['progressive']) {
return $response;
......@@ -76,15 +76,15 @@ public function doSubmitForm(&$form, FormStateInterface &$form_state) {
}
// 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 (!$form_state->has('response') && $redirect = $this->redirectForm($form_state)) {
if (!$form_state->getResponse() && $redirect = $this->redirectForm($form_state)) {
$form_state->setResponse($redirect);
}
// 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;
}
}
......@@ -94,16 +94,11 @@ public function doSubmitForm(&$form, FormStateInterface &$form_state) {
*/
public function executeSubmitHandlers(&$form, FormStateInterface &$form_state) {
// If there was a button pressed, use its handlers.
if (!empty($form_state['submit_handlers'])) {
$handlers = $form_state['submit_handlers'];
}
$handlers = $form_state->getSubmitHandlers();
// Otherwise, check for a form-level handler.
elseif (!empty($form['#submit'])) {
if (!$handlers && !empty($form['#submit'])) {
$handlers = $form['#submit'];
}
else {
$handlers = array();
}
foreach ($handlers as $callback) {
// 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
*/
public function executeValidateHandlers(&$form, FormStateInterface &$form_state) {
// If there was a button pressed, use its handlers.
if (isset($form_state['validate_handlers'])) {
$handlers = $form_state['validate_handlers'];
}
$handlers = $form_state->getValidateHandlers();
// Otherwise, check for a form-level handler.
elseif (isset($form['#validate'])) {
if (!$handlers && isset($form['#validate'])) {
$handlers = $form['#validate'];
}
else {
$handlers = array();
}
foreach ($handlers as $callback) {
call_user_func_array($form_state->prepareCallback($callback), array(&$form, &$form_state));
......@@ -90,12 +85,12 @@ public function executeValidateHandlers(&$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
// validation are ignored.
if (!empty($form_state['must_validate'])) {
$form_state['validation_complete'] = FALSE;
if ($form_state->isValidationEnforced()) {
$form_state->setValidationComplete(FALSE);
}
// If this form has completed validation, do not validate again.
if (!empty($form_state['validation_complete'])) {
if ($form_state->isValidationComplete()) {
return;
}
......@@ -138,9 +133,10 @@ public function validateForm($form_id, &$form, FormStateInterface &$form_state)
protected function handleErrorsWithLimitedValidation(&$form, FormStateInterface &$form_state, $form_id) {
// If validation errors are limited then remove any non validated form values,
// 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();
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
// value is NULL, copy it to $values.
$section_exists = NULL;
......@@ -153,13 +149,13 @@ protected function handleErrorsWithLimitedValidation(&$form, FormStateInterface
// allow the value of the clicked button to be retained in its normal
// $form_state->getValues() locations, even if these locations are not
// included in #limit_validation_errors.
if (!empty($form_state['triggering_element']['#is_button'])) {
$button_value = $form_state['triggering_element']['#value'];
if (!empty($triggering_element['#is_button'])) {
$button_value = $triggering_element['#value'];
// 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
// 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) {
NestedArray::setValue($values, $parents, $button_value);
}
......@@ -168,12 +164,12 @@ protected function handleErrorsWithLimitedValidation(&$form, FormStateInterface
// $form_state->getValue(BUTTON_NAME). If it's still there, after
// validation handlers have run, copy it to $values, but do not override
// 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) {
$values[$name] = $button_value;
}
}
$form_state->set('values', $values);
$form_state->setValues($values);
}
}
......@@ -191,7 +187,7 @@ protected function finalizeValidation(&$form, FormStateInterface &$form_state, $
// After validation, loop through and assign each element its errors.
$this->setElementErrorsFromFormState($form, $form_state);
// Mark this form as validated.
$form_state['validation_complete'] = TRUE;
$form_state->setValidationComplete();
}
/**
......@@ -209,7 +205,7 @@ protected function finalizeValidation(&$form, FormStateInterface &$form_state, $
* an explicit copy of the values for the sake of simplicity. Validation
* handlers can also $form_state to pass information on to submit 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,
* web service requests, or other expensive requests that should
* not be repeated in the submission step.
......@@ -233,7 +229,7 @@ protected function doValidateForm(&$elements, FormStateInterface &$form_state, $
}
// 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.
if (isset($elements['#needs_validation']) && $elements['#required']) {
......@@ -293,7 +289,7 @@ protected function doValidateForm(&$elements, FormStateInterface &$form_state, $
// Done validating this element, so turn off error suppression.
// self::doValidateForm() turns it on again when starting on the next
// 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, $
* an explicit copy of the values for the sake of simplicity. Validation
* handlers can also $form_state to pass information on to submit 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,
* web service requests, or other expensive requests that should
* not be repeated in the submission step.
......@@ -374,8 +370,9 @@ protected function determineLimitValidationErrors(FormStateInterface &$form_stat
// 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
// 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']))) {
return $form_state['triggering_element']['#limit_validation_errors'];
$triggering_element = $form_state->getTriggeringElement();
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
// triggered by an element whose #executes_submit_callback property isn't
......@@ -386,7 +383,7 @@ protected function determineLimitValidationErrors(FormStateInterface &$form_stat
// types, #limit_validation_errors defaults to FALSE (via
// system_element_info()), so that full validation is their default
// 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();
}
// As an extra security measure, explicitly turn off error suppression if
......
......@@ -47,7 +47,7 @@ public function executeValidateHandlers(&$form, FormStateInterface &$form_state)
* 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. For example:
* $form_state['data_for_submission'] = $data;
* $form_state->set('data_for_submission', $data);
* This technique is useful when validation requires file parsing,
* web service requests, or other expensive requests that should
* not be repeated in the submission step.
......
......@@ -74,7 +74,10 @@ protected function setUp() {
*/
public function testSettingsForm() {
// 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(
'Drupal\aggregator_test\Plugin\aggregator\processor\TestProcessor',
......
......@@ -149,9 +149,7 @@ public function validate(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.
$settings = new FormState(array(
'values' => $form_state->getValue('settings')
));
$settings = (new FormState())->setValues($form_state->getValue('settings'));
// Call the plugin validate handler.
$this->entity->getPlugin()->validateConfigurationForm($form, $settings);
// Update the original form values.
......@@ -168,9 +166,7 @@ public function submitForm(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 submission.
// @todo Find a way to avoid this manipulation.
$settings = new FormState(array(
'values' => $form_state->getValue('settings'),
));
$settings = (new FormState())->setValues($form_state->getValue('settings'));
// Call the plugin submit handler.
$entity->getPlugin()->submitConfigurationForm($form, $settings);
......
......@@ -123,10 +123,10 @@ public function buildForm(array $form, FormStateInterface $form_state, $config_t
'#suffix' => '</div>',
);
if ($config_type && $config_name) {
$fake_form_state = new FormState(array('values' => array(
$fake_form_state = (new FormState())->setValues([
'config_type' => $config_type,
'config_name' => $config_name,
)));
]);
$form['export'] = $this->updateExport($form, $fake_form_state);
}
return $form;
......
......@@ -106,9 +106,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.
$effect_data = new FormState(array(
'values' => $form_state->getValue('data'),
));
$effect_data = (new FormState())->setValues($form_state->getValue('data'));
$this->imageEffect->validateConfigurationForm($form, $effect_data);
// Update the original form values.
$form_state->setValue('data', $effect_data['values']);
......@@ -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,
// pass that through for submission.
$effect_data = new FormState(array(
'values' => $form_state->getValue('data'),
));
$effect_data = (new FormState())->setValues($form_state->getValue('data'));
$this->imageEffect->submitConfigurationForm($form, $effect_data);
// Update the original form values.
$form_state->setValue('data', $effect_data['values']);
......
......@@ -214,7 +214,10 @@ protected function buildOverviewForm(array &$form, FormStateInterface $form_stat
// section.
$form['#tree'] = TRUE;
$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');
......
......@@ -178,13 +178,10 @@ public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view
$this->tempStoreFactory->get('quickedit')->set($entity->uuid(), $entity);
}
$form_state = new FormState(array(
'langcode' => $langcode,
'no_redirect' => TRUE,
'build_info' => array(
'args' => array($entity, $field_name),
),
));
$form_state = (new FormState())
->set('langcode', $langcode)
->disableRedirect()
->addBuildInfo('args', [$entity, $field_name]);
$form = $this->formBuilder()->buildForm('Drupal\quickedit\Form\QuickEditFieldForm', $form_state);
if (!empty($form_state['executed'])) {
......
......@@ -271,7 +271,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
}
$form_execute = array();
$form_state_execute = new FormState(array('values' => array()));
$form_state_execute = new FormState();
foreach ($classes as $class) {
$form_state_execute['values']['tests'][$class] = $class;
}
......
......@@ -147,14 +147,13 @@ public function validateForm(array &$form, FormStateInterface $form_state) {}
* Tests that default handlers are added even if custom are specified.
*/
public function testPathElement() {
$form_state = new FormState(array(
'values' => array(
$form_state = (new FormState())
->setValues([
'required_validate' => 'user/' . $this->testUser->id(),
'required_non_validate' => 'magic-ponies',
'required_validate_route' => 'user/' . $this->testUser->id(),
'required_validate_url' => 'user/' . $this->testUser->id(),
),
));
]);
$form_builder = $this->container->get('form_builder');
$form_builder->submitForm($this, $form_state);
......@@ -175,13 +174,12 @@ public function testPathElement() {
));
// Test #required.
$form_state = new FormState(array(
'values' => array(
$form_state = (new FormState())
->setValues([
'required_non_validate' => 'magic-ponies',
'required_validate_route' => 'user/' . $this->testUser->id(),
'required_validate_url' => 'user/' . $this->testUser->id(),
),
));
]);
$form_builder->submitForm($this, $form_state);
$errors = $form_state->getErrors();
// Should be missing 'required_validate' field.
......@@ -189,14 +187,13 @@ public function testPathElement() {
$this->assertEqual($errors, array('required_validate' => t('!name field is required.', array('!name' => 'required_validate'))));
// Test invalid parameters.
$form_state = new FormState(array(
'values' => array(
$form_state = (new FormState())
->setValues([
'required_validate' => 'user/74',
'required_non_validate' => 'magic-ponies',
'required_validate_route' => 'user/74',
'required_validate_url' => 'user/74',
),
));
]);
$form_builder = $this->container->get('form_builder');
$form_builder->submitForm($this, $form_state);
......
......@@ -75,7 +75,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
* Tests that default handlers are added even if custom are specified.
*/
function testDefaultAndCustomHandlers() {
$form_state = new FormState(array('values' => array()));
$form_state = new FormState();
$form_builder = $this->container->get('form_builder');
$form_builder->submitForm($this, $form_state);
......
......@@ -72,7 +72,7 @@ function testSubmissionWorkflow() {
*/
private function submitForm($values, $valid_input) {
// Programmatically submit the given values.
$form_state = new FormState(array('values' => $values));
$form_state = (new FormState())->setValues($values);
\Drupal::formBuilder()->submitForm('\Drupal\form_test\Form\FormTestProgrammaticForm', $form_state);
// Check that the form returns an error when expected, and vice versa.
......@@ -99,10 +99,10 @@ private function submitForm($values, $valid_input) {
* Test the programmed_bypass_access_check flag.
*/
public function testProgrammaticAccessBypass() {
$form_state = new FormState(array('values' => array(
$form_state = (new FormState())->setValues([
'textfield' => 'dummy value',
'field_restricted' => 'dummy value'
)));
]);
// Programmatically submit the form with a value for the restricted field.
// Since programmed_bypass_access_check is set to TRUE by default, the
......
......@@ -52,7 +52,7 @@ public function testConfigForm() {
foreach ($this->values as $form_key => $data) {
$values[$form_key] = $data['#value'];
}
$form_state = new FormState(array('values' => $values));
$form_state = (new FormState())->setValues($values);
\Drupal::formBuilder()->submitForm($this->form, $form_state);
// Check that the form returns an error when expected, and vice versa.
......
......@@ -85,9 +85,9 @@ public function testNoForm() {
* Render array containing markup.
*/
function testProgrammatic($value = 1) {
$form_state = new FormState(array(
'values' => array('value' => $value)
));
$form_state = (new FormState())->setValues([
'value' => $value,
]);
\Drupal::formBuilder()->submitForm('Drupal\batch_test\Form\BatchTestChainedForm', $form_state);
return array(
'success' => array(
......
......@@ -17,12 +17,14 @@
*/
function views_ajax_form_wrapper($form_class, FormStateInterface &$form_state) {
// This won't override settings already in.
$form_state->setIfNotExists('rerender', FALSE);
$form_state->setIfNotExists('no_redirect', !empty($form_state['ajax']));
$form_state->setIfNotExists('no_cache', TRUE);
$form_state->setIfNotExists('build_info', array(
'args' => array(),
));
if (!$form_state->has('rerender')) {
$form_state->set('rerender', FALSE);
}
// Do not overwrite if the redirect has been disabled.
if (!$form_state->isRedirectDisabled()) {
$form_state->disableRedirect(!empty($form_state['ajax']));
}
$form_state->disableCache();
$form = \Drupal::formBuilder()->buildForm($form_class, $form_state);
$output = drupal_render($form);
......
......@@ -129,14 +129,15 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
*/
public function renderExposedForm($block = FALSE) {
// Deal with any exposed filters we may have, before building.
$form_state = new FormState(array(
'view' => &$this->view,
'display' => &$this->view->display_handler->display,
'method' => 'get',
'rerender' => TRUE,
'no_redirect' => TRUE,
'always_process' => TRUE,
));
$form_state = (new FormState())
->setStorage([
'view' => $this->view,
'display' => &$this->view->display_handler->display,
'rerender' => TRUE,
])
->setMethod('get')
->setAlwaysProcess()
->disableRedirect();
// Some types of displays (eg. attachments) may wish to use the exposed
// filters of their parent displays instead of showing an additional
......
......@@ -63,12 +63,12 @@ public function testCreateView() {
));
language_save($language);
$form_state->set('values', array(
$form_state->setValues([
'id' => $random_id,
'label' => $random_label,
'description' => $random_description,
'base_table' => 'views_test_data',
));
]);
$this->wizard->validateView($form, $form_state);
$view = $this->wizard->createView($form, $form_state);
......
......@@ -66,20 +66,16 @@ protected function setType($type) {
public function getFormState(ViewStorageInterface $view, $display_id, $js) {
// $js may already have been converted to a Boolean.
$ajax = is_string($js) ? $js === 'ajax' : $js;
return new FormState(array(
'form_id' => $this->getFormId(),
'form_key' => $this->getFormKey(),
'ajax' => $ajax,
'display_id' => $display_id,
'view' => $view,
'type' => $this->type,
'id' => $this->id,
'no_redirect' => TRUE,
'build_info' => array(
'args' => array(),
'callback_object' => $this,
),
));
return (new FormState())
->set('form_id', $this->getFormId())
->set('form_key', $this->getFormKey())
->set('ajax', $ajax)
->set('display_id', $display_id)
->set('view', $view)
->set('type', $this->type)
->set('id', $this->id)
->disableRedirect()
->addBuildInfo('callback_object', $this);
}
/**
......
......@@ -46,7 +46,7 @@ public function testGetFormIdWithClassName() {