summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-11-07 20:05:32 (GMT)
committerAlex Pott2014-11-07 20:05:32 (GMT)
commit789de472d0eb462d81f3fe5329505d44c13b9e99 (patch)
tree96edb3b3eb845835fd3a4f8363bdfdd1cd82065c
parent56189b764cef8967043f4114e1cc4d211e7750ef (diff)
Issue #2354597 by esod, YesCT, vadim.hirbu, ashutoshsngh: Remove usage of form_set_value().
-rw-r--r--core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php2
-rw-r--r--core/modules/config/src/Form/ConfigSingleImportForm.php2
-rw-r--r--core/modules/entity_reference/entity_reference.module2
-rw-r--r--core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteTagsWidget.php6
-rw-r--r--core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteWidget.php4
-rw-r--r--core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidgetMultiple.php2
-rw-r--r--core/modules/field_ui/src/FieldOverview.php2
-rw-r--r--core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php2
-rw-r--r--core/modules/file/file.module2
-rw-r--r--core/modules/file/src/Plugin/Field/FieldType/FileItem.php4
-rw-r--r--core/modules/filter/src/FilterFormatFormBase.php4
-rw-r--r--core/modules/image/src/Plugin/Field/FieldType/ImageItem.php4
-rw-r--r--core/modules/node/node.api.php2
-rw-r--r--core/modules/system/src/Form/SiteInformationForm.php8
-rw-r--r--core/modules/system/src/Tests/Form/ValidationTest.php8
-rw-r--r--core/modules/system/tests/modules/form_test/src/Callbacks.php4
-rw-r--r--core/modules/system/tests/modules/form_test/src/Form/FormTestValidateForm.php6
-rw-r--r--core/modules/taxonomy/taxonomy.module2
-rw-r--r--core/modules/user/src/Form/UserPasswordForm.php2
-rw-r--r--core/modules/views/src/Plugin/entity_reference/selection/ViewsSelection.php2
-rw-r--r--core/modules/views/src/Plugin/views/query/Sql.php2
-rw-r--r--core/modules/views_ui/admin.inc2
22 files changed, 37 insertions, 37 deletions
diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php
index d23eb44..92ec779 100644
--- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php
@@ -108,7 +108,7 @@ abstract class OptionsWidgetBase extends WidgetBase {
foreach ($values as $value) {
$items[] = array($element['#key_column'] => $value);
}
- form_set_value($element, $items, $form_state);
+ $form_state->setValueForElement($element, $items);
}
/**
diff --git a/core/modules/config/src/Form/ConfigSingleImportForm.php b/core/modules/config/src/Form/ConfigSingleImportForm.php
index debd1cb..58156b0 100644
--- a/core/modules/config/src/Form/ConfigSingleImportForm.php
+++ b/core/modules/config/src/Form/ConfigSingleImportForm.php
@@ -227,7 +227,7 @@ class ConfigSingleImportForm extends ConfirmFormBase {
}
// Store the decoded version of the submitted import.
- form_set_value($form['import'], $data, $form_state);
+ $form_state->setValueForElement($form['import'], $data);
}
/**
diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module
index 33516d7..6d4280b 100644
--- a/core/modules/entity_reference/entity_reference.module
+++ b/core/modules/entity_reference/entity_reference.module
@@ -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']);
}
/**
diff --git a/core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteTagsWidget.php b/core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteTagsWidget.php
index b289a06..c77245c 100644
--- a/core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteTagsWidget.php
+++ b/core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteTagsWidget.php
@@ -80,9 +80,9 @@ class AutocompleteTagsWidget extends AutocompleteWidgetBase {
}
}
};
- // 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);
}
}
diff --git a/core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteWidget.php b/core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteWidget.php
index ef9e6ea..207910f 100644
--- a/core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteWidget.php
+++ b/core/modules/entity_reference/src/Plugin/Field/FieldWidget/AutocompleteWidget.php
@@ -89,11 +89,11 @@ class AutocompleteWidget extends AutocompleteWidgetBase {
// 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);
}
}
diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidgetMultiple.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidgetMultiple.php
index be2ab05..b8a0dd2 100644
--- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidgetMultiple.php
+++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidgetMultiple.php
@@ -94,7 +94,7 @@ class TestFieldWidgetMultiple extends WidgetBase {
foreach ($values as $value) {
$items[] = array('value' => $value);
}
- form_set_value($element, $items, $form_state);
+ $form_state->setValueForElement($element, $items);
}
/**
diff --git a/core/modules/field_ui/src/FieldOverview.php b/core/modules/field_ui/src/FieldOverview.php
index 312832f..290d655 100644
--- a/core/modules/field_ui/src/FieldOverview.php
+++ b/core/modules/field_ui/src/FieldOverview.php
@@ -318,7 +318,7 @@ class FieldOverview extends OverviewBase {
// 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.
diff --git a/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php b/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php
index cd207de..0d6f8bb 100644
--- a/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php
+++ b/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php
@@ -41,7 +41,7 @@ class EntityDisplayModeAddForm extends EntityDisplayModeFormBase {
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'));
}
/**
diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index 93a49d8..e8a565e 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -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));
}
diff --git a/core/modules/file/src/Plugin/Field/FieldType/FileItem.php b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php
index 9307667..1c00e76 100644
--- a/core/modules/file/src/Plugin/Field/FieldType/FileItem.php
+++ b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php
@@ -214,7 +214,7 @@ class FileItem extends EntityReferenceItem {
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 @@ class FileItem extends EntityReferenceItem {
$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);
}
}
}
diff --git a/core/modules/filter/src/FilterFormatFormBase.php b/core/modules/filter/src/FilterFormatFormBase.php
index b6abf1a..e784836 100644
--- a/core/modules/filter/src/FilterFormatFormBase.php
+++ b/core/modules/filter/src/FilterFormatFormBase.php
@@ -218,8 +218,8 @@ abstract class FilterFormatFormBase extends EntityForm {
$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')
diff --git a/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php b/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php
index 24c3927..067fecd 100644
--- a/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php
+++ b/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php
@@ -379,10 +379,10 @@ class ImageItem extends FileItem {
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, '');
}
}
diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php
index d42f748..759c5cd 100644
--- a/core/modules/node/node.api.php
+++ b/core/modules/node/node.api.php
@@ -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.
diff --git a/core/modules/system/src/Form/SiteInformationForm.php b/core/modules/system/src/Form/SiteInformationForm.php
index fec470c..f2efcd5 100644
--- a/core/modules/system/src/Form/SiteInformationForm.php
+++ b/core/modules/system/src/Form/SiteInformationForm.php
@@ -148,11 +148,11 @@ class SiteInformationForm extends ConfigFormBase {
// 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 @@ class SiteInformationForm extends ConfigFormBase {
}
// 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'))) {
diff --git a/core/modules/system/src/Tests/Form/ValidationTest.php b/core/modules/system/src/Tests/Form/ValidationTest.php
index 607db5c..7b6c9e8 100644
--- a/core/modules/system/src/Tests/Form/ValidationTest.php
+++ b/core/modules/system/src/Tests/Form/ValidationTest.php
@@ -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 @@ class ValidationTest extends WebTestBase {
);
$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 @@ class ValidationTest extends WebTestBase {
);
$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 @@ class ValidationTest extends WebTestBase {
);
$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');
}
diff --git a/core/modules/system/tests/modules/form_test/src/Callbacks.php b/core/modules/system/tests/modules/form_test/src/Callbacks.php
index 3edf0fa..3d45894 100644
--- a/core/modules/system/tests/modules/form_test/src/Callbacks.php
+++ b/core/modules/system/tests/modules/form_test/src/Callbacks.php
@@ -23,7 +23,7 @@ class Callbacks {
// 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 @@ class Callbacks {
}
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;
}
diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestValidateForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestValidateForm.php
index 7da8f5d..e403887 100644
--- a/core/modules/system/tests/modules/form_test/src/Form/FormTestValidateForm.php
+++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestValidateForm.php
@@ -16,8 +16,8 @@ use Drupal\form_test\Callbacks;
*
* 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 @@ class FormTestValidateForm extends FormBase {
// 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'))));
diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module
index 1c38a78..9df30d9 100644
--- a/core/modules/taxonomy/taxonomy.module
+++ b/core/modules/taxonomy/taxonomy.module
@@ -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);
}
/**
diff --git a/core/modules/user/src/Form/UserPasswordForm.php b/core/modules/user/src/Form/UserPasswordForm.php
index f06ba29..4d5a012 100644
--- a/core/modules/user/src/Form/UserPasswordForm.php
+++ b/core/modules/user/src/Form/UserPasswordForm.php
@@ -118,7 +118,7 @@ class UserPasswordForm extends FormBase {
}
$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)));
diff --git a/core/modules/views/src/Plugin/entity_reference/selection/ViewsSelection.php b/core/modules/views/src/Plugin/entity_reference/selection/ViewsSelection.php
index 7802113..139f2f6 100644
--- a/core/modules/views/src/Plugin/entity_reference/selection/ViewsSelection.php
+++ b/core/modules/views/src/Plugin/entity_reference/selection/ViewsSelection.php
@@ -239,7 +239,7 @@ class ViewsSelection implements SelectionInterface {
}
$value = array('view_name' => $view, 'display_name' => $display, 'arguments' => $arguments);
- form_set_value($element, $value, $form_state);
+ $form_state->setValueForElement($element, $value);
}
}
diff --git a/core/modules/views/src/Plugin/views/query/Sql.php b/core/modules/views/src/Plugin/views/query/Sql.php
index f3796bb..48856cf 100644
--- a/core/modules/views/src/Plugin/views/query/Sql.php
+++ b/core/modules/views/src/Plugin/views/query/Sql.php
@@ -242,7 +242,7 @@ class Sql extends QueryPluginBase {
$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);
}
/**
diff --git a/core/modules/views_ui/admin.inc b/core/modules/views_ui/admin.inc
index 7356625..61bd9a8 100644
--- a/core/modules/views_ui/admin.inc
+++ b/core/modules/views_ui/admin.inc
@@ -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);
}
/**