Commit 789de472 authored by alexpott's avatar alexpott

Issue #2354597 by esod, YesCT, vadim.hirbu, ashutoshsngh: Remove usage of form_set_value().

parent 56189b76
......@@ -108,7 +108,7 @@ public static function validateElement(array $element, FormStateInterface $form_
foreach ($values as $value) {
$items[] = array($element['#key_column'] => $value);
}
form_set_value($element, $items, $form_state);
$form_state->setValueForElement($element, $items);
}
/**
......
......@@ -227,7 +227,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
}
// Store the decoded version of the submitted import.
form_set_value($form['import'], $data, $form_state);
$form_state->setValueForElement($form['import'], $data);
}
/**
......
......@@ -150,7 +150,7 @@ function _entity_reference_form_process_merge_parent($element) {
*/
function _entity_reference_element_validate_filter(&$element, FormStateInterface $form_state) {
$element['#value'] = array_filter($element['#value']);
form_set_value($element, $element['#value'], $form_state);
$form_state->setValueForElement($element, $element['#value']);
}
/**
......
......@@ -80,9 +80,9 @@ public function elementValidate($element, FormStateInterface $form_state, $form)
}
}
};
// Change the element['#parents'], so in form_set_value() we
// populate the correct key.
// Change the element['#parents'], so in setValueForElement() we populate
// the correct key.
array_pop($element['#parents']);
form_set_value($element, $value, $form_state);
$form_state->setValueForElement($element, $value);
}
}
......@@ -89,11 +89,11 @@ public function elementValidate($element, FormStateInterface $form_state, $form)
// Keep the weight property.
'_weight' => $element['#weight'],
);
// Change the element['#parents'], so in form_set_value() we
// Change the element['#parents'], so in setValueForElement() we
// populate the correct key.
array_pop($element['#parents']);
}
}
form_set_value($element, $value, $form_state);
$form_state->setValueForElement($element, $value);
}
}
......@@ -94,7 +94,7 @@ public static function multipleValidate($element, FormStateInterface $form_state
foreach ($values as $value) {
$items[] = array('value' => $value);
}
form_set_value($element, $items, $form_state);
$form_state->setValueForElement($element, $items);
}
/**
......
......@@ -318,7 +318,7 @@ protected function validateAddNew(array $form, FormStateInterface $form_state) {
// Add the field prefix.
$field_name = \Drupal::config('field_ui.settings')->get('field_prefix') . $field_name;
form_set_value($form['fields']['_add_new_field']['field_name'], $field_name, $form_state);
$form_state->setValueForElement($form['fields']['_add_new_field']['field_name'], $field_name);
}
// Missing field type.
......
......@@ -41,7 +41,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t
public function validate(array $form, FormStateInterface $form_state) {
parent::validate($form, $form_state);
form_set_value($form['id'], $this->targetEntityTypeId . '.' . $form_state->getValue('id'), $form_state);
$form_state->setValueForElement($form['id'], $this->targetEntityTypeId . '.' . $form_state->getValue('id'));
}
/**
......
......@@ -1117,7 +1117,7 @@ function file_managed_file_submit($form, FormStateInterface $form_state) {
// FormState::$input must be updated so that
// \Drupal\file\Element\ManagedFile::valueCallback() has correct information
// during the rebuild.
form_set_value($element['fids'], implode(' ', $fids), $form_state);
$form_state->setValueForElement($element['fids'], implode(' ', $fids));
NestedArray::setValue($form_state->getUserInput(), $element['fids']['#parents'], implode(' ', $fids));
}
......
......@@ -214,7 +214,7 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
public static function validateDirectory($element, FormStateInterface $form_state) {
// Strip slashes from the beginning and end of $element['file_directory'].
$value = trim($element['#value'], '\\/');
form_set_value($element, $value, $form_state);
$form_state->setValueForElement($element, $value);
}
/**
......@@ -236,7 +236,7 @@ public static function validateExtensions($element, FormStateInterface $form_sta
$form_state->setError($element, t('The list of allowed extensions is not valid, be sure to exclude leading dots and to separate extensions with a comma or space.'));
}
else {
form_set_value($element, $extensions, $form_state);
$form_state->setValueForElement($element, $extensions);
}
}
}
......
......@@ -218,8 +218,8 @@ public function validate(array $form, FormStateInterface $form_state) {
$format_name = trim($form_state->getValue('name'));
// Ensure that the values to be saved later are exactly the ones validated.
form_set_value($form['format'], $format_format, $form_state);
form_set_value($form['name'], $format_name, $form_state);
$form_state->setValueForElement($form['format'], $format_format);
$form_state->setValueForElement($form['name'], $format_name);
$format_exists = $this->queryFactory
->get('filter_format')
......
......@@ -379,10 +379,10 @@ public static function validateResolution($element, FormStateInterface $form_sta
return;
}
}
form_set_value($element, $element['x']['#value'] . 'x' . $element['y']['#value'], $form_state);
$form_state->setValueForElement($element, $element['x']['#value'] . 'x' . $element['y']['#value']);
}
else {
form_set_value($element, '', $form_state);
$form_state->setValueForElement($element, '');
}
}
......
......@@ -416,7 +416,7 @@ function hook_node_update_index(\Drupal\node\NodeInterface $node, $langcode) {
* Note: Changes made to the $node object within your hook implementation will
* have no effect. The preferred method to change a node's content is to use
* hook_node_presave() instead. If it is really necessary to change the node at
* the validate stage, you can use form_set_value().
* the validate stage, you can use setValueForElement().
*
* @param \Drupal\node\NodeInterface $node
* The node being validated.
......
......@@ -148,11 +148,11 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
// Check for empty front page path.
if ($form_state->isValueEmpty('site_frontpage')) {
// Set to default "user/login".
form_set_value($form['front_page']['site_frontpage'], 'user/login', $form_state);
$form_state->setValueForElement($form['front_page']['site_frontpage'], 'user/login');
}
else {
// Get the normal path of the front page.
form_set_value($form['front_page']['site_frontpage'], $this->aliasManager->getPathByAlias($form_state->getValue('site_frontpage')), $form_state);
$form_state->setValueForElement($form['front_page']['site_frontpage'], $this->aliasManager->getPathByAlias($form_state->getValue('site_frontpage')));
}
// Validate front page path.
if (!$this->pathValidator->isValid($form_state->getValue('site_frontpage'))) {
......@@ -160,10 +160,10 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
}
// Get the normal paths of both error pages.
if (!$form_state->isValueEmpty('site_403')) {
form_set_value($form['error_page']['site_403'], $this->aliasManager->getPathByAlias($form_state->getValue('site_403')), $form_state);
$form_state->setValueForElement($form['error_page']['site_403'], $this->aliasManager->getPathByAlias($form_state->getValue('site_403')));
}
if (!$form_state->isValueEmpty('site_404')) {
form_set_value($form['error_page']['site_404'], $this->aliasManager->getPathByAlias($form_state->getValue('site_404')), $form_state);
$form_state->setValueForElement($form['error_page']['site_404'], $this->aliasManager->getPathByAlias($form_state->getValue('site_404')));
}
// Validate 403 error path.
if (!$form_state->isValueEmpty('site_403') && !$this->pathValidator->isValid($form_state->getValue('site_403'))) {
......
......@@ -25,7 +25,7 @@ class ValidationTest extends WebTestBase {
public static $modules = array('form_test');
/**
* Tests form alterations by #element_validate, #validate, and form_set_value().
* Tests #element_validate and #validate.
*/
function testValidate() {
$this->drupalGet('form-test/validate');
......@@ -36,7 +36,7 @@ function testValidate() {
);
$this->drupalPostForm(NULL, $edit, 'Save');
$this->assertFieldByName('name', '#value changed by #element_validate', 'Form element #value was altered.');
$this->assertText('Name value: value changed by form_set_value() in #element_validate', 'Form element value in $form_state was altered.');
$this->assertText('Name value: value changed by setValueForElement() in #element_validate', 'Form element value in $form_state was altered.');
// Verify that #validate handlers can alter the form and submitted
// form values.
......@@ -45,7 +45,7 @@ function testValidate() {
);
$this->drupalPostForm(NULL, $edit, 'Save');
$this->assertFieldByName('name', '#value changed by #validate', 'Form element #value was altered.');
$this->assertText('Name value: value changed by form_set_value() in #validate', 'Form element value in $form_state was altered.');
$this->assertText('Name value: value changed by setValueForElement() in #validate', 'Form element value in $form_state was altered.');
// Verify that #element_validate handlers can make form elements
// inaccessible, but values persist.
......@@ -70,7 +70,7 @@ function testValidate() {
);
$this->drupalPostForm(NULL, $edit, 'Save');
$this->assertNoFieldByName('name', '#value changed by #validate', 'Form element #value was not altered.');
$this->assertNoText('Name value: value changed by form_set_value() in #validate', 'Form element value in $form_state was not altered.');
$this->assertNoText('Name value: value changed by setValueForElement() in #validate', 'Form element value in $form_state was not altered.');
$this->assertText('The form has become outdated. Copy any unsaved work in the form below');
}
......
......@@ -23,7 +23,7 @@ public function validateName(&$element, FormStateInterface $form_state) {
// Alter the form element.
$element['#value'] = '#value changed by #element_validate';
// Alter the submitted value in $form_state.
form_set_value($element, 'value changed by form_set_value() in #element_validate', $form_state);
$form_state->setValueForElement($element, 'value changed by setValueForElement() in #element_validate');
$triggered = TRUE;
}
......@@ -36,7 +36,7 @@ public function validateName(&$element, FormStateInterface $form_state) {
}
elseif ($form_state->has('form_test_name')) {
// To simplify this test, just take over the element's value into $form_state.
form_set_value($element, $form_state->get('form_test_name'), $form_state);
$form_state->setValueForElement($element, $form_state->get('form_test_name'));
$triggered = TRUE;
}
......
......@@ -16,8 +16,8 @@
*
* Serves for testing form processing and alterations by form validation
* handlers, especially for the case of a validation error:
* - form_set_value() should be able to alter submitted values in
* $form_state->getValues() without affecting the form element.
* - $form_state->setValueForElement() should be able to alter submitted values
* in $form_state->getValues() without affecting the form element.
* - #element_validate handlers should be able to alter the $element in the form
* structure and the alterations should be contained in the rebuilt form.
* - #validate handlers should be able to alter the $form and the alterations
......@@ -64,7 +64,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
// Alter the form element.
$form['name']['#value'] = '#value changed by #validate';
// Alter the submitted value in $form_state.
form_set_value($form['name'], 'value changed by form_set_value() in #validate', $form_state);
$form_state->setValueForElement($form['name'], 'value changed by setValueForElement() in #validate');
// Output the element's value from $form_state.
drupal_set_message(t('@label value: @value', array('@label' => $form['name']['#title'], '@value' => $form_state->getValue('name'))));
......
......@@ -629,7 +629,7 @@ function taxonomy_autocomplete_validate($element, FormStateInterface $form_state
if ($tags = $element['#value']) {
$typed_terms = Tags::explode($tags);
}
form_set_value($element, $typed_terms, $form_state);
$form_state->setValueForElement($element, $typed_terms);
}
/**
......
......@@ -118,7 +118,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
}
$account = reset($users);
if ($account && $account->id()) {
form_set_value(array('#parents' => array('account')), $account, $form_state);
$form_state->setValueForElement(array('#parents' => array('account')), $account);
}
else {
$form_state->setErrorByName('name', $this->t('Sorry, %name is not recognized as a username or an email address.', array('%name' => $name)));
......
......@@ -239,7 +239,7 @@ public function settingsFormValidate($element, FormStateInterface $form_state, $
}
$value = array('view_name' => $view, 'display_name' => $display, 'arguments' => $arguments);
form_set_value($element, $value, $form_state);
$form_state->setValueForElement($element, $value);
}
}
......@@ -242,7 +242,7 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) {
$element = array('#parents' => array('query', 'options', 'query_tags'));
$value = explode(',', NestedArray::getValue($form_state->getValues(), $element['#parents']));
$value = array_filter(array_map('trim', $value));
form_set_value($element, $value, $form_state);
$form_state->setValueForElement($element, $value);
}
/**
......
......@@ -252,7 +252,7 @@ function views_ui_taxonomy_autocomplete_validate($element, FormStateInterface $f
$value['vocabulary'] = array_pop($vocabularies);
}
}
form_set_value($element, $value, $form_state);
$form_state->setValueForElement($element, $value);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment