diff options
author | Alex Pott <alex.a.pott@googlemail.com> | 2014-08-08 11:25:54 -0500 |
---|---|---|
committer | Alex Pott <alex.a.pott@googlemail.com> | 2014-08-08 11:25:54 -0500 |
commit | 8196034a57f7e110829f291e0901fbe1357e45c0 (patch) | |
tree | da6e6cefdf1d6b6c3e27a847050cb1283f17fbdf | |
parent | dc11fb9a368669c1b95d8ef0f23b747fc9954043 (diff) | |
download | drupal-8196034a57f7e110829f291e0901fbe1357e45c0.tar.gz drupal-8196034a57f7e110829f291e0901fbe1357e45c0.zip |
Issue #2316533 by tim.plunkett: Add getValue/setValue/hasValue and isValueEmpty to FormState.
277 files changed, 1297 insertions, 1029 deletions
diff --git a/core/includes/ajax.inc b/core/includes/ajax.inc index 5534e363a0e..4a03c6869b6 100644 --- a/core/includes/ajax.inc +++ b/core/includes/ajax.inc @@ -99,7 +99,7 @@ use Drupal\Core\Form\FormStateInterface; * get the format string entered by the user: * @code * $format_value = \Drupal\Component\Utility\NestedArray::getValue( - * $form_state['values'], + * $form_state->getValues(), * $form_state['triggering_element']['#array_parents']); * @endcode * diff --git a/core/includes/form.inc b/core/includes/form.inc index 1b4a086f584..577e40c5968 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -238,7 +238,11 @@ function form_builder($form_id, &$element, FormStateInterface $form_state) { */ function form_state_values_clean(FormStateInterface $form_state) { // Remove internal Form API values. - unset($form_state['values']['form_id'], $form_state['values']['form_token'], $form_state['values']['form_build_id'], $form_state['values']['op']); + $form_state + ->unsetValue('form_id') + ->unsetValue('form_token') + ->unsetValue('form_build_id') + ->unsetValue('op'); // Remove button values. // form_builder() collects all button elements in a form. We remove the button @@ -247,9 +251,9 @@ function form_state_values_clean(FormStateInterface $form_state) { // Remove this button's value from the submitted form values by finding // the value corresponding to this button. // We iterate over the #parents of this button and move a reference to - // each parent in $form_state['values']. For example, if #parents is: + // each parent in $form_state->getValues(). For example, if #parents is: // array('foo', 'bar', 'baz') - // then the corresponding $form_state['values'] part will look like this: + // then the corresponding $form_state->getValues() part will look like this: // array( // 'foo' => array( // 'bar' => array( @@ -259,14 +263,14 @@ function form_state_values_clean(FormStateInterface $form_state) { // ) // We start by (re)moving 'baz' to $last_parent, so we are able unset it // at the end of the iteration. Initially, $values will contain a - // reference to $form_state['values'], but in the iteration we move the - // reference to $form_state['values']['foo'], and finally to - // $form_state['values']['foo']['bar'], which is the level where we can - // unset 'baz' (that is stored in $last_parent). + // reference to $form_state->getValues(), but in the iteration we move the + // reference to $form_state->getValue('foo'), and finally to + // $form_state->getValue(array('foo', 'bar')), which is the level where we + // can unset 'baz' (that is stored in $last_parent). $parents = $button['#parents']; $last_parent = array_pop($parents); $key_exists = NULL; - $values = &NestedArray::getValue($form_state['values'], $parents, $key_exists); + $values = &NestedArray::getValue($form_state->getValues(), $parents, $key_exists); if ($key_exists && is_array($values)) { unset($values[$last_parent]); } @@ -285,7 +289,7 @@ function form_state_values_clean(FormStateInterface $form_state) { * The current state of the form. * * @return - * The data that will appear in the $form_state['values'] collection + * The data that will appear in the $form_state->getValues() collection * for this element. Return nothing to use the default. */ function form_type_image_button_value($form, $input, FormStateInterface $form_state) { @@ -414,7 +418,7 @@ function form_type_checkboxes_value($element, $input = FALSE) { * the element's default value should be returned. * * @return array - * The data that will appear in the $form_state['values'] collection + * The data that will appear in the $form_state->getValues() collection * for this element. Return nothing to use the default. */ function form_type_table_value(array $element, $input = FALSE) { @@ -2021,8 +2025,8 @@ function form_process_vertical_tabs($element, FormStateInterface $form_state) { // form is rendered, e.g. on preview pages or when form validation // fails. $name = implode('__', $element['#parents']); - if (isset($form_state['values'][$name . '__active_tab'])) { - $element['#default_tab'] = $form_state['values'][$name . '__active_tab']; + if ($form_state->hasValue($name . '__active_tab')){ + $element['#default_tab'] = $form_state->getValue($name . '__active_tab'); } $element[$name . '__active_tab'] = array( '#type' => 'hidden', @@ -2373,7 +2377,7 @@ function form_validate_number(&$element, FormStateInterface $form_state) { * element's default value should be returned. * * @return - * The data that will appear in the $form_state['values'] collection for + * The data that will appear in the $form_state->getValues() collection for * this element. Return nothing to use the default. */ function form_type_range_value($element, $input = FALSE) { diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 5dee15d5a15..4cdc52945ee 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -155,7 +155,7 @@ function install_drupal($settings = array()) { * 'langcode' that are normally passed in via the URL) and 'forms' (which can * be used to programmatically submit forms during the installation; the keys * of each element indicate the name of the installation task that the form - * submission is for, and the values are used as the $form_state['values'] + * submission is for, and the values are used as the $form_state->getValues() * array that is passed on to the form submission via drupal_form_submit()). * * @see \Drupal\Core\Form\FormBuilderInterface::submitForm() @@ -182,7 +182,7 @@ function install_state_defaults() { // An array of forms to be programmatically submitted during the // installation. The keys of each element indicate the name of the // installation task that the form submission is for, and the values are - // used as the $form_state['values'] array that is passed on to the form + // used as the $form_state->getValues() array that is passed on to the form // submission via drupal_form_submit(). 'forms' => array(), // This becomes TRUE only at the end of the installation process, after @@ -824,10 +824,9 @@ function install_get_form($form_id, array &$install_state) { else { // For non-interactive installs, submit the form programmatically with the // values taken from the installation state. - $form_state['values'] = array(); $install_form_id = $form_builder->getFormId($form_id, $form_state); if (!empty($install_state['forms'][$install_form_id])) { - $form_state['values'] = $install_state['forms'][$install_form_id]; + $form_state->set('values', $install_state['forms'][$install_form_id]); } $form_builder->submitForm($form_id, $form_state); diff --git a/core/lib/Drupal/Core/Condition/ConditionPluginBase.php b/core/lib/Drupal/Core/Condition/ConditionPluginBase.php index a745065354c..c71c067e0d7 100644 --- a/core/lib/Drupal/Core/Condition/ConditionPluginBase.php +++ b/core/lib/Drupal/Core/Condition/ConditionPluginBase.php @@ -59,7 +59,7 @@ abstract class ConditionPluginBase extends ExecutablePluginBase implements Condi * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['negate'] = $form_state['values']['negate']; + $this->configuration['negate'] = $form_state->getValue('negate'); } /** diff --git a/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php b/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php index ef021774a61..65f167cb8ba 100644 --- a/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php +++ b/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php @@ -147,7 +147,7 @@ abstract class DraggableListBuilder extends ConfigEntityListBuilder implements F * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - foreach ($form_state['values'][$this->entitiesKey] as $id => $value) { + foreach ($form_state->getValue($this->entitiesKey) as $id => $value) { if (isset($this->entities[$id]) && $this->entities[$id]->get($this->weightKey) != $value['weight']) { // Save entity only when its weight was changed. $this->entities[$id]->set($this->weightKey, $value['weight']); diff --git a/core/lib/Drupal/Core/Display/VariantBase.php b/core/lib/Drupal/Core/Display/VariantBase.php index b39d9b36c77..eba349b9091 100644 --- a/core/lib/Drupal/Core/Display/VariantBase.php +++ b/core/lib/Drupal/Core/Display/VariantBase.php @@ -122,7 +122,7 @@ abstract class VariantBase extends PluginBase implements VariantInterface { * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['label'] = $form_state['values']['label']; + $this->configuration['label'] = $form_state->getValue('label'); } /** diff --git a/core/lib/Drupal/Core/Entity/ContentEntityForm.php b/core/lib/Drupal/Core/Entity/ContentEntityForm.php index d2fc4800e9c..5a1244e782c 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityForm.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityForm.php @@ -113,7 +113,7 @@ class ContentEntityForm extends EntityForm implements ContentEntityFormInterface // Then extract the values of fields that are not rendered through widgets, // by simply copying from top-level form values. This leaves the fields // that are not being edited within this form untouched. - foreach ($form_state['values'] as $name => $values) { + foreach ($form_state->getValues() as $name => $values) { if ($entity->hasField($name) && !isset($extracted[$name])) { $entity->set($name, $values); } diff --git a/core/lib/Drupal/Core/Entity/Display/EntityFormDisplayInterface.php b/core/lib/Drupal/Core/Entity/Display/EntityFormDisplayInterface.php index 4ecc887a2f3..11c11fcf04c 100644 --- a/core/lib/Drupal/Core/Entity/Display/EntityFormDisplayInterface.php +++ b/core/lib/Drupal/Core/Entity/Display/EntityFormDisplayInterface.php @@ -24,14 +24,15 @@ interface EntityFormDisplayInterface extends EntityDisplayInterface { * larger form. * * By default, submitted field values appear at the top-level of - * $form_state['values']. A different location within $form_state['values'] - * can be specified by setting the '#parents' property on the incoming $form - * parameter. Because of name clashes, two instances of the same field cannot - * appear within the same $form element, or within the same '#parents' space. + * $form_state->getValues(). A different location within + * $form_state->getValues() can be specified by setting the '#parents' + * property on the incoming $form parameter. Because of name clashes, two + * instances of the same field cannot appear within the same $form element, or + * within the same '#parents' space. * * Sample resulting structure in $form: * @code - * '#parents' => The location of field values in $form_state['values'], + * '#parents' => The location of field values in $form_state->getValues(), * '#entity_type' => The name of the entity type, * '#bundle' => The name of the bundle, * // One sub-array per field appearing in the entity, keyed by field name. @@ -91,9 +92,9 @@ interface EntityFormDisplayInterface extends EntityDisplayInterface { * The form structure to fill in. This can be a full form structure, or a * sub-element of a larger form. The #parents property can be set to * control the location of submitted field values within - * $form_state['values']. If not specified, $form['#parents'] is set to an - * empty array, which results in field values located at the top-level of - * $form_state['values']. + * $form_state->getValues(). If not specified, $form['#parents'] is set to + * an empty array, which results in field values located at the top-level of + * $form_state->getValues(). * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state. */ @@ -144,8 +145,8 @@ interface EntityFormDisplayInterface extends EntityDisplayInterface { * * @return array * An array whose keys and values are the keys of the top-level entries in - * $form_state['values'] that have been processed. The remaining entries, if - * any, do not correspond to widgets and should be extracted manually by + * $form_state->getValues() that have been processed. The remaining entries, + * if any, do not correspond to widgets and should be extracted manually by * the caller if needed. */ public function extractFormValues(ContentEntityInterface $entity, array &$form, FormStateInterface $form_state); diff --git a/core/lib/Drupal/Core/Entity/EntityForm.php b/core/lib/Drupal/Core/Entity/EntityForm.php index f929a955858..f154844e59d 100644 --- a/core/lib/Drupal/Core/Entity/EntityForm.php +++ b/core/lib/Drupal/Core/Entity/EntityForm.php @@ -307,8 +307,8 @@ class EntityForm extends FormBase implements EntityFormInterface { */ protected function updateFormLangcode(FormStateInterface $form_state) { // Update the form language as it might have changed. - if (isset($form_state['values']['langcode']) && $this->isDefaultFormLangcode($form_state)) { - $form_state['langcode'] = $form_state['values']['langcode']; + if ($form_state->hasValue('langcode') && $this->isDefaultFormLangcode($form_state)) { + $form_state['langcode'] = $form_state->getValue('langcode'); } } @@ -352,7 +352,7 @@ class EntityForm extends FormBase implements EntityFormInterface { // @todo: This relies on a method that only exists for config and content // entities, in a different way. Consider moving this logic to a config // entity specific implementation. - foreach ($form_state['values'] as $key => $value) { + foreach ($form_state->getValues() as $key => $value) { $entity->set($key, $value); } } diff --git a/core/lib/Drupal/Core/Field/WidgetBase.php b/core/lib/Drupal/Core/Field/WidgetBase.php index c94465a38e3..1095c4818e8 100644 --- a/core/lib/Drupal/Core/Field/WidgetBase.php +++ b/core/lib/Drupal/Core/Field/WidgetBase.php @@ -331,10 +331,10 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state) { $field_name = $this->fieldDefinition->getName(); - // Extract the values from $form_state['values']. + // Extract the values from $form_state->getValues(). $path = array_merge($form['#parents'], array($field_name)); $key_exists = NULL; - $values = NestedArray::getValue($form_state['values'], $path, $key_exists); + $values = NestedArray::getValue($form_state->getValues(), $path, $key_exists); if ($key_exists) { // Account for drag-and-drop reordering if needed. diff --git a/core/lib/Drupal/Core/Field/WidgetInterface.php b/core/lib/Drupal/Core/Field/WidgetInterface.php index 90034a82136..9c045a66415 100644 --- a/core/lib/Drupal/Core/Field/WidgetInterface.php +++ b/core/lib/Drupal/Core/Field/WidgetInterface.php @@ -83,9 +83,9 @@ interface WidgetInterface extends WidgetBaseInterface { * - #field_parents: The 'parents' space for the field in the form. Most * widgets can simply overlook this property. This identifies the * location where the field values are placed within - * $form_state['values'], and is used to access processing information - * for the field through the getWidgetState() and setWidgetState() - * methods. + * $form_state->getValues(), and is used to access processing + * information for the field through the getWidgetState() and + * setWidgetState() methods. * - #title: The sanitized element label for the field instance, ready for * output. * - #description: The sanitized element description for the field instance, diff --git a/core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php b/core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php index c72f46e612d..dfc2a8f2dc6 100644 --- a/core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php +++ b/core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php @@ -46,9 +46,7 @@ class FileTransferAuthorizeForm extends FormBase { } // Decide on a default backend. - if (isset($form_state['values']['connection_settings']['authorize_filetransfer_default'])) { - $authorize_filetransfer_default = $form_state['values']['connection_settings']['authorize_filetransfer_default']; - } + if ($authorize_filetransfer_default = $form_state->getValue(array('connection_settings', 'authorize_filetransfer_default'))); elseif ($authorize_filetransfer_default = $this->config('system.authorize')->get('filetransfer_default')); else { $authorize_filetransfer_default = key($available_backends); @@ -111,7 +109,7 @@ class FileTransferAuthorizeForm extends FormBase { $form['connection_settings'][$name] += $this->addConnectionSettings($name); // Start non-JS code. - if (isset($form_state['values']['connection_settings']['authorize_filetransfer_default']) && $form_state['values']['connection_settings']['authorize_filetransfer_default'] == $name) { + if ($form_state->getValue(array('connection_settings', 'authorize_filetransfer_default')) == $name) { // Change the submit button to the submit_process one. $form['submit_process']['#attributes'] = array(); @@ -146,9 +144,9 @@ class FileTransferAuthorizeForm extends FormBase { return; } - if (isset($form_state['values']['connection_settings'])) { - $backend = $form_state['values']['connection_settings']['authorize_filetransfer_default']; - $filetransfer = $this->getFiletransfer($backend, $form_state['values']['connection_settings'][$backend]); + if ($form_connection_settings = $form_state->getValue('connection_settings')) { + $backend = $form_connection_settings['authorize_filetransfer_default']; + $filetransfer = $this->getFiletransfer($backend, $form_connection_settings[$backend]); try { if (!$filetransfer) { throw new \Exception($this->t('The connection protocol %backend does not exist.', array('%backend' => $backend))); @@ -170,11 +168,12 @@ class FileTransferAuthorizeForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { + $form_connection_settings = $form_state->getValue('connection_settings'); switch ($form_state['triggering_element']['#name']) { case 'process_updates': // Save the connection settings to the DB. - $filetransfer_backend = $form_state['values']['connection_settings']['authorize_filetransfer_default']; + $filetransfer_backend = $form_connection_settings['authorize_filetransfer_default']; // If the database is available then try to save our settings. We have // to make sure it is available since this code could potentially (will @@ -182,7 +181,7 @@ class FileTransferAuthorizeForm extends FormBase { // database is set up. try { $connection_settings = array(); - foreach ($form_state['values']['connection_settings'][$filetransfer_backend] as $key => $value) { + foreach ($form_connection_settings[$filetransfer_backend] as $key => $value) { // We do *not* want to store passwords in the database, unless the // backend explicitly says so via the magic #filetransfer_save form // property. Otherwise, we store everything that's not explicitly @@ -202,7 +201,7 @@ class FileTransferAuthorizeForm extends FormBase { // Save the connection settings minus the password. $this->config('system.authorize')->set('filetransfer_connection_settings_' . $filetransfer_backend, $connection_settings); - $filetransfer = $this->getFiletransfer($filetransfer_backend, $form_state['values']['connection_settings'][$filetransfer_backend]); + $filetransfer = $this->getFiletransfer($filetransfer_backend, $form_connection_settings[$filetransfer_backend]); // Now run the operation. $this->runOperation($filetransfer); @@ -220,7 +219,7 @@ class FileTransferAuthorizeForm extends FormBase { case 'change_connection_type': $form_state['rebuild'] = TRUE; - unset($form_state['values']['connection_settings']['authorize_filetransfer_default']); + $form_state->unsetValue(array('connection_settings', 'authorize_filetransfer_default')); break; } } diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index 6aeeffdfbbe..d3a308477e4 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -237,7 +237,7 @@ class FormBuilder implements FormBuilderInterface, FormValidatorInterface, FormS // Now that we have a constructed form, process it. This is where: // - Element #process functions get called to further refine $form. // - User input, if any, gets incorporated in the #value property of the - // corresponding elements and into $form_state['values']. + // corresponding elements and into $form_state->getValues(). // - Validation and submission handlers are called. // - If this submission is part of a multistep workflow, the form is rebuilt // to contain the information of the next step. @@ -386,7 +386,7 @@ class FormBuilder implements FormBuilderInterface, FormValidatorInterface, FormS // the form, to be consistent with what self::buildForm() does for // non-programmatic submissions (form builder functions may expect it to be // there). - $form_state->set('input', $form_state->get('values')); + $form_state->set('input', $form_state->getValues()); $form_state->set('programmed', TRUE); @@ -466,8 +466,8 @@ class FormBuilder implements FormBuilderInterface, FormValidatorInterface, FormS // self::doBuildForm() finishes building the form by calling element // #process functions and mapping user input, if any, to #value properties, - // and also storing the values in $form_state['values']. We need to retain - // the unprocessed $form in case it needs to be cached. + // and also storing the values in $form_state->getValues(). We need to + // retain the unprocessed $form in case it needs to be cached. $unprocessed_form = $form; $form = $this->doBuildForm($form_id, $form, $form_state); @@ -869,10 +869,10 @@ class FormBuilder implements FormBuilderInterface, FormValidatorInterface, FormS // buttons often have their #name property not derived from their // #parents property, we can't assume that input processing that's // happened up until here has resulted in - // $form_state['values'][BUTTON_NAME] being set. But it's common for + // $form_state->getValue(BUTTON_NAME) being set. But it's common for // forms to have several buttons named 'op' and switch on - // $form_state['values']['op'] during submit handler execution. - $form_state->addValue($triggering_element['#name'], $triggering_element['#value']); + // $form_state->getValue('op') during submit handler execution. + $form_state->setValue($triggering_element['#name'], $triggering_element['#value']); } } return $element; @@ -1016,7 +1016,7 @@ class FormBuilder implements FormBuilderInterface, FormValidatorInterface, FormS } } - // Set the element's value in $form_state['values'], but only, if its key + // Set the element's value in $form_state->getValues(), but only, if its key // does not exist yet (a #value_callback may have already populated it). if (!NestedArray::keyExists($form_state->getValues(), $element['#parents'])) { $form_state->setValueForElement($element, $element['#value']); diff --git a/core/lib/Drupal/Core/Form/FormBuilderInterface.php b/core/lib/Drupal/Core/Form/FormBuilderInterface.php index 2feb39a3415..e9a7602b6ee 100644 --- a/core/lib/Drupal/Core/Form/FormBuilderInterface.php +++ b/core/lib/Drupal/Core/Form/FormBuilderInterface.php @@ -137,9 +137,9 @@ interface FormBuilderInterface { * name exists, it is called to build the form array. * @param $form_state * The current state of the form. Most important is the - * $form_state['values'] collection, a tree of data used to simulate the + * $form_state->getValues() collection, a tree of data used to simulate the * incoming \Drupal::request()->request information from a user's form - * submission. If a key is not filled in $form_state['values'], then the + * submission. If a key is not filled in $form_state->getValues(), then the * default value of the respective element is used. To submit an unchecked * checkbox or other control that browsers submit by not having a * \Drupal::request()->request entry, include the key, but set the value to @@ -158,7 +158,7 @@ interface FormBuilderInterface { * @endcode * would be called via self::submitForm() as follows: * @code - * $form_state['values'] = $my_form_values; + * $form_state->set('values', $my_form_values); * $form_state['build_info']['args'] = array(&$object); * drupal_form_submit('mymodule_form', $form_state); * @endcode @@ -166,11 +166,12 @@ interface FormBuilderInterface { * @code * // register a new user * $form_state = new FormState(); - * $form_state['values']['name'] = 'robo-user'; - * $form_state['values']['mail'] = 'robouser@example.com'; - * $form_state['values']['pass']['pass1'] = 'password'; - * $form_state['values']['pass']['pass2'] = 'password'; - * $form_state['values']['op'] = t('Create new account'); + * $values['name'] = 'robo-user'; + * $values['mail'] = 'robouser@example.com'; + * $values['pass']['pass1'] = 'password'; + * $values['pass']['pass2'] = 'password'; + * $values['op'] = t('Create new account'); + * $form_state->set('values', $values); * drupal_form_submit('user_register_form', $form_state); * @endcode */ @@ -302,7 +303,7 @@ interface FormBuilderInterface { * 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['values'] and setting $form_state['rebuild']. The form + * $form_state->getValues() and setting $form_state['rebuild']. The form * building functions must then be implemented to use the $form_state data * to rebuild the form with the structure appropriate for the new state. * - Where user input must affect the rendering of the form without affecting diff --git a/core/lib/Drupal/Core/Form/FormState.php b/core/lib/Drupal/Core/Form/FormState.php index 5e2be94ef80..bc660925644 100644 --- a/core/lib/Drupal/Core/Form/FormState.php +++ b/core/lib/Drupal/Core/Form/FormState.php @@ -196,7 +196,7 @@ class FormState implements FormStateInterface, \ArrayAccess { * * @var array */ - protected $values; + protected $values = array(); /** * The array of values as they were submitted by the user. @@ -559,33 +559,66 @@ class FormState implements FormStateInterface, \ArrayAccess { /** * {@inheritdoc} */ - public function getValues() { - return $this->values ?: array(); + public function &getValues() { + return $this->values; } /** * {@inheritdoc} */ - public function addValue($property, $value) { - $values = $this->getValues(); - $values[$property] = $value; - $this->set('values', $values); + public function &getValue($key, $default = NULL) { + $exists = NULL; + $value = &NestedArray::getValue($this->getValues(), (array) $key, $exists); + if (!$exists) { + $value = $default; + } + return $value; + } + + /** + * {@inheritdoc} + */ + public function setValue($key, $value) { + NestedArray::setValue($this->getValues(), (array) $key, $value, TRUE); return $this; } /** * {@inheritdoc} */ - public function setValueForElement($element, $value) { - $values = $this->getValues(); - NestedArray::setValue($values, $element['#parents'], $value, TRUE); - $this->set('values', $values); + public function unsetValue($key) { + NestedArray::unsetValue($this->getValues(), (array) $key); return $this; } /** * {@inheritdoc} */ + public function hasValue($key) { + $exists = NULL; + $value = NestedArray::getValue($this->getValues(), (array) $key, $exists); + return $exists && isset($value); + } + + /** + * {@inheritdoc} + */ + public function isValueEmpty($key) { + $exists = NULL; + $value = NestedArray::getValue($this->getValues(), (array) $key, $exists); + return !$exists || empty($value); + } + + /** + * {@inheritdoc} + */ + public function setValueForElement($element, $value) { + return $this->setValue($element['#parents'], $value); + } + + /** + * {@inheritdoc} + */ public function setResponse(Response $response) { $this->set('response', $response); return $this; @@ -670,10 +703,10 @@ class FormState implements FormStateInterface, \ArrayAccess { // Exploding by '][' reconstructs the element's #parents. If the // reconstructed #parents begin with the same keys as the specified // section, then the element's values are within the part of - // $form_state['values'] that the clicked button requires to be valid, - // so errors for this element must be recorded. As the exploded array - // will all be strings, we need to cast every value of the section - // array to string. + // $form_state->getValues() that the clicked button requires to be + // valid, so errors for this element must be recorded. As the exploded + // array will all be strings, we need to cast every value of the + // section array to string. if (array_slice(explode('][', $name), 0, count($section)) === array_map('strval', $section)) { $record = TRUE; break; diff --git a/core/lib/Drupal/Core/Form/FormStateInterface.php b/core/lib/Drupal/Core/Form/FormStateInterface.php index a24d28dc0df..98a76942536 100644 --- a/core/lib/Drupal/Core/Form/FormStateInterface.php +++ b/core/lib/Drupal/Core/Form/FormStateInterface.php @@ -181,12 +181,79 @@ interface FormStateInterface { * @return array * An associative array of values submitted to the form. */ - public function getValues(); + public function &getValues(); /** - * {@inheritdoc} + * Returns the submitted form value for a specific key. + * + * @param string|array $key + * Values are stored as a multi-dimensional associative array. If $key is a + * string, it will return $values[$key]. If $key is an array, each element + * of the array will be used as a nested key. If $key = array('foo', 'bar') + * it will return $values['foo']['bar']. + * @param mixed $default + * (optional) The default value if the specified key does not exist. + * + * @return mixed + * The value for the given key, or NULL. + */ + public function &getValue($key, $default = NULL); + + /** + * Sets the submitted form value for a specific key. + * + * @param string|array $key + * Values are stored as a multi-dimensional associative array. If $key is a + * string, it will use $values[$key] = $value. If $key is an array, each + * element of the array will be used as a nested key. If + * $key = array('foo', 'bar') it will use $values['foo']['bar'] = $value. + * @param mixed $value + * The value to set. + * + * @return $this + */ + public function setValue($key, $value); + + /** + * Removes a specific key from the submitted form values. + * + * @param string|array $key + * Values are stored as a multi-dimensional associative array. If $key is a + * string, it will use unset($values[$key]). If $key is an array, each + * element of the array will be used as a nested key. If + * $key = array('foo', 'bar') it will use unset($values['foo']['bar']). + * + * @return $this + */ + public function unsetValue($key); + + /** + * Determines if a specific key is present in the submitted form values. + * + * @param string|array $key + * Values are stored as a multi-dimensional associative array. If $key is a + * string, it will return isset($values[$key]). If $key is an array, each + * element of the array will be used as a nested key. If + * $key = array('foo', 'bar') it will return isset($values['foo']['bar']). + * + * @return bool + * TRUE if the $key is set, FALSE otherwise. + */ + public function hasValue($key); + + /** + * Determines if a specific key has a value in the submitted form values. + * + * @param string|array $key + * Values are stored as a multi-dimensional associative array. If $key is a + * string, it will return empty($values[$key]). If $key is an array, each + * element of the array will be used as a nested key. If + * $key = array('foo', 'bar') it will return empty($values['foo']['bar']). + * + * @return bool + * TRUE if the $key has no value, FALSE otherwise. */ - public function addValue($property, $value); + public function isValueEmpty($key); /** * Changes submitted form values during form validation. @@ -208,8 +275,8 @@ interface FormStateInterface { * set $element['#parents'] to be an array giving the path through the form * array's keys to the element whose value you want to update. For instance, * if you want to update the value of $form['elem1']['elem2'], which should - * be stored in $form_state['values']['elem1']['elem2'], you would set - * $element['#parents'] = array('elem1','elem2'). + * be stored in $form_state->getValue(array('elem1', 'elem2')), you would + * set $element['#parents'] = array('elem1','elem2'). * @param mixed $value * The new value for the form element. * @@ -250,9 +317,9 @@ interface FormStateInterface { * values to the database. * * The #limit_validation_errors property is a list of "sections" within - * $form_state['values'] that must contain valid values. Each "section" is an - * array with the ordered set of keys needed to reach that part of - * $form_state['values'] (i.e., the #parents property of the element). + * $form_state->getValues() that must contain valid values. Each "section" is + * an array with the ordered set of keys needed to reach that part of + * $form_state->getValues() (i.e., the #parents property of the element). * * Example 1: Allow the "Previous" button to function, regardless of whether * any user input is valid. @@ -274,33 +341,35 @@ interface FormStateInterface { * '#type' => 'submit', * '#value' => t('Previous'), * '#limit_validation_errors' => array( - * array('step1'), // Validate $form_state['values']['step1']. - * array('foo', 'bar'), // Validate $form_state['values']['foo']['bar']. + * // Validate $form_state->getValue('step1'). + * array('step1'), + * // Validate $form_state->getValue(array('foo', 'bar')). + * array('foo', 'bar'), * ), * '#submit' => array('some_submit_function'), // #submit required. * ); * @endcode * - * This will require $form_state['values']['step1'] and everything within it - * (for example, $form_state['values']['step1']['choice']) to be valid, so - * calls to self::setErrorByName('step1', $message) or + * This will require $form_state->getValue('step1') and everything within it + * (for example, $form_state->getValue(array('step1', 'choice'))) to be valid, + * so calls to self::setErrorByName('step1', $message) or * self::setErrorByName('step1][choice', $message) will prevent the submit * handlers from running, and result in the error message being displayed to * the user. However, calls to self::setErrorByName('step2', $message) and * self::setErrorByName('step2][groupX][choiceY', $message) will be * suppressed, resulting in the message not being displayed to the user, and - * the submit handlers will run despite $form_state['values']['step2'] and - * $form_state['values']['step2']['groupX']['choiceY'] containing invalid - * values. Errors for an invalid $form_state['values']['foo'] will be + * the submit handlers will run despite $form_state->getValue('step2') and + * $form_state->getValue(array('step2', 'groupX', 'choiceY')) containing + * invalid values. Errors for an invalid $form_state->getValue('foo') will be * suppressed, but errors flagging invalid values for - * $form_state['values']['foo']['bar'] and everything within it will be - * flagged and submission prevented. + * $form_state->getValue(array('foo', 'bar')) and everything within it will + * be flagged and submission prevented. * * Partial form validation is implemented by suppressing errors rather than by * skipping the input processing and validation steps entirely, because some * forms have button-level submit handlers that call Drupal API functions that - * assume that certain data exists within $form_state['values'], and while not - * doing anything with that data that requires it to be valid, PHP errors + * assume that certain data exists within $form_state->getValues(), and while + * not doing anything with that data that requires it to be valid, PHP errors * would be triggered if the input processing and validation steps were fully * skipped. * diff --git a/core/lib/Drupal/Core/Form/FormValidator.php b/core/lib/Drupal/Core/Form/FormValidator.php index 2e859ef694e..817bf0a85b1 100644 --- a/core/lib/Drupal/Core/Form/FormValidator.php +++ b/core/lib/Drupal/Core/Form/FormValidator.php @@ -91,7 +91,7 @@ class FormValidator implements FormValidatorInterface { // If the session token was set by self::prepareForm(), ensure that it // matches the current user's session. if (isset($form['#token'])) { - if (!$this->csrfToken->validate($form_state['values']['form_token'], $form['#token'])) { + if (!$this->csrfToken->validate($form_state->getValue('form_token'), $form['#token'])) { $url = $this->requestStack->getCurrentRequest()->getRequestUri(); // Setting this error will cause the form to fail validation. @@ -130,17 +130,17 @@ class FormValidator implements FormValidatorInterface { if (isset($form_state['triggering_element']['#limit_validation_errors']) && $form_state['triggering_element']['#limit_validation_errors'] !== FALSE) { $values = array(); foreach ($form_state['triggering_element']['#limit_validation_errors'] as $section) { - // If the section exists within $form_state['values'], even if the value - // is NULL, copy it to $values. + // If the section exists within $form_state->getValues(), even if the + // value is NULL, copy it to $values. $section_exists = NULL; - $value = NestedArray::getValue($form_state['values'], $section, $section_exists); + $value = NestedArray::getValue($form_state->getValues(), $section, $section_exists); if ($section_exists) { NestedArray::setValue($values, $section, $value); } } // A button's #value does not require validation, so for convenience we // allow the value of the clicked button to be retained in its normal - // $form_state['values'] locations, even if these locations are not + // $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']; @@ -149,20 +149,20 @@ class FormValidator implements FormValidatorInterface { // 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']; - if (!NestedArray::keyExists($values, $parents) && NestedArray::getValue($form_state['values'], $parents) === $button_value) { + if (!NestedArray::keyExists($values, $parents) && NestedArray::getValue($form_state->getValues(), $parents) === $button_value) { NestedArray::setValue($values, $parents, $button_value); } // Additionally, self::doBuildForm() places the button value in - // $form_state['values'][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 // what may already be in $values. $name = $form_state['triggering_element']['#name']; - if (!isset($values[$name]) && isset($form_state['values'][$name]) && $form_state['values'][$name] === $button_value) { + if (!isset($values[$name]) && $form_state->getValue($name) === $button_value) { $values[$name] = $button_value; } } - $form_state['values'] = $values; + $form_state->set('values', $values); } } @@ -194,8 +194,8 @@ class FormValidator implements FormValidatorInterface { * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. The current user-submitted data is stored - * in $form_state['values'], though form validation functions are passed an - * explicit copy of the values for the sake of simplicity. Validation + * in $form_state->getValues(), though form validation functions are passed + * 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; @@ -291,8 +291,8 @@ class FormValidator implements FormValidatorInterface { * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. The current user-submitted data is stored - * in $form_state['values'], though form validation functions are passed an - * explicit copy of the values for the sake of simplicity. Validation + * in $form_state->getValues(), though form validation functions are passed + * 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; @@ -333,7 +333,7 @@ class FormValidator implements FormValidatorInterface { // @see form_process_select() elseif ($elements['#type'] == 'select' && !$elements['#multiple'] && $elements['#required'] && !isset($elements['#default_value']) && $elements['#value'] === $elements['#empty_value']) { $elements['#value'] = NULL; - NestedArray::setValue($form_state['values'], $elements['#parents'], NULL, TRUE); + $form_state->setValueForElement($elements, NULL); } elseif (!isset($options[$elements['#value']])) { $form_state->setError($elements, $this->t('An illegal choice has been detected. Please contact the site administrator.')); diff --git a/core/lib/Drupal/Core/Form/FormValidatorInterface.php b/core/lib/Drupal/Core/Form/FormValidatorInterface.php index a8332388594..061cf9395c5 100644 --- a/core/lib/Drupal/Core/Form/FormValidatorInterface.php +++ b/core/lib/Drupal/Core/Form/FormValidatorInterface.php @@ -39,12 +39,12 @@ interface FormValidatorInterface { * structure (like #process and #after_build callbacks during form building) * in case of a validation error. If a validation handler alters the form * structure, it is responsible for validating the values of changed form - * elements in $form_state['values'] to prevent form submit handlers from + * elements in $form_state->getValues() to prevent form submit handlers from * receiving unvalidated values. * @param $form_state * The current state of the form. The current user-submitted data is stored - * in $form_state['values'], though form validation functions are passed an - * explicit copy of the values for the sake of simplicity. Validation + * in $form_state->getValues(), though form validation functions are passed + * 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; diff --git a/core/lib/Drupal/Core/Installer/Form/SelectLanguageForm.php b/core/lib/Drupal/Core/Installer/Form/SelectLanguageForm.php index a5c073743bd..6285c399e51 100644 --- a/core/lib/Drupal/Core/Installer/Form/SelectLanguageForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SelectLanguageForm.php @@ -99,7 +99,7 @@ class SelectLanguageForm extends FormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $install_state = &$form_state['build_info']['args'][0]; - $install_state['parameters']['langcode'] = $form_state['values']['langcode']; + $install_state['parameters']['langcode'] = $form_state->getValue('langcode'); } } diff --git a/core/lib/Drupal/Core/Installer/Form/SelectProfileForm.php b/core/lib/Drupal/Core/Installer/Form/SelectProfileForm.php index e16c10ece59..9be9d13ea95 100644 --- a/core/lib/Drupal/Core/Installer/Form/SelectProfileForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SelectProfileForm.php @@ -90,7 +90,7 @@ class SelectProfileForm extends FormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { global $install_state; - $install_state['parameters']['profile'] = $form_state['values']['profile']; + $install_state['parameters']['profile'] = $form_state->getValue('profile'); } } diff --git a/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php index 6bbb267047e..c8fdd192c61 100644 --- a/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php @@ -229,7 +229,7 @@ class SiteConfigureForm extends FormBase { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - if ($error = user_validate_name($form_state['values']['account']['name'])) { + if ($error = user_validate_name($form_state->getValue(array('account', 'name')))) { $form_state->setErrorByName('account][name', $error); } } @@ -239,36 +239,39 @@ class SiteConfigureForm extends FormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('system.site') - ->set('name', $form_state['values']['site_name']) - ->set('mail', $form_state['values']['site_mail']) + ->set('name', $form_state->getValue('site_name')) + ->set('mail', $form_state->getValue('site_mail')) ->save(); $this->config('system.date') - ->set('timezone.default', $form_state['values']['date_default_timezone']) - ->set('country.default', $form_state['values']['site_default_country']) + ->set('timezone.default', $form_state->getValue('date_default_timezone')) + ->set('country.default', $form_state->getValue('site_default_country')) ->save(); + $account_values = $form_state->getValue('account'); + // Enable update.module if this option was selected. - if ($form_state['values']['update_status_module'][1]) { + $update_status_module = $form_state->getValue('update_status_module'); + if ($update_status_module[1]) { $this->moduleHandler->install(array('file', 'update'), FALSE); // Add the site maintenance account's email address to the list of // addresses to be notified when updates are available, if selected. - if ($form_state['values']['update_status_module'][2]) { + if ($update_status_module[2]) { // Reset the configuration factory so it is updated with the new module. $this->resetConfigFactory(); - $this->config('update.settings')->set('notification.emails', array($form_state['values']['account']['mail']))->save(); + $this->config('update.settings')->set('notification.emails', array($account_values['mail']))->save(); } } // We precreated user 1 with placeholder values. Let's save the real values. $account = $this->userStorage->load(1); - $account->init = $account->mail = $form_state['values']['account']['mail']; + $account->init = $account->mail = $account_values['mail']; $account->roles = $account->getRoles(); $account->activate(); - $account->timezone = $form_state['values']['date_default_timezone']; - $account->pass = $form_state['values']['account']['pass']; - $account->name = $form_state['values']['account']['name']; + $account->timezone = $form_state->getValue('date_default_timezone'); + $account->pass = $account_values['pass']; + $account->name = $account_values['name']; $account->save(); // Record when this install ran. diff --git a/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php b/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php index e853cba5f1e..71c25e9a133 100644 --- a/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php @@ -116,8 +116,8 @@ class SiteSettingsForm extends FormBase { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - $driver = $form_state['values']['driver']; - $database = $form_state['values'][$driver]; + $driver = $form_state->getValue('driver'); + $database = $form_state->getValue($driver); $drivers = drupal_get_database_types(); $reflection = new \ReflectionClass($drivers[$driver]); $install_namespace = $reflection->getNamespaceName(); @@ -126,7 +126,7 @@ class SiteSettingsForm extends FormBase { $database['driver'] = $driver; $form_state['storage']['database'] = $database; - $errors = install_database_errors($database, $form_state['values']['settings_file']); + $errors = install_database_errors($database, $form_state->getValue('settings_file')); foreach ($errors as $name => $message) { $form_state->setErrorByName($name, $message); } diff --git a/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php b/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php index af3d43ceb15..865195d62f1 100644 --- a/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php +++ b/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php @@ -158,10 +158,10 @@ class MenuLinkDefaultForm implements MenuLinkFormInterface, ContainerInjectionIn */ public function extractFormValues(array &$form, FormStateInterface $form_state) { $new_definition = array(); - $new_definition['hidden'] = $form_state['values']['enabled'] ? 0 : 1; - $new_definition['weight'] = (int) $form_state['values']['weight']; - $new_definition['expanded'] = $form_state['values']['expanded'] ? 1 : 0; - list($menu_name, $parent) = explode(':', $form_state['values']['menu_parent'], 2); + $new_definition['hidden'] = $form_state->getValue('enabled') ? 0 : 1; + $new_definition['weight'] = (int) $form_state->getValue('weight'); + $new_definition['expanded'] = $form_state->getValue('expanded') ? 1 : 0; + list($menu_name, $parent) = explode(':', $form_state->getValue('menu_parent'), 2); if (!empty($menu_name)) { $new_definition['menu_name'] = $menu_name; } diff --git a/core/modules/action/src/Form/ActionAdminManageForm.php b/core/modules/action/src/Form/ActionAdminManageForm.php index 192a81e7c6d..0c42f18a903 100644 --- a/core/modules/action/src/Form/ActionAdminManageForm.php +++ b/core/modules/action/src/Form/ActionAdminManageForm.php @@ -89,10 +89,10 @@ class ActionAdminManageForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - if ($form_state['values']['action']) { + if ($form_state->getValue('action')) { $form_state->setRedirect( 'action.admin_add', - array('action_id' => $form_state['values']['action']) + array('action_id' => $form_state->getValue('action')) ); } } diff --git a/core/modules/action/src/Plugin/Action/EmailAction.php b/core/modules/action/src/Plugin/Action/EmailAction.php index b973204511c..1c67123f25a 100644 --- a/core/modules/action/src/Plugin/Action/EmailAction.php +++ b/core/modules/action/src/Plugin/Action/EmailAction.php @@ -157,7 +157,7 @@ class EmailAction extends ConfigurableActionBase implements ContainerFactoryPlug * {@inheritdoc} */ public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { - if (!valid_email_address($form_state['values']['recipient']) && strpos($form_state['values']['recipient'], ':mail') === FALSE) { + if (!valid_email_address($form_state->getValue('recipient')) && strpos($form_state->getValue('recipient'), ':mail') === FALSE) { // We want the literal %author placeholder to be emphasized in the error message. form_set_error('recipient', $form_state, t('Enter a valid email address or use a token email address such as %author.', array('%author' => '[node:author:mail]'))); } @@ -167,9 +167,9 @@ class EmailAction extends ConfigurableActionBase implements ContainerFactoryPlug * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['recipient'] = $form_state['values']['recipient']; - $this->configuration['subject'] = $form_state['values']['subject']; - $this->configuration['message'] = $form_state['values']['message']; + $this->configuration['recipient'] = $form_state->getValue('recipient'); + $this->configuration['subject'] = $form_state->getValue('subject'); + $this->configuration['message'] = $form_state->getValue('message'); } } diff --git a/core/modules/action/src/Plugin/Action/GotoAction.php b/core/modules/action/src/Plugin/Action/GotoAction.php index 40ba6214bff..833f304702f 100644 --- a/core/modules/action/src/Plugin/Action/GotoAction.php +++ b/core/modules/action/src/Plugin/Action/GotoAction.php @@ -110,7 +110,7 @@ class GotoAction extends ConfigurableActionBase implements ContainerFactoryPlugi * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['url'] = $form_state['values']['url']; + $this->configuration['url'] = $form_state->getValue('url'); } } diff --git a/core/modules/action/src/Plugin/Action/MessageAction.php b/core/modules/action/src/Plugin/Action/MessageAction.php index ece48fa128f..799651457b9 100644 --- a/core/modules/action/src/Plugin/Action/MessageAction.php +++ b/core/modules/action/src/Plugin/Action/MessageAction.php @@ -85,7 +85,7 @@ class MessageAction extends ConfigurableActionBase implements ContainerFactoryPl * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['message'] = $form_state['values']['message']; + $this->configuration['message'] = $form_state->getValue('message'); unset($this->configuration['node']); } diff --git a/core/modules/aggregator/src/Form/OpmlFeedAdd.php b/core/modules/aggregator/src/Form/OpmlFeedAdd.php index 546b44328f3..2eec5072f78 100644 --- a/core/modules/aggregator/src/Form/OpmlFeedAdd.php +++ b/core/modules/aggregator/src/Form/OpmlFeedAdd.php @@ -105,7 +105,7 @@ class OpmlFeedAdd extends FormBase { public function validateForm(array &$form, FormStateInterface $form_state) { // If both fields are empty or filled, cancel. $file_upload = $this->getRequest()->files->get('files[upload]', NULL, TRUE); - if (empty($form_state['values']['remote']) == empty($file_upload)) { + if ($form_state->isValueEmpty('remote') == empty($file_upload)) { $form_state->setErrorByName('remote', $this->t('<em>Either</em> upload a file or enter a URL.')); } } @@ -121,7 +121,7 @@ class OpmlFeedAdd extends FormBase { else { // @todo Move this to a fetcher implementation. try { - $response = $this->httpClient->get($form_state['values']['remote']); + $response = $this->httpClient->get($form_state->getValue('remote')); $data = $response->getBody(TRUE); } catch (RequestException $e) { @@ -168,7 +168,7 @@ class OpmlFeedAdd extends FormBase { $new_feed = $this->feedStorage->create(array( 'title' => $feed['title'], 'url' => $feed['url'], - 'refresh' => $form_state['values']['refresh'], + 'refresh' => $form_state->getValue('refresh'), )); $new_feed->save(); } diff --git a/core/modules/aggregator/src/Form/SettingsForm.php b/core/modules/aggregator/src/Form/SettingsForm.php index 3177742abcf..ff6fd624f2d 100644 --- a/core/modules/aggregator/src/Form/SettingsForm.php +++ b/core/modules/aggregator/src/Form/SettingsForm.php @@ -207,15 +207,15 @@ class SettingsForm extends ConfigFormBase { $instance->submitConfigurationForm($form, $form_state); } - $config->set('items.allowed_html', $form_state['values']['aggregator_allowed_html_tags']); - if (isset($form_state['values']['aggregator_fetcher'])) { - $config->set('fetcher', $form_state['values']['aggregator_fetcher']); + $config->set('items.allowed_html', $form_state->getValue('aggregator_allowed_html_tags')); + if ($form_state->hasValue('aggregator_fetcher')) { + $config->set('fetcher', $form_state->getValue('aggregator_fetcher')); } - if (isset($form_state['values']['aggregator_parser'])) { - $config->set('parser', $form_state['values']['aggregator_parser']); + if ($form_state->hasValue('aggregator_parser')) { + $config->set('parser', $form_state->getValue('aggregator_parser')); } - if (isset($form_state['values']['aggregator_processors'])) { - $config->set('processors', array_filter($form_state['values']['aggregator_processors'])); + if ($form_state->hasValue('aggregator_processors')) { + $config->set('processors', array_filter($form_state->getValue('aggregator_processors'))); } $config->save(); } diff --git a/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php b/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php index 38f47566ed5..2ead20ed404 100644 --- a/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php +++ b/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php @@ -143,8 +143,8 @@ class AggregatorFeedBlock extends BlockBase implements ContainerFactoryPluginInt * {@inheritdoc} */ public function blockSubmit($form, FormStateInterface $form_state) { - $this->configuration['block_count'] = $form_state['values']['block_count']; - $this->configuration['feed'] = $form_state['values']['feed']; + $this->configuration['block_count'] = $form_state->getValue('block_count'); + $this->configuration['feed'] = $form_state->getValue('feed'); } /** diff --git a/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php b/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php index 816b4c04285..642646a3610 100644 --- a/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php +++ b/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php @@ -163,9 +163,9 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['items']['expire'] = $form_state['values']['aggregator_clear']; - $this->configuration['items']['teaser_length'] = $form_state['values']['aggregator_teaser_length']; - $this->configuration['source']['list_max'] = $form_state['values']['aggregator_summary_items']; + $this->configuration['items']['expire'] = $form_state->getValue('aggregator_clear'); + $this->configuration['items']['teaser_length'] = $form_state->getValue('aggregator_teaser_length'); + $this->configuration['source']['list_max'] = $form_state->getValue('aggregator_summary_items'); // @todo Refactor aggregator plugins to ConfigEntity so this is not needed. $this->setConfiguration($this->configuration); } diff --git a/core/modules/aggregator/tests/modules/aggregator_test/src/Plugin/aggregator/processor/TestProcessor.php b/core/modules/aggregator/tests/modules/aggregator_test/src/Plugin/aggregator/processor/TestProcessor.php index b4f5fd565bc..c9307015f3b 100644 --- a/core/modules/aggregator/tests/modules/aggregator_test/src/Plugin/aggregator/processor/TestProcessor.php +++ b/core/modules/aggregator/tests/modules/aggregator_test/src/Plugin/aggregator/processor/TestProcessor.php @@ -92,7 +92,7 @@ class TestProcessor extends AggregatorPluginSettingsBase implements ProcessorInt * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['items']['dummy_length'] = $form_state['values']['dummy_length']; + $this->configuration['items']['dummy_length'] = $form_state->getValue('dummy_length'); $this->setConfiguration($this->configuration); } diff --git a/core/modules/ban/src/Form/BanAdmin.php b/core/modules/ban/src/Form/BanAdmin.php index 19ea5d7b439..94c1d4f0b77 100644 --- a/core/modules/ban/src/Form/BanAdmin.php +++ b/core/modules/ban/src/Form/BanAdmin.php @@ -105,7 +105,7 @@ class BanAdmin extends FormBase { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - $ip = trim($form_state['values']['ip']); + $ip = trim($form_state->getValue('ip')); if ($this->ipManager->isBanned($ip)) { $form_state->setErrorByName('ip', $this->t('This IP address is already banned.')); } @@ -121,7 +121,7 @@ class BanAdmin extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $ip = trim($form_state['values']['ip']); + $ip = trim($form_state->getValue('ip')); $this->ipManager->banIp($ip); drupal_set_message($this->t('The IP address %ip has been banned.', array('%ip' => $ip))); $form_state->setRedirect('ban.admin_page'); diff --git a/core/modules/block/src/BlockBase.php b/core/modules/block/src/BlockBase.php index b18591ad228..a2f5e170c8e 100644 --- a/core/modules/block/src/BlockBase.php +++ b/core/modules/block/src/BlockBase.php @@ -339,19 +339,20 @@ abstract class BlockBase extends ContextAwarePluginBase implements BlockPluginIn */ public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { // Remove the admin_label form item element value so it will not persist. - unset($form_state['values']['admin_label']); + $form_state->unsetValue('admin_label'); // Transform the #type = checkboxes value to a numerically indexed array. - $form_state['values']['cache']['contexts'] = array_values(array_filter($form_state['values']['cache']['contexts'])); + $contexts = $form_state->getValue(array('cache', 'contexts')); + $form_state->setValue(array('cache', 'contexts'), array_values(array_filter($contexts))); foreach ($this->getVisibilityConditions() as $condition_id => $condition) { // Allow the condition to validate the form. $condition_values = new FormState(array( - 'values' => $form_state['values']['visibility'][$condition_id], + 'values' => $form_state->getValue(array('visibility', $condition_id)), )); $condition->validateConfigurationForm($form, $condition_values); // Update the original form values. - $form_state['values']['visibility'][$condition_id] = $condition_values['values']; + $form_state->setValue(array('visibility', $condition_id), $condition_values['values']); } $this->blockValidate($form, $form_state); @@ -373,18 +374,18 @@ abstract class BlockBase extends ContextAwarePluginBase implements BlockPluginIn public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { // Process the block's submission handling if no errors occurred only. if (!form_get_errors($form_state)) { - $this->configuration['label'] = $form_state['values']['label']; - $this->configuration['label_display'] = $form_state['values']['label_display']; - $this->configuration['provider'] = $form_state['values']['provider']; - $this->configuration['cache'] = $form_state['values']['cache']; + $this->configuration['label'] = $form_state->getValue('label'); + $this->configuration['label_display'] = $form_state->getValue('label_display'); + $this->configuration['provider'] = $form_state->getValue('provider'); + $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['values']['visibility'][$condition_id], + 'values' => $form_state->getValue(array('visibility', $condition_id)), )); $condition->submitConfigurationForm($form, $condition_values); // Update the original form values. - $form_state['values']['visibility'][$condition_id] = $condition_values['values']; + $form_state->setValue(array('visibility', $condition_id), $condition_values['values']); } $this->blockSubmit($form, $form_state); } diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index ad193635b84..e289086e4a4 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -128,7 +128,7 @@ class BlockForm extends EntityForm { * Handles switching the available regions based on the selected theme. */ public function themeSwitch($form, FormStateInterface $form_state) { - $form['region']['#options'] = system_region_list($form_state['values']['theme'], REGIONS_VISIBLE); + $form['region']['#options'] = system_region_list($form_state->getValue('theme'), REGIONS_VISIBLE); return $form['region']; } @@ -150,12 +150,12 @@ class BlockForm extends EntityForm { // 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['values']['settings'] + 'values' => $form_state->getValue('settings') )); // Call the plugin validate handler. $this->entity->getPlugin()->validateConfigurationForm($form, $settings); // Update the original form values. - $form_state['values']['settings'] = $settings['values']; + $form_state->setValue('settings', $settings['values']); } /** @@ -169,13 +169,13 @@ class BlockForm extends EntityForm { // 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['values']['settings'], + 'values' => $form_state->getValue('settings'), )); // Call the plugin submit handler. $entity->getPlugin()->submitConfigurationForm($form, $settings); // Update the original form values. - $form_state['values']['settings'] = $settings['values']; + $form_state->setValue('settings', $settings['values']); // Save the settings of the plugin. $entity->save(); @@ -184,7 +184,7 @@ class BlockForm extends EntityForm { $form_state->setRedirect( 'block.admin_display_theme', array( - 'theme' => $form_state['values']['theme'], + 'theme' => $form_state->getValue('theme'), ), array('query' => array('block-placement' => drupal_html_class($this->entity->id()))) ); diff --git a/core/modules/block/src/BlockListBuilder.php b/core/modules/block/src/BlockListBuilder.php index 1b26b9fcd5a..6717745b96a 100644 --- a/core/modules/block/src/BlockListBuilder.php +++ b/core/modules/block/src/BlockListBuilder.php @@ -399,10 +399,11 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface * Form submission handler for the main block administration form. */ public function submitForm(array &$form, FormStateInterface $form_state) { - $entities = entity_load_multiple('block', array_keys($form_state['values']['blocks'])); + $entities = entity_load_multiple('block', array_keys($form_state->getValue('blocks'))); foreach ($entities as $entity_id => $entity) { - $entity->set('weight', $form_state['values']['blocks'][$entity_id]['weight']); - $entity->set('region', $form_state['values']['blocks'][$entity_id]['region']); + $entity_values = $form_state->getValue(array('blocks', $entity_id)); + $entity->set('weight', $entity_values['weight']); + $entity->set('region', $entity_values['region']); if ($entity->get('region') == BlockInterface::BLOCK_REGION_NONE) { $entity->disable(); } diff --git a/core/modules/block/src/Plugin/views/display/Block.php b/core/modules/block/src/Plugin/views/display/Block.php index 0e2e968f2fe..9f4821333aa 100644 --- a/core/modules/block/src/Plugin/views/display/Block.php +++ b/core/modules/block/src/Plugin/views/display/Block.php @@ -209,7 +209,7 @@ class Block extends DisplayPluginBase { case 'block_category': case 'allow': case 'block_hide_empty': - $this->setOption($form_state['section'], $form_state['values'][$form_state['section']]); + $this->setOption($form_state['section'], $form_state->getValue($form_state['section'])); break; } } @@ -289,8 +289,8 @@ class Block extends DisplayPluginBase { * * @see \Drupal\views\Plugin\Block\ViewsBlock::blockSubmit() */ public function blockSubmit(ViewsBlock $block, $form, FormStateInterface $form_state) { - if (isset($form_state['values']['override']['items_per_page'])) { - $block->setConfigurationValue('items_per_page', $form_state['values']['override']['items_per_page']); + if ($items_per_page = $form_state->getValue(array('override', 'items_per_page'))) { + $block->setConfigurationValue('items_per_page', $items_per_page); } } diff --git a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestBlockInstantiation.php b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestBlockInstantiation.php index 255ba63efed..9f5e7730459 100644 --- a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestBlockInstantiation.php +++ b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestBlockInstantiation.php @@ -53,7 +53,7 @@ class TestBlockInstantiation extends BlockBase { * {@inheritdoc} */ public function blockSubmit($form, FormStateInterface $form_state) { - $this->configuration['display_message'] = $form_state['values']['display_message']; + $this->configuration['display_message'] = $form_state->getValue('display_message'); } /** diff --git a/core/modules/block_content/src/BlockContentForm.php b/core/modules/block_content/src/BlockContentForm.php index 101f01b85c0..cd2b95155a5 100644 --- a/core/modules/block_content/src/BlockContentForm.php +++ b/core/modules/block_content/src/BlockContentForm.php @@ -180,7 +180,7 @@ class BlockContentForm extends ContentEntityForm { $block = parent::submit($form, $form_state); // Save as a new revision if requested to do so. - if (!empty($form_state['values']['revision'])) { + if (!$form_state->isValueEmpty('revision')) { $block->setNewRevision(); } @@ -209,7 +209,7 @@ class BlockContentForm extends ContentEntityForm { } if ($block->id()) { - $form_state['values']['id'] = $block->id(); + $form_state->setValue('id', $block->id()); $form_state['id'] = $block->id(); if ($insert) { if (!$theme = $block->getTheme()) { @@ -240,10 +240,10 @@ class BlockContentForm extends ContentEntityForm { */ public function validateForm(array &$form, FormStateInterface $form_state) { if ($this->entity->isNew()) { - $exists = $this->blockContentStorage->loadByProperties(array('info' => $form_state['values']['info'])); + $exists = $this->blockContentStorage->loadByProperties(array('info' => $form_state->getValue('info'))); if (!empty($exists)) { $form_state->setErrorByName('info', $this->t('A block with description %name already exists.', array( - '%name' => $form_state['values']['info'][0]['value'], + '%name' => $form_state->getValue(array('info', 0, 'value')), ))); } } diff --git a/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php b/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php index 8a5a4091001..342d0cc3bbc 100644 --- a/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php +++ b/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php @@ -139,7 +139,7 @@ class BlockContentBlock extends BlockBase implements ContainerFactoryPluginInter public function blockSubmit($form, FormStateInterface $form_state) { // Invalidate the block cache to update custom block-based derivatives. if ($this->moduleHandler->moduleExists('block')) { - $this->configuration['view_mode'] = $form_state['values']['block_content']['view_mode']; + $this->configuration['view_mode'] = $form_state->getValue(array('block_content', 'view_mode')); $this->blockManager->clearCachedDefinitions(); } } diff --git a/core/modules/book/book.module b/core/modules/book/book.module index f5ca37ff2ae..3fe7f33594d 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -196,7 +196,7 @@ function book_form_node_form_alter(&$form, FormStateInterface $form_state, $form * @todo: Remove this in favor of an entity field. */ function book_node_builder($entity_type, NodeInterface $entity, &$form, FormStateInterface $form_state) { - $entity->book = $form_state['values']['book']; + $entity->book = $form_state->getValue('book'); // Always save a revision for non-administrators. if (!empty($entity->book['bid']) && !\Drupal::currentUser()->hasPermission('administer nodes')) { @@ -218,7 +218,7 @@ function book_node_builder($entity_type, NodeInterface $entity, &$form, FormStat */ function book_pick_book_nojs_submit($form, FormStateInterface $form_state) { $node = $form_state['controller']->getEntity(); - $node->book = $form_state['values']['book']; + $node->book = $form_state->getValue('book'); $form_state['rebuild'] = TRUE; } diff --git a/core/modules/book/src/BookManager.php b/core/modules/book/src/BookManager.php index 45f9adf2c9c..ad906ed7cbc 100644 --- a/core/modules/book/src/BookManager.php +++ b/core/modules/book/src/BookManager.php @@ -172,8 +172,8 @@ class BookManager implements BookManagerInterface { public function addFormElements(array $form, FormStateInterface $form_state, NodeInterface $node, AccountInterface $account, $collapsed = TRUE) { // If the form is being processed during the Ajax callback of our book bid // dropdown, then $form_state will hold the value that was selected. - if (isset($form_state['values']['book'])) { - $node->book = $form_state['values']['book']; + if ($form_state->hasValue('book')) { + $node->book = $form_state->getValue('book'); } $form['book'] = array( '#type' => 'details', diff --git a/core/modules/book/src/Form/BookAdminEditForm.php b/core/modules/book/src/Form/BookAdminEditForm.php index 3ea104adf37..6c4af16140b 100644 --- a/core/modules/book/src/Form/BookAdminEditForm.php +++ b/core/modules/book/src/Form/BookAdminEditForm.php @@ -85,7 +85,7 @@ class BookAdminEditForm extends FormBase { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - if ($form_state['values']['tree_hash'] != $form_state['values']['tree_current_hash']) { + if ($form_state->getValue('tree_hash') != $form_state->getValue('tree_current_hash')) { $form_state->setErrorByName('', $this->t('This book has been modified by another user, the changes could not be saved.')); } } @@ -102,7 +102,7 @@ class BookAdminEditForm extends FormBase { foreach (Element::children($form['table']) as $key) { if ($form['table'][$key]['#item']) { $row = $form['table'][$key]; - $values = $form_state['values']['table'][$key]; + $values = $form_state->getValue(array('table', $key)); // Update menu item if moved. if ($row['pid']['#default_value'] != $values['pid'] || $row['weight']['#default_value'] != $values['weight']) { diff --git a/core/modules/book/src/Form/BookOutlineForm.php b/core/modules/book/src/Form/BookOutlineForm.php index c4b435d2054..8530fab254f 100644 --- a/core/modules/book/src/Form/BookOutlineForm.php +++ b/core/modules/book/src/Form/BookOutlineForm.php @@ -106,7 +106,7 @@ class BookOutlineForm extends ContentEntityForm { 'node.view', array('node' => $this->entity->id()) ); - $book_link = $form_state['values']['book']; + $book_link = $form_state->getValue('book'); if (!$book_link['bid']) { drupal_set_message($this->t('No changes were made')); return; diff --git a/core/modules/book/src/Form/BookSettingsForm.php b/core/modules/book/src/Form/BookSettingsForm.php index 5a7d206e952..fe1db372b7d 100644 --- a/core/modules/book/src/Form/BookSettingsForm.php +++ b/core/modules/book/src/Form/BookSettingsForm.php @@ -52,8 +52,8 @@ class BookSettingsForm extends ConfigFormBase { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - $child_type = $form_state['values']['book_child_type']; - if (empty($form_state['values']['book_allowed_types'][$child_type])) { + $child_type = $form_state->getValue('book_child_type'); + if ($form_state->isValueEmpty(array('book_allowed_types', $child_type))) { $form_state->setErrorByName('book_child_type', $this->t('The content type for the %add-child link must be one of those selected as an allowed book outline type.', array('%add-child' => $this->t('Add child page')))); } @@ -64,7 +64,7 @@ class BookSettingsForm extends ConfigFormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $allowed_types = array_filter($form_state['values']['book_allowed_types']); + $allowed_types = array_filter($form_state->getValue('book_allowed_types')); // We need to save the allowed types in an array ordered by machine_name so // that we can save them in the correct order if node type changes. // @see book_node_type_update(). @@ -72,7 +72,7 @@ class BookSettingsForm extends ConfigFormBase { $this->config('book.settings') // Remove unchecked types. ->set('allowed_types', $allowed_types) - ->set('child_type', $form_state['values']['book_child_type']) + ->set('child_type', $form_state->getValue('book_child_type')) ->save(); parent::submitForm($form, $form_state); diff --git a/core/modules/book/src/Plugin/Block/BookNavigationBlock.php b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php index 51d0a0d71d7..ad2ea92376e 100644 --- a/core/modules/book/src/Plugin/Block/BookNavigationBlock.php +++ b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php @@ -105,7 +105,7 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt * {@inheritdoc} */ public function blockSubmit($form, FormStateInterface $form_state) { - $this->configuration['block_mode'] = $form_state['values']['book_block_mode']; + $this->configuration['block_mode'] = $form_state->getValue('book_block_mode'); } /** diff --git a/core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalImage.php b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalImage.php index 4a1329cca9c..23f9c1c8609 100644 --- a/core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalImage.php +++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalImage.php @@ -85,9 +85,9 @@ class DrupalImage extends CKEditorPluginBase implements CKEditorPluginConfigurab * @see editor_image_upload_settings_form() */ function validateImageUploadSettings(array $element, FormStateInterface $form_state) { - $settings = &$form_state['values']['editor']['settings']['plugins']['drupalimage']['image_upload']; + $settings = &$form_state->getValue(array('editor', 'settings', 'plugins', 'drupalimage', 'image_upload')); $form_state['editor']->setImageUploadSettings($settings); - unset($form_state['values']['editor']['settings']['plugins']['drupalimage']); + $form_state->unsetValue(array('editor', 'settings', 'plugins', 'drupalimage')); } } diff --git a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php index b377f73b9bc..c6836270383 100644 --- a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php +++ b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php @@ -237,9 +237,9 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface { */ public function settingsFormSubmit(array $form, FormStateInterface $form_state) { // Modify the toolbar settings by reference. The values in - // $form_state['values']['editor']['settings'] will be saved directly by - // editor_form_filter_admin_format_submit(). - $toolbar_settings = &$form_state['values']['editor']['settings']['toolbar']; + // $form_state->getValue(array('editor', 'settings')) will be saved directly + // by editor_form_filter_admin_format_submit(). + $toolbar_settings = &$form_state->getValue(array('editor', 'settings', 'toolbar')); // The rows key is not built into the form structure, so decode the button // groups data into this new key and remove the button_groups key. @@ -247,8 +247,8 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface { unset($toolbar_settings['button_groups']); // Remove the plugin settings' vertical tabs state; no need to save that. - if (isset($form_state['values']['editor']['settings']['plugins'])) { - unset($form_state['values']['editor']['settings']['plugin_settings']); + if ($form_state->hasValue(array('editor', 'settings', 'plugins'))) { + $form_state->unsetValue(array('editor', 'settings', 'plugin_settings')); } } diff --git a/core/modules/color/color.module b/core/modules/color/color.module index 1f03e18faa9..a06ab8ec69c 100644 --- a/core/modules/color/color.module +++ b/core/modules/color/color.module @@ -291,7 +291,7 @@ function template_preprocess_color_scheme_form(&$variables) { * The current state of the form. * * @return string - * The data that will appear in the $form_state['values'] collection for this + * The data that will appear in the $form_state->getValues() collection for this * element. Return nothing to use the default. */ function color_palette_color_value($element, $input = FALSE, FormStateInterface $form_state) { @@ -302,7 +302,7 @@ function color_palette_color_value($element, $input = FALSE, FormStateInterface // Start with the provided value for this textfield, and validate that if // necessary, falling back on the default value. $value = form_type_textfield_value($element, $input, $form_state); - if (!$value || !isset($form_state['complete form']['#token']) || color_valid_hexadecimal_string($value) || \Drupal::csrfToken()->validate($form_state['values']['form_token'], $form_state['complete form']['#token'])) { + if (!$value || !isset($form_state['complete form']['#token']) || color_valid_hexadecimal_string($value) || \Drupal::csrfToken()->validate($form_state->getValue('form_token'), $form_state['complete form']['#token'])) { return $value; } else { @@ -332,7 +332,7 @@ function color_valid_hexadecimal_string($color) { */ function color_scheme_form_validate($form, FormStateInterface $form_state) { // Only accept hexadecimal CSS color strings to avoid XSS upon use. - foreach ($form_state['values']['palette'] as $key => $color) { + foreach ($form_state->getValue('palette') as $key => $color) { if (!color_valid_hexadecimal_string($color)) { form_set_error('palette][' . $key, $form_state, t('You must enter a valid hexadecimal color value for %name.', array('%name' => $form['color']['palette'][$key]['#title']))); } @@ -347,20 +347,20 @@ function color_scheme_form_validate($form, FormStateInterface $form_state) { function color_scheme_form_submit($form, FormStateInterface $form_state) { // Get theme coloring info. - if (!isset($form_state['values']['info'])) { + if (!$form_state->hasValue('info')) { return; } - $theme = $form_state['values']['theme']; - $info = $form_state['values']['info']; + $theme = $form_state->getValue('theme'); + $info = $form_state->getValue('info'); $config = \Drupal::config('color.theme.' . $theme); // Resolve palette. - $palette = $form_state['values']['palette']; - if ($form_state['values']['scheme'] != '') { + $palette = $form_state->getValue('palette'); + if ($form_state->getValue('scheme') != '') { foreach ($palette as $key => $color) { - if (isset($info['schemes'][$form_state['values']['scheme']]['colors'][$key])) { - $palette[$key] = $info['schemes'][$form_state['values']['scheme']]['colors'][$key]; + if (isset($info['schemes'][$form_state->getValue('scheme')]['colors'][$key])) { + $palette[$key] = $info['schemes'][$form_state->getValue('scheme')]['colors'][$key]; } } $palette += $info['schemes']['default']['colors']; diff --git a/core/modules/comment/src/CommentForm.php b/core/modules/comment/src/CommentForm.php index 2819a56f7dd..7ea66537a4b 100644 --- a/core/modules/comment/src/CommentForm.php +++ b/core/modules/comment/src/CommentForm.php @@ -265,24 +265,24 @@ class CommentForm extends ContentEntityForm { if (!$entity->isNew()) { // Verify the name in case it is being changed from being anonymous. - $accounts = $this->entityManager->getStorage('user')->loadByProperties(array('name' => $form_state['values']['name'])); + $accounts = $this->entityManager->getStorage('user')->loadByProperties(array('name' => $form_state->getValue('name'))); $account = reset($accounts); - $form_state['values']['uid'] = $account ? $account->id() : 0; + $form_state->setValue('uid', $account ? $account->id() : 0); - $date = $form_state['values']['date']; + $date = $form_state->getValue('date'); if ($date instanceOf DrupalDateTime && $date->hasErrors()) { $form_state->setErrorByName('date', $this->t('You have to specify a valid date.')); } - if ($form_state['values']['name'] && !$form_state['values']['is_anonymous'] && !$account) { + if ($form_state->getValue('name') && !$form_state->getValue('is_anonymous') && !$account) { $form_state->setErrorByName('name', $this->t('You have to specify a valid author.')); } } - elseif ($form_state['values']['is_anonymous']) { + elseif ($form_state->getValue('is_anonymous')) { // Validate anonymous comment author fields (if given). If the (original) // author of this comment was an anonymous user, verify that no registered // user with this name exists. - if ($form_state['values']['name']) { - $accounts = $this->entityManager->getStorage('user')->loadByProperties(array('name' => $form_state['values']['name'])); + if ($form_state->getValue('name')) { + $accounts = $this->entityManager->getStorage('user')->loadByProperties(array('name' => $form_state->getValue('name'))); if (!empty($accounts)) { $form_state->setErrorByName('name', $this->t('The name you used belongs to a registered user.')); } @@ -295,8 +295,8 @@ class CommentForm extends ContentEntityForm { */ public function buildEntity(array $form, FormStateInterface $form_state) { $comment = parent::buildEntity($form, $form_state); - if (!empty($form_state['values']['date']) && $form_state['values']['date'] instanceOf DrupalDateTime) { - $comment->setCreatedTime($form_state['values']['date']->getTimestamp()); + if (!$form_state->isValueEmpty('date') && $form_state->getValue('date') instanceOf DrupalDateTime) { + $comment->setCreatedTime($form_state->getValue('date')->getTimestamp()); } else { $comment->setCreatedTime(REQUEST_TIME); @@ -371,7 +371,7 @@ class CommentForm extends ContentEntityForm { if ($this->currentUser->hasPermission('post comments') && ($this->currentUser->hasPermission('administer comments') || $entity->{$field_name}->status == CommentItemInterface::OPEN)) { $comment->save(); - $form_state['values']['cid'] = $comment->id(); + $form_state->setValue('cid', $comment->id()); // Add a log entry. $logger->notice('Comment posted: %subject.', array('%subject' => $comment->getSubject(), 'link' => l(t('View'), 'comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id())))); diff --git a/core/modules/comment/src/Form/CommentAdminOverview.php b/core/modules/comment/src/Form/CommentAdminOverview.php index e65ac1a5f6f..8edba5168ff 100644 --- a/core/modules/comment/src/Form/CommentAdminOverview.php +++ b/core/modules/comment/src/Form/CommentAdminOverview.php @@ -252,9 +252,9 @@ class CommentAdminOverview extends FormBase { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - $form_state['values']['comments'] = array_diff($form_state['values']['comments'], array(0)); + $form_state->setValue('comments', array_diff($form_state->getValue('comments'), array(0))); // We can't execute any 'Update options' if no comments were selected. - if (count($form_state['values']['comments']) == 0) { + if (count($form_state->getValue('comments')) == 0) { $form_state->setErrorByName('', $this->t('Select one or more comments to perform the update on.')); } } @@ -263,8 +263,8 @@ class CommentAdminOverview extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $operation = $form_state['values']['operation']; - $cids = $form_state['values']['comments']; + $operation = $form_state->getValue('operation'); + $cids = $form_state->getValue('comments'); foreach ($cids as $cid) { // Delete operation handled in \Drupal\comment\Form\ConfirmDeleteMultiple diff --git a/core/modules/comment/src/Form/ConfirmDeleteMultiple.php b/core/modules/comment/src/Form/ConfirmDeleteMultiple.php index c3a9b84e14e..2024def099a 100644 --- a/core/modules/comment/src/Form/ConfirmDeleteMultiple.php +++ b/core/modules/comment/src/Form/ConfirmDeleteMultiple.php @@ -118,9 +118,9 @@ class ConfirmDeleteMultiple extends ConfirmFormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - if ($form_state['values']['confirm']) { + if ($form_state->getValue('confirm')) { $this->commentStorage->delete($this->comments); - $count = count($form_state['values']['comments']); + $count = count($form_state->getValue('comments')); $this->logger('content')->notice('Deleted @count comments.', array('@count' => $count)); drupal_set_message(format_plural($count, 'Deleted 1 comment.', 'Deleted @count comments.')); } diff --git a/core/modules/comment/src/Plugin/Action/UnpublishByKeywordComment.php b/core/modules/comment/src/Plugin/Action/UnpublishByKeywordComment.php index 87ec9e7c8bc..3d10bcb8223 100644 --- a/core/modules/comment/src/Plugin/Action/UnpublishByKeywordComment.php +++ b/core/modules/comment/src/Plugin/Action/UnpublishByKeywordComment.php @@ -64,7 +64,7 @@ class UnpublishByKeywordComment extends ConfigurableActionBase { * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['keywords'] = Tags::explode($form_state['values']['keywords']); + $this->configuration['keywords'] = Tags::explode($form_state->getValue('keywords')); } } diff --git a/core/modules/comment/src/Plugin/views/wizard/Comment.php b/core/modules/comment/src/Plugin/views/wizard/Comment.php index 5227f39dddb..0c182664cc2 100644 --- a/core/modules/comment/src/Plugin/views/wizard/Comment.php +++ b/core/modules/comment/src/Plugin/views/wizard/Comment.php @@ -104,8 +104,8 @@ class Comment extends WizardPluginBase { */ protected function pageDisplayOptions(array $form, FormStateInterface $form_state) { $display_options = parent::pageDisplayOptions($form, $form_state); - $row_plugin = isset($form_state['values']['page']['style']['row_plugin']) ? $form_state['values']['page']['style']['row_plugin'] : NULL; - $row_options = isset($form_state['values']['page']['style']['row_options']) ? $form_state['values']['page']['style']['row_options'] : array(); + $row_plugin = $form_state->getValue(array('page', 'style', 'row_plugin')); + $row_options = $form_state->getValue(array('page', 'style', 'row_options'), array()); $this->display_options_row($display_options, $row_plugin, $row_options); return $display_options; } @@ -115,8 +115,8 @@ class Comment extends WizardPluginBase { */ protected function blockDisplayOptions(array $form, FormStateInterface $form_state) { $display_options = parent::blockDisplayOptions($form, $form_state); - $row_plugin = isset($form_state['values']['block']['style']['row_plugin']) ? $form_state['values']['block']['style']['row_plugin'] : NULL; - $row_options = isset($form_state['values']['block']['style']['row_options']) ? $form_state['values']['block']['style']['row_options'] : array(); + $row_plugin = $form_state->getValue(array('block', 'style', 'row_plugin')); + $row_options = $form_state->getValue(array('block', 'style', 'row_options'), array()); $this->display_options_row($display_options, $row_plugin, $row_options); return $display_options; } diff --git a/core/modules/config/src/Form/ConfigImportForm.php b/core/modules/config/src/Form/ConfigImportForm.php index 4353684c372..9ed9b83175b 100644 --- a/core/modules/config/src/Form/ConfigImportForm.php +++ b/core/modules/config/src/Form/ConfigImportForm.php @@ -77,7 +77,7 @@ class ConfigImportForm extends FormBase { public function validateForm(array &$form, FormStateInterface $form_state) { $file_upload = $this->getRequest()->files->get('files[import_tarball]', NULL, TRUE); if ($file_upload && $file_upload->isValid()) { - $form_state['values']['import_tarball'] = $file_upload->getRealPath(); + $form_state->setValue('import_tarball', $file_upload->getRealPath()); } else { $form_state->setErrorByName('import_tarball', $this->t('The import tarball could not be uploaded.')); @@ -88,7 +88,7 @@ class ConfigImportForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - if ($path = $form_state['values']['import_tarball']) { + if ($path = $form_state->getValue('import_tarball')) { $this->configStorage->deleteAll(); try { $archiver = new ArchiveTar($path, 'gz'); diff --git a/core/modules/config/src/Form/ConfigSingleExportForm.php b/core/modules/config/src/Form/ConfigSingleExportForm.php index 28d1069095a..579501a4e09 100644 --- a/core/modules/config/src/Form/ConfigSingleExportForm.php +++ b/core/modules/config/src/Form/ConfigSingleExportForm.php @@ -99,7 +99,7 @@ class ConfigSingleExportForm extends FormBase { 'wrapper' => 'edit-config-type-wrapper', ), ); - $default_type = isset($form_state['values']['config_type']) ? $form_state['values']['config_type'] : $config_type; + $default_type = $form_state->getValue('config_type', $config_type); $form['config_name'] = array( '#title' => $this->t('Configuration name'), '#type' => 'select', @@ -136,7 +136,7 @@ class ConfigSingleExportForm extends FormBase { * Handles switching the configuration type selector. */ public function updateConfigurationType($form, FormStateInterface $form_state) { - $form['config_name']['#options'] = $this->findConfiguration($form_state['values']['config_type']); + $form['config_name']['#options'] = $this->findConfiguration($form_state->getValue('config_type')); return $form['config_name']; } @@ -145,13 +145,13 @@ class ConfigSingleExportForm extends FormBase { */ public function updateExport($form, FormStateInterface $form_state) { // Determine the full config name for the selected config entity. - if ($form_state['values']['config_type'] !== 'system.simple') { - $definition = $this->entityManager->getDefinition($form_state['values']['config_type']); - $name = $definition->getConfigPrefix() . '.' . $form_state['values']['config_name']; + if ($form_state->getValue('config_type') !== 'system.simple') { + $definition = $this->entityManager->getDefinition($form_state->getValue('config_type')); + $name = $definition->getConfigPrefix() . '.' . $form_state->getValue('config_name'); } // The config name is used directly for simple configuration. else { - $name = $form_state['values']['config_name']; + $name = $form_state->getValue('config_name'); } // Read the raw data for this config name, encode it, and display it. $form['export']['#value'] = Yaml::encode($this->configStorage->read($name)); diff --git a/core/modules/config/src/Form/ConfigSingleImportForm.php b/core/modules/config/src/Form/ConfigSingleImportForm.php index f1ffa576e22..515074612d9 100644 --- a/core/modules/config/src/Form/ConfigSingleImportForm.php +++ b/core/modules/config/src/Form/ConfigSingleImportForm.php @@ -185,20 +185,20 @@ class ConfigSingleImportForm extends ConfirmFormBase { } // Decode the submitted import. - $data = Yaml::decode($form_state['values']['import']); + $data = Yaml::decode($form_state->getValue('import')); // Validate for config entities. - if ($form_state['values']['config_type'] !== 'system.simple') { - $definition = $this->entityManager->getDefinition($form_state['values']['config_type']); + if ($form_state->getValue('config_type') !== 'system.simple') { + $definition = $this->entityManager->getDefinition($form_state->getValue('config_type')); $id_key = $definition->getKey('id'); // If a custom entity ID is specified, override the value in the // configuration data being imported. - if (!empty($form_state['values']['custom_entity_id'])) { - $data[$id_key] = $form_state['values']['custom_entity_id']; + if (!$form_state->isValueEmpty('custom_entity_id')) { + $data[$id_key] = $form_state->getValue('custom_entity_id'); } - $entity_storage = $this->entityManager->getStorage($form_state['values']['config_type']); + $entity_storage = $this->entityManager->getStorage($form_state->getValue('config_type')); // If an entity ID was not specified, set an error. if (!isset($data[$id_key])) { $form_state->setErrorByName('import', $this->t('Missing ID key "@id_key" for this @entity_type import.', array('@id_key' => $id_key, '@entity_type' => $definition->getLabel()))); @@ -222,7 +222,7 @@ class ConfigSingleImportForm extends ConfirmFormBase { } } else { - $config = $this->config($form_state['values']['config_name']); + $config = $this->config($form_state->getValue('config_name')); $this->configExists = !$config->isNew() ? $config : FALSE; } @@ -237,7 +237,7 @@ class ConfigSingleImportForm extends ConfirmFormBase { // If this form has not yet been confirmed, store the values and rebuild. if (!$this->data) { $form_state['rebuild'] = TRUE; - $this->data = $form_state['values']; + $this->data = $form_state->getValues(); return; } diff --git a/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php b/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php index f3f769d57a4..d3d63bea026 100644 --- a/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php +++ b/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php @@ -205,7 +205,7 @@ abstract class ConfigTranslationFormBase extends FormBase implements BaseFormIdI * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $form_values = $form_state['values']['config_names']; + $form_values = $form_state->getValue('config_names'); // For the form submission handling, use the raw data. $config_factory = $this->configFactory(); diff --git a/core/modules/config_translation/src/FormElement/DateFormat.php b/core/modules/config_translation/src/FormElement/DateFormat.php index 0e7cd83f87e..9076d2a6f2a 100644 --- a/core/modules/config_translation/src/FormElement/DateFormat.php +++ b/core/modules/config_translation/src/FormElement/DateFormat.php @@ -58,7 +58,7 @@ class DateFormat implements ElementInterface { public static function ajaxSample(array $form, FormStateInterface $form_state) { $response = new AjaxResponse(); - $format_value = NestedArray::getValue($form_state['values'], $form_state['triggering_element']['#array_parents']); + $format_value = NestedArray::getValue($form_state->getValues(), $form_state['triggering_element']['#array_parents']); if (!empty($format_value)) { // Format the date with a custom date format with the given pattern. // The object is not instantiated in an Ajax context, so $this->t() diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index bee5dcfb031..2856fa061a1 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -188,8 +188,8 @@ function contact_form_user_form_alter(&$form, FormStateInterface $form_state) { */ function contact_user_profile_form_submit($form, FormStateInterface $form_state) { $account = $form_state['controller']->getEntity(); - if ($account->id() && isset($form_state['values']['contact'])) { - \Drupal::service('user.data')->set('contact', $account->id(), 'enabled', (int) $form_state['values']['contact']); + if ($account->id() && $form_state->hasValue('contact')) { + \Drupal::service('user.data')->set('contact', $account->id(), 'enabled', (int) $form_state->getValue('contact')); } } @@ -224,6 +224,6 @@ function contact_form_user_admin_settings_alter(&$form, FormStateInterface $form */ function contact_form_user_admin_settings_submit($form, FormStateInterface $form_state) { \Drupal::config('contact.settings') - ->set('user_default_enabled', $form_state['values']['contact_default_status']) + ->set('user_default_enabled', $form_state->getValue('contact_default_status')) ->save(); } diff --git a/core/modules/contact/src/CategoryForm.php b/core/modules/contact/src/CategoryForm.php index e722cda4615..e6defb1f1dc 100644 --- a/core/modules/contact/src/CategoryForm.php +++ b/core/modules/contact/src/CategoryForm.php @@ -77,7 +77,7 @@ class CategoryForm extends EntityForm { parent::validate($form, $form_state); // Validate and each email recipient. - $recipients = explode(',', $form_state['values']['recipients']); + $recipients = explode(',', $form_state->getValue('recipients')); foreach ($recipients as &$recipient) { $recipient = trim($recipient); @@ -85,7 +85,7 @@ class CategoryForm extends EntityForm { $form_state->setErrorByName('recipients', $this->t('%recipient is an invalid email address.', array('%recipient' => $recipient))); } } - $form_state['values']['recipients'] = $recipients; + $form_state->setValue('recipients', $recipients); } /** @@ -108,7 +108,7 @@ class CategoryForm extends EntityForm { } // Update the default category. - if ($form_state['values']['selected']) { + if ($form_state->getValue('selected')) { $contact_settings ->set('default_category', $category->id()) ->save(); diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 9b33f0e58f5..66204772a4d 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -256,7 +256,7 @@ function _content_translation_preprocess_language_content_settings_table(&$varia * @see content_translation_admin_settings_form_submit() */ function content_translation_form_language_content_settings_validate(array $form, FormStateInterface $form_state) { - $settings = &$form_state['values']['settings']; + $settings = &$form_state->getValue('settings'); foreach ($settings as $entity_type => $entity_settings) { foreach ($entity_settings as $bundle => $bundle_settings) { if (!empty($bundle_settings['translatable'])) { @@ -286,8 +286,8 @@ function content_translation_form_language_content_settings_validate(array $form * @see content_translation_admin_settings_form_validate() */ function content_translation_form_language_content_settings_submit(array $form, FormStateInterface $form_state) { - $entity_types = $form_state['values']['entity_types']; - $settings = &$form_state['values']['settings']; + $entity_types = $form_state->getValue('entity_types'); + $settings = &$form_state->getValue('settings'); // If an entity type is not translatable all its bundles and fields must be // marked as non-translatable. Similarly, if a bundle is made non-translatable diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 9b43982f8b8..5ca5e2eba44 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -775,7 +775,7 @@ function content_translation_language_configuration_element_process(array $eleme */ function content_translation_language_configuration_element_validate($element, FormStateInterface $form_state, array $form) { $key = $form_state['content_translation']['key']; - $values = $form_state['values'][$key]; + $values = $form_state->getValue($key); if (!$values['language_show'] && $values['content_translation'] && \Drupal::languageManager()->isLanguageLocked($values['langcode'])) { foreach (\Drupal::languageManager()->getLanguages(LanguageInterface::STATE_LOCKED) as $language) { $locked_languages[] = $language->name; @@ -797,7 +797,7 @@ function content_translation_language_configuration_element_validate($element, F function content_translation_language_configuration_element_submit(array $form, FormStateInterface $form_state) { $key = $form_state['content_translation']['key']; $context = $form_state['language'][$key]; - $enabled = $form_state['values'][$key]['content_translation']; + $enabled = $form_state->getValue(array($key, 'content_translation')); if (content_translation_enabled($context['entity_type'], $context['bundle']) != $enabled) { content_translation_set_config($context['entity_type'], $context['bundle'], 'enabled', $enabled); diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index d2267dee8d5..734ee5d7e55 100644 --- a/core/modules/content_translation/src/ContentTranslationHandler.php +++ b/core/modules/content_translation/src/ContentTranslationHandler.php @@ -379,7 +379,7 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface { if (!isset($entity->translation[$form_langcode])) { $entity->translation[$form_langcode] = array(); } - $values = isset($form_state['values']['content_translation']) ? $form_state['values']['content_translation'] : array(); + $values = $form_state->getValue('content_translation', array()); $translation = &$entity->translation[$form_langcode]; // @todo Use the entity setter when all entities support multilingual @@ -412,8 +412,8 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface { * Validates the submitted content translation metadata. */ function entityFormValidate($form, FormStateInterface $form_state) { - if (!empty($form_state['values']['content_translation'])) { - $translation = $form_state['values']['content_translation']; + if (!$form_state->isValueEmpty('content_translation')) { + $translation = $form_state->getValue('content_translation'); // Validate the "authored by" field. if (!empty($translation['name']) && !($account = user_load_by_name($translation['name']))) { form_set_error('content_translation][name', $form_state, t('The translation authoring username %name does not exist.', array('%name' => $translation['name']))); @@ -433,7 +433,7 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface { public function entityFormSourceChange($form, FormStateInterface $form_state) { $form_controller = content_translation_form_controller($form_state); $entity = $form_controller->getEntity(); - $source = $form_state['values']['source_langcode']['source']; + $source = $form_state->getValue(array('source_langcode', 'source')); $entity_type_id = $entity->getEntityTypeId(); $form_state->setRedirect('content_translation.translation_add_' . $entity_type_id, array( diff --git a/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module index e70bad37f11..d0114e280ab 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -126,7 +126,7 @@ function datetime_theme() { function datetime_datetime_widget_validate(&$element, FormStateInterface $form_state) { if (!form_get_errors($form_state)) { $input_exists = FALSE; - $input = NestedArray::getValue($form_state['values'], $element['#parents'], $input_exists); + $input = NestedArray::getValue($form_state->getValues(), $element['#parents'], $input_exists); if ($input_exists) { // The date should have been returned to a date object at this point by // datetime_validate(), which runs before this. @@ -164,7 +164,7 @@ function datetime_datetime_widget_validate(&$element, FormStateInterface $form_s function datetime_datelist_widget_validate(&$element, FormStateInterface $form_state) { if (!form_get_errors($form_state)) { $input_exists = FALSE; - $input = NestedArray::getValue($form_state['values'], $element['#parents'], $input_exists); + $input = NestedArray::getValue($form_state->getValues(), $element['#parents'], $input_exists); if ($input_exists) { // The date should have been returned to a date object at this point by // datetime_validate(), which runs before this. @@ -534,7 +534,7 @@ function form_type_datetime_value($element, $input = FALSE) { function datetime_datetime_validate($element, FormStateInterface $form_state) { $input_exists = FALSE; - $input = NestedArray::getValue($form_state['values'], $element['#parents'], $input_exists); + $input = NestedArray::getValue($form_state->getValues(), $element['#parents'], $input_exists); if ($input_exists) { $title = !empty($element['#title']) ? $element['#title'] : ''; @@ -875,7 +875,7 @@ function form_type_datelist_value($element, $input = FALSE, FormStateInterface $ */ function datetime_datelist_validate($element, FormStateInterface $form_state) { $input_exists = FALSE; - $input = NestedArray::getValue($form_state['values'], $element['#parents'], $input_exists); + $input = NestedArray::getValue($form_state->getValues(), $element['#parents'], $input_exists); if ($input_exists) { // If there's empty input and the field is not required, set it to empty. diff --git a/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeFieldItemList.php b/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeFieldItemList.php index 4ed473b9866..5cd1c244f7b 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeFieldItemList.php +++ b/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeFieldItemList.php @@ -55,8 +55,8 @@ class DateTimeFieldItemList extends FieldItemList { * {@inheritdoc} */ public function defaultValuesFormSubmit(array $element, array &$form, FormStateInterface $form_state) { - if ($form_state['values']['default_value_input']['default_date']) { - return array($form_state['values']['default_value_input']); + if ($form_state->getValue(array('default_value_input', 'default_date'))) { + return array($form_state->getValue('default_value_input')); } return array(); } diff --git a/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module index 41ed76afc5a..3531ed93991 100644 --- a/core/modules/dblog/dblog.module +++ b/core/modules/dblog/dblog.module @@ -114,5 +114,5 @@ function dblog_form_system_logging_settings_alter(&$form, FormStateInterface $fo * @see dblog_form_system_logging_settings_alter() */ function dblog_logging_settings_submit($form, FormStateInterface $form_state) { - \Drupal::config('dblog.settings')->set('row_limit', $form_state['values']['dblog_row_limit'])->save(); + \Drupal::config('dblog.settings')->set('row_limit', $form_state->getValue('dblog_row_limit'))->save(); } diff --git a/core/modules/dblog/src/Form/DblogFilterForm.php b/core/modules/dblog/src/Form/DblogFilterForm.php index 4a896389d95..4804e7ed8bb 100644 --- a/core/modules/dblog/src/Form/DblogFilterForm.php +++ b/core/modules/dblog/src/Form/DblogFilterForm.php @@ -69,7 +69,7 @@ class DblogFilterForm extends FormBase { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - if (empty($form_state['values']['type']) && empty($form_state['values']['severity'])) { + if ($form_state->isValueEmpty('type') && $form_state->isValueEmpty('severity')) { $form_state->setErrorByName('type', $this->t('You must select something to filter by.')); } } @@ -80,8 +80,8 @@ class DblogFilterForm extends FormBase { public function submitForm(array &$form, FormStateInterface $form_state) { $filters = dblog_filters(); foreach ($filters as $name => $filter) { - if (isset($form_state['values'][$name])) { - $_SESSION['dblog_overview_filter'][$name] = $form_state['values'][$name]; + if ($form_state->hasValue($name)) { + $_SESSION['dblog_overview_filter'][$name] = $form_state->getValue($name); } } } diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index 9aa349ab98d..3e2804dcfe7 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -171,14 +171,14 @@ function editor_form_filter_format_form_alter(&$form, FormStateInterface $form_s */ function editor_form_filter_admin_format_editor_configure($form, FormStateInterface $form_state) { $editor = $form_state['editor']; - if (isset($form_state['values']['editor']['editor'])) { - if ($form_state['values']['editor']['editor'] === '') { + if ($editor_value = $form_state->getValue(array('editor', 'editor'))) { + if ($editor_value === '') { $form_state['editor'] = FALSE; } - elseif (empty($editor) || $form_state['values']['editor']['editor'] !== $editor->getEditor()) { + elseif (empty($editor) || $editor_value !== $editor->getEditor()) { $editor = entity_create('editor', array( 'format' => $form_state['controller']->getEntity()->id(), - 'editor' => $form_state['values']['editor']['editor'], + 'editor' => $editor_value, )); $form_state['editor'] = $editor; } @@ -206,7 +206,7 @@ function editor_form_filter_admin_format_validate($form, FormStateInterface $for // 'Configure' button won't be clicked automatically. So, when the user has // selected a text editor and has then clicked 'Save configuration', we should // point out that the user must still configure the text editor. - if ($form_state['values']['editor']['editor'] !== '' && empty($form_state['editor'])) { + if ($form_state->getValue(array('editor', 'editor')) !== '' && empty($form_state['editor'])) { form_set_error('editor][editor', $form_state, t('You must configure the selected text editor.')); } } @@ -218,7 +218,7 @@ function editor_form_filter_admin_format_submit($form, FormStateInterface $form_ // Delete the existing editor if disabling or switching between editors. $format_id = $form_state['controller']->getEntity()->id(); $original_editor = editor_load($format_id); - if ($original_editor && $original_editor->getEditor() != $form_state['values']['editor']) { + if ($original_editor && $original_editor->getEditor() != $form_state->getValue('editor')) { $original_editor->delete(); } @@ -227,7 +227,7 @@ function editor_form_filter_admin_format_submit($form, FormStateInterface $form_ // Ensure the text format is set: when creating a new text format, this // would equal the empty string. $form_state['editor']->set('format', $format_id); - $form_state['editor']->setSettings($form_state['values']['editor']['settings']); + $form_state['editor']->setSettings($form_state->getValue(array('editor', 'settings'))); $form_state['editor']->save(); } } diff --git a/core/modules/editor/src/Form/EditorImageDialog.php b/core/modules/editor/src/Form/EditorImageDialog.php index cfe096cc5c1..0d7e39466ff 100644 --- a/core/modules/editor/src/Form/EditorImageDialog.php +++ b/core/modules/editor/src/Form/EditorImageDialog.php @@ -190,14 +190,15 @@ class EditorImageDialog extends FormBase { // Convert any uploaded files from the FID values to data-editor-file-uuid // attributes. - if (!empty($form_state['values']['fid'][0])) { - $file = file_load($form_state['values']['fid'][0]); + $fid = $form_state->getValue(array('fid', 0)); + if (!empty($fid)) { + $file = file_load($fid); $file_url = file_create_url($file->getFileUri()); // Transform absolute image URLs to relative image URLs: prevent problems // on multisite set-ups and prevent mixed content errors. $file_url = file_url_transform_relative($file_url); - $form_state['values']['attributes']['src'] = $file_url; - $form_state['values']['attributes']['data-editor-file-uuid'] = $file->uuid(); + $form_state->setValue(array('attributes', 'src'), $file_url); + $form_state->setValue(array('attributes', 'data-editor-file-uuid'), $file->uuid()); } if (form_get_errors($form_state)) { @@ -208,7 +209,7 @@ class EditorImageDialog extends FormBase { $response->addCommand(new HtmlCommand('#editor-image-dialog-form', $output)); } else { - $response->addCommand(new EditorDialogSave($form_state['values'])); + $response->addCommand(new EditorDialogSave($form_state->getValues())); $response->addCommand(new CloseModalDialogCommand()); } diff --git a/core/modules/editor/src/Form/EditorLinkDialog.php b/core/modules/editor/src/Form/EditorLinkDialog.php index 8f31c3c9afe..4965cc5ff34 100644 --- a/core/modules/editor/src/Form/EditorLinkDialog.php +++ b/core/modules/editor/src/Form/EditorLinkDialog.php @@ -90,7 +90,7 @@ class EditorLinkDialog extends FormBase { $response->addCommand(new HtmlCommand('#editor-link-dialog-form', $output)); } else { - $response->addCommand(new EditorDialogSave($form_state['values'])); + $response->addCommand(new EditorDialogSave($form_state->getValues())); $response->addCommand(new CloseModalDialogCommand()); } diff --git a/core/modules/editor/src/Plugin/EditorPluginInterface.php b/core/modules/editor/src/Plugin/EditorPluginInterface.php index 10ad314e015..6f72a807d06 100644 --- a/core/modules/editor/src/Plugin/EditorPluginInterface.php +++ b/core/modules/editor/src/Plugin/EditorPluginInterface.php @@ -52,8 +52,8 @@ interface EditorPluginInterface extends PluginInspectionInterface { * Validates the settings form for an editor. * * The contents of the editor settings are located in - * $form_state['values']['editor']['settings']. Calls to form_error() should - * reflect this location in the settings form. + * $form_state->getValue(array('editor', 'settings')). Calls to form_error() + * should reflect this location in the settings form. * * @param array $form * An associative array containing the structure of the form. @@ -65,8 +65,8 @@ interface EditorPluginInterface extends PluginInspectionInterface { /** * Modifies any values in the form state to prepare them for saving. * - * Values in $form_state['values']['editor']['settings'] are saved by Editor - * module in editor_form_filter_admin_format_submit(). + * Values in $form_state->getValue(array('editor', 'settings')) are saved by + * Editor module in editor_form_filter_admin_format_submit(). * * @param array $form * An associative array containing the structure of the form. diff --git a/core/modules/entity/src/Form/EntityDisplayModeAddForm.php b/core/modules/entity/src/Form/EntityDisplayModeAddForm.php index 296fde24df4..04c83397541 100644 --- a/core/modules/entity/src/Form/EntityDisplayModeAddForm.php +++ b/core/modules/entity/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['values']['id'], $form_state); + form_set_value($form['id'], $this->targetEntityTypeId . '.' . $form_state->getValue('id'), $form_state); } /** diff --git a/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php b/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php index 032a3659226..047b8062cee 100644 --- a/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php +++ b/core/modules/entity_reference/src/ConfigurableEntityReferenceItem.php @@ -252,9 +252,9 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements All * The form state of the (entire) configuration form. */ public static function instanceSettingsFormValidate(array $form, FormStateInterface $form_state) { - if (isset($form_state['values']['instance'])) { - unset($form_state['values']['instance']['settings']['handler_submit']); - $form_state['instance']->settings = $form_state['values']['instance']['settings']; + if ($form_state->hasValue('instance')) { + $form_state->unsetValue(array('instance', 'settings', 'handler_submit')); + $form_state['instance']->settings = $form_state->getValue(array('instance', 'settings')); } } diff --git a/core/modules/field/src/Plugin/views/field/Field.php b/core/modules/field/src/Plugin/views/field/Field.php index b7280bd7bbc..9605cf807d0 100644 --- a/core/modules/field/src/Plugin/views/field/Field.php +++ b/core/modules/field/src/Plugin/views/field/Field.php @@ -678,8 +678,8 @@ class Field extends FieldPluginBase { $item = &$form_state['handler']->options; // Add settings for "field API" fields. - $item['group_column'] = $form_state['values']['options']['group_column']; - $item['group_columns'] = array_filter($form_state['values']['options']['group_columns']); + $item['group_column'] = $form_state->getValue(array('options', 'group_column')); + $item['group_columns'] = array_filter($form_state->getValue(array('options', 'group_columns'))); } /** diff --git a/core/modules/field/src/Tests/FieldAttachOtherTest.php b/core/modules/field/src/Tests/FieldAttachOtherTest.php index a5aee717cca..ec5dd88dc91 100644 --- a/core/modules/field/src/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/src/Tests/FieldAttachOtherTest.php @@ -334,8 +334,8 @@ class FieldAttachOtherTest extends FieldUnitTestBase { $form_state['build_info']['callback_object'] = \Drupal::entityManager()->getFormObject($entity_type, 'default'); \Drupal::formBuilder()->prepareForm('field_test_entity_form', $form, $form_state); drupal_process_form('field_test_entity_form', $form, $form_state); - $form_state['values'][$this->fieldTestData->field_name] = $values; - $form_state['values'][$this->fieldTestData->field_name_2] = $values_2; + $form_state->setValue($this->fieldTestData->field_name, $values); + $form_state->setValue($this->fieldTestData->field_name_2, $values_2); // Extract values for all fields. $entity = clone($entity_init); diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index 400fb216d6d..033832cac52 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -200,7 +200,7 @@ function field_ui_entity_operation(EntityInterface $entity) { * @see field_ui_form_node_type_form_alter() */ function field_ui_form_node_type_form_submit($form, FormStateInterface $form_state) { - if ($form_state['triggering_element']['#parents'][0] === 'save_continue' && $route_info = FieldUI::getOverviewRouteInfo('node', $form_state['values']['type'])) { + if ($form_state['triggering_element']['#parents'][0] === 'save_continue' && $route_info = FieldUI::getOverviewRouteInfo('node', $form_state->getValue('type'))) { $form_state->setRedirectUrl($route_info); } } diff --git a/core/modules/field_ui/src/DisplayOverviewBase.php b/core/modules/field_ui/src/DisplayOverviewBase.php index 9ceddab1f48..5e3b26f3930 100644 --- a/core/modules/field_ui/src/DisplayOverviewBase.php +++ b/core/modules/field_ui/src/DisplayOverviewBase.php @@ -318,8 +318,8 @@ abstract class DisplayOverviewBase extends OverviewBase { // Check the currently selected plugin, and merge persisted values for its // settings. - if (isset($form_state['values']['fields'][$field_name]['type'])) { - $display_options['type'] = $form_state['values']['fields'][$field_name]['type']; + if ($display_type = $form_state->getValue(array('fields', $field_name, 'type'))) { + $display_options['type'] = $display_type; } if (isset($form_state['plugin_settings'][$field_name]['settings'])) { $display_options['settings'] = $form_state['plugin_settings'][$field_name]['settings']; @@ -502,7 +502,7 @@ abstract class DisplayOverviewBase extends OverviewBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $form_values = $form_state['values']; + $form_values = $form_state->getValues(); $display = $this->getEntityDisplay($this->mode); // Collect data for 'regular' fields. @@ -621,11 +621,11 @@ abstract class DisplayOverviewBase extends OverviewBase { case 'update': // Store the saved settings, and set the field back to 'non edit' mode. $field_name = $trigger['#field_name']; - if (isset($form_state['values']['fields'][$field_name]['settings_edit_form']['settings'])) { - $form_state['plugin_settings'][$field_name]['settings'] = $form_state['values']['fields'][$field_name]['settings_edit_form']['settings']; + if ($plugin_settings = $form_state->getValue(array('fields', $field_name, 'settings_edit_form', 'settings'))) { + $form_state['plugin_settings'][$field_name]['settings'] = $plugin_settings; } - if (isset($form_state['values']['fields'][$field_name]['settings_edit_form']['third_party_settings'])) { - $form_state['plugin_settings'][$field_name]['third_party_settings'] = $form_state['values']['fields'][$field_name]['settings_edit_form']['third_party_settings']; + if ($plugin_third_party_settings = $form_state->getValue(array('fields', $field_name, 'settings_edit_form', 'third_party_settings'))) { + $form_state['plugin_settings'][$field_name]['third_party_settings'] = $plugin_third_party_settings; } unset($form_state['plugin_settings_edit']); break; @@ -638,7 +638,7 @@ abstract class DisplayOverviewBase extends OverviewBase { case 'refresh_table': // If the currently edited field is one of the rows to be refreshed, set // it back to 'non edit' mode. - $updated_rows = explode(' ', $form_state['values']['refresh_rows']); + $updated_rows = explode(' ', $form_state->getValue('refresh_rows')); if (isset($form_state['plugin_settings_edit']) && in_array($form_state['plugin_settings_edit'], $updated_rows)) { unset($form_state['plugin_settings_edit']); } @@ -669,7 +669,7 @@ abstract class DisplayOverviewBase extends OverviewBase { break; case 'refresh_table': - $updated_rows = array_values(explode(' ', $form_state['values']['refresh_rows'])); + $updated_rows = array_values(explode(' ', $form_state->getValue('refresh_rows'))); $updated_columns = array('settings_summary', 'settings_edit'); break; } diff --git a/core/modules/field_ui/src/FieldOverview.php b/core/modules/field_ui/src/FieldOverview.php index 04c9805aa84..6d5f15fe3e4 100644 --- a/core/modules/field_ui/src/FieldOverview.php +++ b/core/modules/field_ui/src/FieldOverview.php @@ -298,7 +298,7 @@ class FieldOverview extends OverviewBase { * @see \Drupal\field_ui\FieldOverview::validateForm() */ protected function validateAddNew(array $form, FormStateInterface $form_state) { - $field = $form_state['values']['fields']['_add_new_field']; + $field = $form_state->getValue(array('fields', '_add_new_field')); // Validate if any information was provided in the 'add new field' row. if (array_filter(array($field['label'], $field['field_name'], $field['type']))) { @@ -340,9 +340,7 @@ class FieldOverview extends OverviewBase { protected function validateAddExisting(array $form, FormStateInterface $form_state) { // The form element might be absent if no existing fields can be added to // this bundle. - if (isset($form_state['values']['fields']['_add_existing_field'])) { - $field = $form_state['values']['fields']['_add_existing_field']; - + if ($field = $form_state->getValue(array('fields', '_add_existing_field'))) { // Validate if any information was provided in the // 're-use existing field' row. if (array_filter(array($field['label'], $field['field_name']))) { @@ -364,7 +362,7 @@ class FieldOverview extends OverviewBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $error = FALSE; - $form_values = $form_state['values']['fields']; + $form_values = $form_state->getValue('fields'); $destinations = array(); // Create new field. diff --git a/core/modules/field_ui/src/Form/FieldInstanceEditForm.php b/core/modules/field_ui/src/Form/FieldInstanceEditForm.php index 08bb37bb8bb..4fc453c5648 100644 --- a/core/modules/field_ui/src/Form/FieldInstanceEditForm.php +++ b/core/modules/field_ui/src/Form/FieldInstanceEditForm.php @@ -185,7 +185,7 @@ class FieldInstanceEditForm extends FormBase { $this->instance->default_value = $default_value; // Merge incoming values into the instance. - foreach ($form_state['values']['instance'] as $key => $value) { + foreach ($form_state->getValue('instance') as $key => $value) { $this->instance->$key = $value; } $this->instance->save(); diff --git a/core/modules/field_ui/src/Form/FieldStorageEditForm.php b/core/modules/field_ui/src/Form/FieldStorageEditForm.php index 81306703e95..903a614c428 100644 --- a/core/modules/field_ui/src/Form/FieldStorageEditForm.php +++ b/core/modules/field_ui/src/Form/FieldStorageEditForm.php @@ -162,8 +162,9 @@ class FieldStorageEditForm extends FormBase { */ public function validateForm(array &$form, FormStateInterface $form_state) { // Validate field cardinality. - $cardinality = $form_state['values']['field']['cardinality']; - $cardinality_number = $form_state['values']['field']['cardinality_number']; + $field_values = $form_state->getValue('field'); + $cardinality = $field_values['cardinality']; + $cardinality_number = $field_values['cardinality_number']; if ($cardinality === 'number' && empty($cardinality_number)) { $form_state->setErrorByName('field][cardinality_number', $this->t('Number of values is required.')); } @@ -173,7 +174,7 @@ class FieldStorageEditForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $form_values = $form_state['values']; + $form_values = $form_state->getValues(); $field_values = $form_values['field']; // Save field cardinality. diff --git a/core/modules/file/file.module b/core/modules/file/file.module index a71340dd21e..825594e6cd7 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -1404,11 +1404,11 @@ function file_managed_file_submit($form, FormStateInterface $form_state) { $element['#files'][$fid]->delete(); } } - // Update both $form_state['values'] and $form_state['input'] to reflect + // Update both $form_state->getValues() and $form_state['input'] to reflect // that the file has been removed, so that the form is rebuilt correctly. - // $form_state['values'] must be updated in case additional submit handlers - // run, and for form building functions that run during the rebuild, such as - // when the managed_file element is part of a field widget. + // $form_state->getValues() must be updated in case additional submit + // handlers run, and for form building functions that run during the + // rebuild, such as when the managed_file element is part of a field widget. // $form_state['input'] must be updated so that file_managed_file_value() // has correct information during the rebuild. form_set_value($element['fids'], implode(' ', $fids), $form_state); diff --git a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php index 8778f80e7fc..fdcdb9be674 100644 --- a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php @@ -74,9 +74,9 @@ class FileWidget extends WidgetBase { $field_name = $this->fieldDefinition->getName(); $parents = $form['#parents']; - // Load the items for form rebuilds from the field state as they might not be - // in $form_state['values'] because of validation limitations. Also, they are - // only passed in as $items when editing existing entities. + // Load the items for form rebuilds from the field state as they might not + // be in $form_state->getValues() because of validation limitations. Also, + // they are only passed in as $items when editing existing entities. $field_state = static::getWidgetState($parents, $field_name, $form_state); if (isset($field_state['items'])) { $items->setValue($field_state['items']); @@ -309,7 +309,7 @@ class FileWidget extends WidgetBase { */ public static function validateMultipleCount($element, FormStateInterface $form_state, $form) { $parents = $element['#parents']; - $values = NestedArray::getValue($form_state['values'], $parents); + $values = NestedArray::getValue($form_state->getValues(), $parents); array_pop($parents); $current = count(Element::children(NestedArray::getValue($form, $parents))) - 1; @@ -330,7 +330,7 @@ class FileWidget extends WidgetBase { $message = t('Field %field can only hold @max values but there were @count uploaded. The following files have been omitted as a result: %list.', $args); drupal_set_message($message, 'warning'); $values['fids'] = array_slice($values['fids'], 0, $keep); - NestedArray::setValue($form_state['values'], $element['#parents'], $values); + NestedArray::setValue($form_state->getValues(), $element['#parents'], $values); } } @@ -501,7 +501,7 @@ class FileWidget extends WidgetBase { $field_name = $element['#field_name']; $parents = $element['#field_parents']; - $submitted_values = NestedArray::getValue($form_state['values'], array_slice($button['#parents'], 0, -2)); + $submitted_values = NestedArray::getValue($form_state->getValues(), array_slice($button['#parents'], 0, -2)); foreach ($submitted_values as $delta => $submitted_value) { if (empty($submitted_value['fids'])) { unset($submitted_values[$delta]); @@ -528,7 +528,7 @@ class FileWidget extends WidgetBase { $submitted_values = array_values($new_values); // Update form_state values. - NestedArray::setValue($form_state['values'], array_slice($button['#parents'], 0, -2), $submitted_values); + NestedArray::setValue($form_state->getValues(), array_slice($button['#parents'], 0, -2), $submitted_values); // Update items. $field_state = static::getWidgetState($parents, $field_name, $form_state); diff --git a/core/modules/file/tests/file_module_test/src/Form/FileModuleTestForm.php b/core/modules/file/tests/file_module_test/src/Form/FileModuleTestForm.php index 19264ccac01..05290904591 100644 --- a/core/modules/file/tests/file_module_test/src/Form/FileModuleTestForm.php +++ b/core/modules/file/tests/file_module_test/src/Form/FileModuleTestForm.php @@ -73,10 +73,10 @@ class FileModuleTestForm extends FormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { if ($form['#tree']) { - $uploads = $form_state['values']['nested']['file']; + $uploads = $form_state->getValue(array('nested', 'file')); } else { - $uploads = $form_state['values']['file']; + $uploads = $form_state->getValue('file'); } if ($form['nested']['file']['#extended']) { diff --git a/core/modules/file/tests/file_test/src/Form/FileTestForm.php b/core/modules/file/tests/file_test/src/Form/FileTestForm.php index 68ebf611f64..bdefad46673 100644 --- a/core/modules/file/tests/file_test/src/Form/FileTestForm.php +++ b/core/modules/file/tests/file_test/src/Form/FileTestForm.php @@ -81,8 +81,8 @@ class FileTestForm implements FormInterface { public function submitForm(array &$form, FormStateInterface $form_state) { // Process the upload and perform validation. Note: we're using the // form value for the $replace parameter. - if (!empty($form_state['values']['file_subdir'])) { - $destination = 'temporary://' . $form_state['values']['file_subdir']; + if (!$form_state->isValueEmpty('file_subdir')) { + $destination = 'temporary://' . $form_state->getValue('file_subdir'); file_prepare_directory($destination, FILE_CREATE_DIRECTORY); } else { @@ -91,20 +91,20 @@ class FileTestForm implements FormInterface { // Setup validators. $validators = array(); - if ($form_state['values']['is_image_file']) { + if ($form_state->getValue('is_image_file')) { $validators['file_validate_is_image'] = array(); } - if ($form_state['values']['allow_all_extensions']) { + if ($form_state->getValue('allow_all_extensions')) { $validators['file_validate_extensions'] = array(); } - elseif (!empty($form_state['values']['extensions'])) { - $validators['file_validate_extensions'] = array($form_state['values']['extensions']); + elseif (!$form_state->isValueEmpty('extensions')) { + $validators['file_validate_extensions'] = array($form_state->getValue('extensions')); } - $file = file_save_upload('file_test_upload', $validators, $destination, 0, $form_state['values']['file_test_replace']); + $file = file_save_upload('file_test_upload', $validators, $destination, 0, $form_state->getValue('file_test_replace')); if ($file) { - $form_state['values']['file_test_upload'] = $file; + $form_state->setValue('file_test_upload', $file); drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->getFileUri()))); drupal_set_message(t('File name is @filename.', array('@filename' => $file->getFilename()))); drupal_set_message(t('File MIME type is @mimetype.', array('@mimetype' => $file->getMimeType()))); diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index 82e0ffc5fc2..3fa834b99ef 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -489,8 +489,9 @@ function check_markup($text, $format_id = NULL, $langcode = '', $filter_types_to * The resulting value for the element will be an array holding the value and * the format. For example, the value for the body element will be: * @code - * $form_state['values']['body']['value'] = 'foo'; - * $form_state['values']['body']['format'] = 'foo'; + * $values = $form_state->getValue('body'); + * $values['value'] = 'foo'; + * $values['format'] = 'foo'; * @endcode * * @param $element diff --git a/core/modules/filter/src/FilterFormatFormBase.php b/core/modules/filter/src/FilterFormatFormBase.php index 28ec4dafa2b..65159ddadda 100644 --- a/core/modules/filter/src/FilterFormatFormBase.php +++ b/core/modules/filter/src/FilterFormatFormBase.php @@ -214,8 +214,8 @@ abstract class FilterFormatFormBase extends EntityForm { parent::validate($form, $form_state); // @todo Move trimming upstream. - $format_format = trim($form_state['values']['format']); - $format_name = trim($form_state['values']['name']); + $format_format = trim($form_state->getValue('format')); + $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); @@ -239,7 +239,7 @@ abstract class FilterFormatFormBase extends EntityForm { // Add the submitted form values to the text format, and save it. $format = $this->entity; - foreach ($form_state['values'] as $key => $value) { + foreach ($form_state->getValues() as $key => $value) { if ($key != 'filters') { $format->set($key, $value); } @@ -253,7 +253,7 @@ abstract class FilterFormatFormBase extends EntityForm { // Save user permissions. if ($permission = $format->getPermissionName()) { - foreach ($form_state['values']['roles'] as $rid => $enabled) { + foreach ($form_state->getValue('roles') as $rid => $enabled) { user_role_change_permissions($rid, array($permission => $enabled)); } } diff --git a/core/modules/forum/src/Form/ForumForm.php b/core/modules/forum/src/Form/ForumForm.php index 67e23989e4a..8ee5f435f7e 100644 --- a/core/modules/forum/src/Form/ForumForm.php +++ b/core/modules/forum/src/Form/ForumForm.php @@ -66,7 +66,7 @@ class ForumForm extends TermForm { $term = parent::buildEntity($form, $form_state); // Assign parents from forum parent select field. - $term->parent = array($form_state['values']['parent'][0]); + $term->parent = array($form_state->getValue(array('parent', 0))); return $term; } @@ -83,7 +83,7 @@ class ForumForm extends TermForm { case SAVED_NEW: drupal_set_message($this->t('Created new @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType))); $this->logger('forum')->notice('Created new @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType, 'link' => l($this->t('Edit'), 'admin/structure/forum/edit/' . $this->urlStub . '/' . $term->id()))); - $form_state['values']['tid'] = $term->id(); + $form_state->setValue('tid', $term->id()); break; case SAVED_UPDATED: diff --git a/core/modules/forum/src/ForumSettingsForm.php b/core/modules/forum/src/ForumSettingsForm.php index 51b42a38a90..77f176ddd3e 100644 --- a/core/modules/forum/src/ForumSettingsForm.php +++ b/core/modules/forum/src/ForumSettingsForm.php @@ -66,9 +66,9 @@ class ForumSettingsForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('forum.settings') - ->set('topics.hot_threshold', $form_state['values']['forum_hot_topic']) - ->set('topics.page_limit', $form_state['values']['forum_per_page']) - ->set('topics.order', $form_state['values']['forum_order']) + ->set('topics.hot_threshold', $form_state->getValue('forum_hot_topic')) + ->set('topics.page_limit', $form_state->getValue('forum_per_page')) + ->set('topics.order', $form_state->getValue('forum_order')) ->save(); parent::submitForm($form, $form_state); diff --git a/core/modules/forum/src/Plugin/Block/ForumBlockBase.php b/core/modules/forum/src/Plugin/Block/ForumBlockBase.php index b9bab021716..0ab6a20fcc7 100644 --- a/core/modules/forum/src/Plugin/Block/ForumBlockBase.php +++ b/core/modules/forum/src/Plugin/Block/ForumBlockBase.php @@ -79,7 +79,7 @@ abstract class ForumBlockBase extends BlockBase { * {@inheritdoc} */ public function blockSubmit($form, FormStateInterface $form_state) { - $this->configuration['block_count'] = $form_state['values']['block_count']; + $this->configuration['block_count'] = $form_state->getValue('block_count'); } /** diff --git a/core/modules/image/src/Form/ImageEffectFormBase.php b/core/modules/image/src/Form/ImageEffectFormBase.php index ef3e677e47b..008e0a550c9 100644 --- a/core/modules/image/src/Form/ImageEffectFormBase.php +++ b/core/modules/image/src/Form/ImageEffectFormBase.php @@ -107,11 +107,11 @@ abstract class ImageEffectFormBase extends FormBase { // 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['values']['data'], + 'values' => $form_state->getValue('data'), )); $this->imageEffect->validateConfigurationForm($form, $effect_data); // Update the original form values. - $form_state['values']['data'] = $effect_data['values']; + $form_state->setValue('data', $effect_data['values']); } /** @@ -123,13 +123,13 @@ abstract class ImageEffectFormBase extends FormBase { // 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['values']['data'], + 'values' => $form_state->getValue('data'), )); $this->imageEffect->submitConfigurationForm($form, $effect_data); // Update the original form values. - $form_state['values']['data'] = $effect_data['values']; + $form_state->setValue('data', $effect_data['values']); - $this->imageEffect->setWeight($form_state['values']['weight']); + $this->imageEffect->setWeight($form_state->getValue('weight')); if (!$this->imageEffect->getUuid()) { $this->imageStyle->addImageEffect($this->imageEffect->getConfiguration()); } diff --git a/core/modules/image/src/Form/ImageStyleDeleteForm.php b/core/modules/image/src/Form/ImageStyleDeleteForm.php index 27235993288..e490fa60261 100644 --- a/core/modules/image/src/Form/ImageStyleDeleteForm.php +++ b/core/modules/image/src/Form/ImageStyleDeleteForm.php @@ -63,7 +63,7 @@ class ImageStyleDeleteForm extends EntityConfirmFormBase { * {@inheritdoc} */ public function submit(array $form, FormStateInterface $form_state) { - $this->entity->set('replacementID', $form_state['values']['replacement']); + $this->entity->set('replacementID', $form_state->getValue('replacement')); $this->entity->delete(); drupal_set_message($this->t('Style %name was deleted.', array('%name' => $this->entity->label()))); $form_state->setRedirectUrl($this->getCancelUrl()); diff --git a/core/modules/image/src/Form/ImageStyleEditForm.php b/core/modules/image/src/Form/ImageStyleEditForm.php index 99f766c5e6c..e1ff08ab1c2 100644 --- a/core/modules/image/src/Form/ImageStyleEditForm.php +++ b/core/modules/image/src/Form/ImageStyleEditForm.php @@ -157,7 +157,7 @@ class ImageStyleEditForm extends ImageStyleFormBase { * Validate handler for image effect. */ public function effectValidate($form, FormStateInterface $form_state) { - if (!$form_state['values']['new']) { + if (!$form_state->getValue('new')) { $form_state->setErrorByName('new', $this->t('Select an effect to add.')); } } @@ -168,12 +168,12 @@ class ImageStyleEditForm extends ImageStyleFormBase { public function effectSave($form, FormStateInterface $form_state) { // Update image effect weights. - if (!empty($form_state['values']['effects'])) { - $this->updateEffectWeights($form_state['values']['effects']); + if (!$form_state->isValueEmpty('effects')) { + $this->updateEffectWeights($form_state->getValue('effects')); } - $this->entity->set('name', $form_state['values']['name']); - $this->entity->set('label', $form_state['values']['label']); + $this->entity->set('name', $form_state->getValue('name')); + $this->entity->set('label', $form_state->getValue('label')); $status = parent::save($form, $form_state); @@ -182,7 +182,7 @@ class ImageStyleEditForm extends ImageStyleFormBase { } // Check if this field has any configuration options. - $effect = $this->imageEffectManager->getDefinition($form_state['values']['new']); + $effect = $this->imageEffectManager->getDefinition($form_state->getValue('new')); // Load the configuration form for this option. if (is_subclass_of($effect['class'], '\Drupal\image\ConfigurableImageEffectInterface')) { @@ -190,9 +190,9 @@ class ImageStyleEditForm extends ImageStyleFormBase { 'image.effect_add_form', array( 'image_style' => $this->entity->id(), - 'image_effect' => $form_state['values']['new'], + 'image_effect' => $form_state->getValue('new'), ), - array('query' => array('weight' => $form_state['values']['weight'])) + array('query' => array('weight' => $form_state->getValue('weight'))) ); } // If there's no form, immediately add the image effect. @@ -200,7 +200,7 @@ class ImageStyleEditForm extends ImageStyleFormBase { $effect = array( 'id' => $effect['id'], 'data' => array(), - 'weight' => $form_state['values']['weight'], + 'weight' => $form_state->getValue('weight'), ); $effect_id = $this->entity->addImageEffect($effect); $this->entity->save(); @@ -216,8 +216,8 @@ class ImageStyleEditForm extends ImageStyleFormBase { public function save(array $form, FormStateInterface $form_state) { // Update image effect weights. - if (!empty($form_state['values']['effects'])) { - $this->updateEffectWeights($form_state['values']['effects']); + if (!$form_state->isValueEmpty('effects')) { + $this->updateEffectWeights($form_state->getValue('effects')); } parent::save($form, $form_state); @@ -253,7 +253,7 @@ class ImageStyleEditForm extends ImageStyleFormBase { * {@inheritdoc} */ protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) { - foreach ($form_state['values'] as $key => $value) { + foreach ($form_state->getValues() as $key => $value) { // Do not copy effects here, see self::updateEffectWeights(). if ($key != 'effects') { $entity->set($key, $value); diff --git a/core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php index 1edf23cdec8..37c2c930570 100644 --- a/core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php @@ -94,8 +94,8 @@ class ResizeImageEffect extends ConfigurableImageEffectBase { public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { parent::submitConfigurationForm($form, $form_state); - $this->configuration['height'] = $form_state['values']['height']; - $this->configuration['width'] = $form_state['values']['width']; + $this->configuration['height'] = $form_state->getValue('height'); + $this->configuration['width'] = $form_state->getValue('width'); } } diff --git a/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php index eaaa860ffaa..94c9c48912c 100644 --- a/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php @@ -128,7 +128,7 @@ class RotateImageEffect extends ConfigurableImageEffectBase { * {@inheritdoc} */ public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { - if (!Color::validateHex($form_state['values']['bgcolor'])) { + if (!Color::validateHex($form_state->getValue('bgcolor'))) { form_set_error('bgcolor', $form_state, $this->t('Background color must be a hexadecimal color value.')); } } @@ -139,9 +139,9 @@ class RotateImageEffect extends ConfigurableImageEffectBase { public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { parent::submitConfigurationForm($form, $form_state); - $this->configuration['degrees'] = $form_state['values']['degrees']; - $this->configuration['bgcolor'] = $form_state['values']['bgcolor']; - $this->configuration['random'] = $form_state['values']['random']; + $this->configuration['degrees'] = $form_state->getValue('degrees'); + $this->configuration['bgcolor'] = $form_state->getValue('bgcolor'); + $this->configuration['random'] = $form_state->getValue('random'); } } diff --git a/core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php index a6e1d233df2..338be49eb89 100644 --- a/core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php @@ -85,7 +85,7 @@ class ScaleImageEffect extends ResizeImageEffect { */ public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { parent::validateConfigurationForm($form, $form_state); - if (empty($form_state['values']['width']) && empty($form_state['values']['height'])) { + if ($form_state->isValueEmpty('width') && $form_state->isValueEmpty('height')) { form_set_error('data', $form_state, $this->t('Width and height can not both be blank.')); } } @@ -96,7 +96,7 @@ class ScaleImageEffect extends ResizeImageEffect { public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { parent::submitConfigurationForm($form, $form_state); - $this->configuration['upscale'] = $form_state['values']['upscale']; + $this->configuration['upscale'] = $form_state->getValue('upscale'); } } diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 0b74b14d203..32f741bae21 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -271,7 +271,7 @@ function language_configuration_element_submit(&$form, FormStateInterface $form_ // values. if (isset($form_state['language'])) { foreach ($form_state['language'] as $element_name => $values) { - language_save_default_configuration($values['entity_type'], $values['bundle'], $form_state['values'][$element_name]); + language_save_default_configuration($values['entity_type'], $values['bundle'], $form_state->getValue($element_name)); } } } @@ -676,7 +676,7 @@ function language_form_system_regional_settings_alter(&$form, FormStateInterface */ function language_system_regional_settings_form_submit($form, FormStateInterface $form_state) { $languages = \Drupal::languageManager()->getLanguages(); - $language = $languages[$form_state['values']['site_default_language']]; + $language = $languages[$form_state->getValue('site_default_language')]; $language->default = TRUE; language_save($language); } diff --git a/core/modules/language/src/Form/ContentLanguageSettingsForm.php b/core/modules/language/src/Form/ContentLanguageSettingsForm.php index 47c136e8e95..34ce092892c 100644 --- a/core/modules/language/src/Form/ContentLanguageSettingsForm.php +++ b/core/modules/language/src/Form/ContentLanguageSettingsForm.php @@ -149,7 +149,7 @@ class ContentLanguageSettingsForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->config('language.settings'); - foreach ($form_state['values']['settings'] as $entity_type => $entity_settings) { + foreach ($form_state->getValue('settings') as $entity_type => $entity_settings) { foreach ($entity_settings as $bundle => $bundle_settings) { $config->set(language_get_default_configuration_settings_key($entity_type, $bundle), array( 'langcode' => $bundle_settings['settings']['language']['langcode'], diff --git a/core/modules/language/src/Form/LanguageAddForm.php b/core/modules/language/src/Form/LanguageAddForm.php index 1e9cca9177a..9b6445cf553 100644 --- a/core/modules/language/src/Form/LanguageAddForm.php +++ b/core/modules/language/src/Form/LanguageAddForm.php @@ -33,7 +33,7 @@ class LanguageAddForm extends LanguageFormBase { $predefined_languages = $this->languageManager->getStandardLanguageListWithoutConfigured(); $predefined_languages['custom'] = $this->t('Custom language...'); - $predefined_default = !empty($form_state['values']['predefined_langcode']) ? $form_state['values']['predefined_langcode'] : key($predefined_languages); + $predefined_default = $form_state->getValue('predefined_langcode', key($predefined_languages)); $form['predefined_langcode'] = array( '#type' => 'select', '#title' => $this->t('Language name'), @@ -83,14 +83,14 @@ class LanguageAddForm extends LanguageFormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $langcode = $form_state['values']['predefined_langcode']; + $langcode = $form_state->getValue('predefined_langcode'); if ($langcode == 'custom') { - $langcode = $form_state['values']['langcode']; + $langcode = $form_state->getValue('langcode'); // Custom language form. $language = new Language(array( 'id' => $langcode, - 'name' => $form_state['values']['name'], - 'direction' => $form_state['values']['direction'], + 'name' => $form_state->getValue('name'), + 'direction' => $form_state->getValue('direction'), )); } else { @@ -119,8 +119,8 @@ class LanguageAddForm extends LanguageFormBase { * Validates the language addition form on custom language button. */ public function validateCustom(array $form, FormStateInterface $form_state) { - if ($form_state['values']['predefined_langcode'] == 'custom') { - $langcode = $form_state['values']['langcode']; + if ($form_state->getValue('predefined_langcode') == 'custom') { + $langcode = $form_state->getValue('langcode'); // Reuse the editing form validation routine if we add a custom language. $this->validateCommon($form['custom_language'], $form_state); @@ -137,7 +137,7 @@ class LanguageAddForm extends LanguageFormBase { * Element specific validator for the Add language button. */ public function validatePredefined($form, FormStateInterface $form_state) { - $langcode = $form_state['values']['predefined_langcode']; + $langcode = $form_state->getValue('predefined_langcode'); if ($langcode == 'custom') { $form_state->setErrorByName('predefined_langcode', $this->t('Fill in the language details and save the language with <em>Add custom language</em>.')); } diff --git a/core/modules/language/src/Form/LanguageEditForm.php b/core/modules/language/src/Form/LanguageEditForm.php index c1f1cf8f40b..abac06d2cb7 100644 --- a/core/modules/language/src/Form/LanguageEditForm.php +++ b/core/modules/language/src/Form/LanguageEditForm.php @@ -50,10 +50,10 @@ class LanguageEditForm extends LanguageFormBase { public function submitForm(array &$form, FormStateInterface $form_state) { // Prepare a language object for saving. $languages = language_list(); - $langcode = $form_state['values']['langcode']; + $langcode = $form_state->getValue('langcode'); $language = $languages[$langcode]; - $language->name = $form_state['values']['name']; - $language->direction = $form_state['values']['direction']; + $language->name = $form_state->getValue('name'); + $language->direction = $form_state->getValue('direction'); language_save($language); $form_state->setRedirect('language.admin_overview'); diff --git a/core/modules/language/src/Form/LanguageFormBase.php b/core/modules/language/src/Form/LanguageFormBase.php index ecf8f50a3ae..2c14193193c 100644 --- a/core/modules/language/src/Form/LanguageFormBase.php +++ b/core/modules/language/src/Form/LanguageFormBase.php @@ -99,10 +99,10 @@ abstract class LanguageFormBase extends EntityForm { */ public function validateCommon(array $form, FormStateInterface $form_state) { // Ensure sane field values for langcode and name. - if (!isset($form['langcode_view']) && preg_match('@[^a-zA-Z_-]@', $form_state['values']['langcode'])) { + if (!isset($form['langcode_view']) && preg_match('@[^a-zA-Z_-]@', $form_state->getValue('langcode'))) { $form_state->setErrorByName('langcode', $this->t('%field may only contain characters a-z, underscores, or hyphens.', array('%field' => $form['langcode']['#title']))); } - if ($form_state['values']['name'] != String::checkPlain($form_state['values']['name'])) { + if ($form_state->getValue('name') != String::checkPlain($form_state->getValue('name'))) { $form_state->setErrorByName('name', $this->t('%field cannot contain any markup.', array('%field' => $form['name']['#title']))); } } diff --git a/core/modules/language/src/Form/NegotiationBrowserForm.php b/core/modules/language/src/Form/NegotiationBrowserForm.php index 73509e04c50..39d47cbb8d2 100644 --- a/core/modules/language/src/Form/NegotiationBrowserForm.php +++ b/core/modules/language/src/Form/NegotiationBrowserForm.php @@ -135,8 +135,8 @@ class NegotiationBrowserForm extends ConfigFormBase { // Check all mappings. $mappings = array(); - if (isset($form_state['values']['mappings'])) { - $mappings = $form_state['values']['mappings']; + if ($form_state->hasValue('mappings')) { + $mappings = $form_state->getValue('mappings'); foreach ($mappings as $key => $data) { // Make sure browser_langcode is unique. if (array_key_exists($data['browser_langcode'], $unique_values)) { @@ -150,7 +150,7 @@ class NegotiationBrowserForm extends ConfigFormBase { } // Check new mapping. - $data = $form_state['values']['new_mapping']; + $data = $form_state->getValue('new_mapping'); if (!empty($data['browser_langcode'])) { // Make sure browser_langcode is unique. if (array_key_exists($data['browser_langcode'], $unique_values)) { diff --git a/core/modules/language/src/Form/NegotiationConfigureForm.php b/core/modules/language/src/Form/NegotiationConfigureForm.php index 445e336ef3a..35be7844015 100644 --- a/core/modules/language/src/Form/NegotiationConfigureForm.php +++ b/core/modules/language/src/Form/NegotiationConfigureForm.php @@ -138,11 +138,11 @@ class NegotiationConfigureForm extends FormBase { foreach ($configurable_types as $type) { $customized[$type] = in_array($type, $stored_values); $method_weights = array(); - $enabled_methods = $form_state['values'][$type]['enabled']; + $enabled_methods = $form_state->getValue(array($type, 'enabled')); $enabled_methods[LanguageNegotiationSelected::METHOD_ID] = TRUE; - $method_weights_input = $form_state['values'][$type]['weight']; - if (isset($form_state['values'][$type]['configurable'])) { - $customized[$type] = !empty($form_state['values'][$type]['configurable']); + $method_weights_input = $form_state->getValue(array($type, 'weight')); + if ($form_state->hasValue(array($type, 'configurable'))) { + $customized[$type] = !$form_state->isValueEmpty(array($type, 'configurable')); } foreach ($method_weights_input as $method_id => $weight) { diff --git a/core/modules/language/src/Form/NegotiationSelectedForm.php b/core/modules/language/src/Form/NegotiationSelectedForm.php index f88daa81f60..a0b7df4a1dd 100644 --- a/core/modules/language/src/Form/NegotiationSelectedForm.php +++ b/core/modules/language/src/Form/NegotiationSelectedForm.php @@ -43,7 +43,7 @@ class NegotiationSelectedForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('language.negotiation') - ->set('selected_langcode', $form_state['values']['selected_langcode']) + ->set('selected_langcode', $form_state->getValue('selected_langcode')) ->save(); parent::submitForm($form, $form_state); diff --git a/core/modules/language/src/Form/NegotiationSessionForm.php b/core/modules/language/src/Form/NegotiationSessionForm.php index 92c6dd469e5..d506a557d38 100644 --- a/core/modules/language/src/Form/NegotiationSessionForm.php +++ b/core/modules/language/src/Form/NegotiationSessionForm.php @@ -44,7 +44,7 @@ class NegotiationSessionForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('language.settings') - ->set('session.parameter', $form_state['values']['language_negotiation_session_param']) + ->set('session.parameter', $form_state->getValue('language_negotiation_session_param')) ->save(); parent::submitForm($form, $form_state); diff --git a/core/modules/language/src/Form/NegotiationUrlForm.php b/core/modules/language/src/Form/NegotiationUrlForm.php index 91a5c0a08da..7f7cf58c1e3 100644 --- a/core/modules/language/src/Form/NegotiationUrlForm.php +++ b/core/modules/language/src/Form/NegotiationUrlForm.php @@ -101,12 +101,12 @@ class NegotiationUrlForm extends ConfigFormBase { $languages = language_list(); // Count repeated values for uniqueness check. - $count = array_count_values($form_state['values']['prefix']); + $count = array_count_values($form_state->getValue('prefix')); foreach ($languages as $langcode => $language) { - $value = $form_state['values']['prefix'][$langcode]; + $value = $form_state->getValue(array('prefix', $langcode)); if ($value === '') { - if (!$language->default && $form_state['values']['language_negotiation_url_part'] == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) { + if (!$language->default && $form_state->getValue('language_negotiation_url_part') == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) { // Throw a form error if the prefix is blank for a non-default language, // although it is required for selected negotiation type. $form_state->setErrorByName("prefix][$langcode", t('The prefix may only be left blank for the default language.')); @@ -125,12 +125,12 @@ class NegotiationUrlForm extends ConfigFormBase { } // Count repeated values for uniqueness check. - $count = array_count_values($form_state['values']['domain']); + $count = array_count_values($form_state->getValue('domain')); foreach ($languages as $langcode => $language) { - $value = $form_state['values']['domain'][$langcode]; + $value = $form_state->getValue(array('domain', $langcode)); if ($value === '') { - if (!$language->default && $form_state['values']['language_negotiation_url_part'] == LanguageNegotiationUrl::CONFIG_DOMAIN) { + if (!$language->default && $form_state->getValue('language_negotiation_url_part') == LanguageNegotiationUrl::CONFIG_DOMAIN) { // Throw a form error if the domain is blank for a non-default language, // although it is required for selected negotiation type. $form_state->setErrorByName("domain][$langcode", t('The domain may only be left blank for the default language.')); @@ -145,7 +145,7 @@ class NegotiationUrlForm extends ConfigFormBase { // Domain names should not contain protocol and/or ports. foreach ($languages as $langcode => $name) { - $value = $form_state['values']['domain'][$langcode]; + $value = $form_state->getValue(array('domain', $langcode)); if (!empty($value)) { // Ensure we have exactly one protocol when checking the hostname. $host = 'http://' . str_replace(array('http://', 'https://'), '', $value); @@ -164,12 +164,12 @@ class NegotiationUrlForm extends ConfigFormBase { public function submitForm(array &$form, FormStateInterface $form_state) { // Save selected format (prefix or domain). $this->config('language.negotiation') - ->set('url.source', $form_state['values']['language_negotiation_url_part']) + ->set('url.source', $form_state->getValue('language_negotiation_url_part')) ->save(); // Save new domain and prefix values. - language_negotiation_url_prefixes_save($form_state['values']['prefix']); - language_negotiation_url_domains_save($form_state['values']['domain']); + language_negotiation_url_prefixes_save($form_state->getValue('prefix')); + language_negotiation_url_domains_save($form_state->getValue('domain')); parent::submitForm($form, $form_state); } diff --git a/core/modules/language/src/Plugin/Condition/Language.php b/core/modules/language/src/Plugin/Condition/Language.php index 3ae2b09a751..e0bb12ba5c3 100644 --- a/core/modules/language/src/Plugin/Condition/Language.php +++ b/core/modules/language/src/Plugin/Condition/Language.php @@ -57,7 +57,7 @@ class Language extends ConditionPluginBase { * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['langcodes'] = array_filter($form_state['values']['langcodes']); + $this->configuration['langcodes'] = array_filter($form_state->getValue('langcodes')); parent::submitConfigurationForm($form, $form_state); } diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 8b5109652ad..b44d1a1d0a3 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -713,11 +713,11 @@ function locale_form_language_admin_add_form_alter(&$form, FormStateInterface $f */ function locale_form_language_admin_add_form_alter_submit($form, FormStateInterface $form_state) { if (\Drupal::config('locale.settings')->get('translation.import_enabled')) { - if (empty($form_state['values']['predefined_langcode']) || $form_state['values']['predefined_langcode'] == 'custom') { - $langcode = $form_state['values']['langcode']; + if ($form_state->isValueEmpty('predefined_langcode') || $form_state->getValue('predefined_langcode') == 'custom') { + $langcode = $form_state->getValue('langcode'); } else { - $langcode = $form_state['values']['predefined_langcode']; + $langcode = $form_state->getValue('predefined_langcode'); } // Download and import translations for the newly added language. @@ -752,7 +752,7 @@ function locale_form_language_admin_edit_form_alter(&$form, FormStateInterface $ * Form submission handler for language_admin_edit_form(). */ function locale_form_language_admin_edit_form_alter_submit($form, FormStateInterface $form_state) { - \Drupal::config('locale.settings')->set('translate_english', intval($form_state['values']['locale_translate_english']))->save(); + \Drupal::config('locale.settings')->set('translate_english', intval($form_state->getValue('locale_translate_english')))->save(); } /** @@ -795,12 +795,12 @@ function locale_form_system_file_system_settings_alter(&$form, FormStateInterfac * should be ignored. The old translation status is no longer valid. */ function locale_system_file_system_settings_submit(&$form, FormStateInterface $form_state) { - if ($form['translation_path']['#default_value'] != $form_state['values']['translation_path']) { + if ($form['translation_path']['#default_value'] != $form_state->getValue('translation_path')) { locale_translation_clear_status(); } \Drupal::config('locale.settings') - ->set('translation.path', $form_state['values']['translation_path']) + ->set('translation.path', $form_state->getValue('translation_path')) ->save(); } diff --git a/core/modules/locale/src/Form/ExportForm.php b/core/modules/locale/src/Form/ExportForm.php index 1a7772e3464..631c4aa8aa4 100644 --- a/core/modules/locale/src/Form/ExportForm.php +++ b/core/modules/locale/src/Form/ExportForm.php @@ -130,13 +130,13 @@ class ExportForm extends FormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { // If template is required, language code is not given. - if ($form_state['values']['langcode'] != LanguageInterface::LANGCODE_SYSTEM) { - $language = $this->languageManager->getLanguage($form_state['values']['langcode']); + if ($form_state->getValue('langcode') != LanguageInterface::LANGCODE_SYSTEM) { + $language = $this->languageManager->getLanguage($form_state->getValue('langcode')); } else { $language = NULL; } - $content_options = isset($form_state['values']['content_options']) ? $form_state['values']['content_options'] : array(); + $content_options = $form_state->getValue('content_options', array()); $reader = new PoDatabaseReader(); $language_name = ''; if ($language != NULL) { diff --git a/core/modules/locale/src/Form/ImportForm.php b/core/modules/locale/src/Form/ImportForm.php index 0a41461e1e1..426187f9fb8 100644 --- a/core/modules/locale/src/Form/ImportForm.php +++ b/core/modules/locale/src/Form/ImportForm.php @@ -172,18 +172,18 @@ class ImportForm extends FormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { // Add language, if not yet supported. - $language = $this->languageManager->getLanguage($form_state['values']['langcode']); + $language = $this->languageManager->getLanguage($form_state->getValue('langcode')); if (empty($language)) { $language = new Language(array( - 'id' => $form_state['values']['langcode'], + 'id' => $form_state->getValue('langcode'), )); $language = language_save($language); drupal_set_message($this->t('The language %language has been created.', array('%language' => $this->t($language->name)))); } $options = array( - 'langcode' => $form_state['values']['langcode'], - 'overwrite_options' => $form_state['values']['overwrite_options'], - 'customized' => $form_state['values']['customized'] ? LOCALE_CUSTOMIZED : LOCALE_NOT_CUSTOMIZED, + 'langcode' => $form_state->getValue('langcode'), + 'overwrite_options' => $form_state->getValue('overwrite_options'), + 'customized' => $form_state->getValue('customized') ? LOCALE_CUSTOMIZED : LOCALE_NOT_CUSTOMIZED, ); $this->moduleHandler->loadInclude('locale', 'bulk.inc'); $file = locale_translate_file_attach_properties($this->file, $options); diff --git a/core/modules/locale/src/Form/LocaleSettingsForm.php b/core/modules/locale/src/Form/LocaleSettingsForm.php index 169a19e9746..0157d5ef8c7 100644 --- a/core/modules/locale/src/Form/LocaleSettingsForm.php +++ b/core/modules/locale/src/Form/LocaleSettingsForm.php @@ -87,7 +87,7 @@ class LocaleSettingsForm extends ConfigFormBase { public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); - if (empty($form['#translation_directory']) && $form_state['values']['use_source'] == LOCALE_TRANSLATION_USE_SOURCE_LOCAL) { + if (empty($form['#translation_directory']) && $form_state->getValue('use_source') == LOCALE_TRANSLATION_USE_SOURCE_LOCAL) { $form_state->setErrorByName('use_source', $this->t('You have selected local translation source, but no <a href="@url">Interface translation directory</a> was configured.', array('@url' => url('admin/config/media/file-system')))); } } @@ -96,7 +96,7 @@ class LocaleSettingsForm extends ConfigFormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $values = $form_state['values']; + $values = $form_state->getValues(); $config = $this->config('locale.settings'); $config->set('translation.update_interval_days', $values['update_interval_days'])->save(); @@ -127,7 +127,7 @@ class LocaleSettingsForm extends ConfigFormBase { // Invalidate the cached translation status when the configuration setting // of 'use_source' changes. - if ($form['use_source']['#default_value'] != $form_state['values']['use_source']) { + if ($form['use_source']['#default_value'] != $form_state->getValue('use_source')) { locale_translation_clear_status(); } diff --git a/core/modules/locale/src/Form/TranslateEditForm.php b/core/modules/locale/src/Form/TranslateEditForm.php index ef49ce7a306..131612f843e 100644 --- a/core/modules/locale/src/Form/TranslateEditForm.php +++ b/core/modules/locale/src/Form/TranslateEditForm.php @@ -160,8 +160,8 @@ class TranslateEditForm extends TranslateFormBase { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - $langcode = $form_state['values']['langcode']; - foreach ($form_state['values']['strings'] as $lid => $translations) { + $langcode = $form_state->getValue('langcode'); + foreach ($form_state->getValue('strings') as $lid => $translations) { foreach ($translations['translations'] as $key => $value) { if (!locale_string_is_safe($value)) { $form_state->setErrorByName("strings][$lid][translations][$key", $this->t('The submitted string contains disallowed HTML: %string', array('%string' => $value))); @@ -176,17 +176,17 @@ class TranslateEditForm extends TranslateFormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $langcode = $form_state['values']['langcode']; + $langcode = $form_state->getValue('langcode'); $updated = array(); // Preload all translations for strings in the form. - $lids = array_keys($form_state['values']['strings']); + $lids = array_keys($form_state->getValue('strings')); $existing_translation_objects = array(); foreach ($this->localeStorage->getTranslations(array('lid' => $lids, 'language' => $langcode, 'translated' => TRUE)) as $existing_translation_object) { $existing_translation_objects[$existing_translation_object->lid] = $existing_translation_object; } - foreach ($form_state['values']['strings'] as $lid => $new_translation) { + foreach ($form_state->getValue('strings') as $lid => $new_translation) { $existing_translation = isset($existing_translation_objects[$lid]); // Plural translations are saved in a delimited string. To be able to diff --git a/core/modules/locale/src/Form/TranslateFilterForm.php b/core/modules/locale/src/Form/TranslateFilterForm.php index 176afffcb9a..1a109b53a88 100644 --- a/core/modules/locale/src/Form/TranslateFilterForm.php +++ b/core/modules/locale/src/Form/TranslateFilterForm.php @@ -87,8 +87,8 @@ class TranslateFilterForm extends TranslateFormBase { public function submitForm(array &$form, FormStateInterface $form_state) { $filters = $this->translateFilters(); foreach ($filters as $name => $filter) { - if (isset($form_state['values'][$name])) { - $_SESSION['locale_translate_filter'][$name] = $form_state['values'][$name]; + if ($form_state->hasValue($name)) { + $_SESSION['locale_translate_filter'][$name] = $form_state->getValue($name); } } $form_state->setRedirect('locale.translate_page'); diff --git a/core/modules/locale/src/Form/TranslationStatusForm.php b/core/modules/locale/src/Form/TranslationStatusForm.php index 2cd93d61679..df43b6216fe 100644 --- a/core/modules/locale/src/Form/TranslationStatusForm.php +++ b/core/modules/locale/src/Form/TranslationStatusForm.php @@ -267,7 +267,7 @@ class TranslationStatusForm extends FormBase { */ public function validateForm(array &$form, FormStateInterface $form_state) { // Check if a language has been selected. 'tableselect' doesn't. - if (!array_filter($form_state['values']['langcodes'])) { + if (!array_filter($form_state->getValue('langcodes'))) { $form_state->setErrorByName('', $this->t('Select a language to update.')); } } @@ -277,8 +277,8 @@ class TranslationStatusForm extends FormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->moduleHandler->loadInclude('locale', 'fetch.inc'); - $langcodes = array_filter($form_state['values']['langcodes']); - $projects = array_filter($form_state['values']['projects_update']); + $langcodes = array_filter($form_state->getValue('langcodes')); + $projects = array_filter($form_state->getValue('projects_update')); // Set the translation import options. This determines if existing // translations will be overwritten by imported strings. diff --git a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php index 9da535659b9..35f6d8e4bc4 100644 --- a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php +++ b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php @@ -212,15 +212,15 @@ class MenuLinkContentForm extends ContentEntityForm implements MenuLinkFormInter */ public function extractFormValues(array &$form, FormStateInterface $form_state) { $new_definition = array(); - $new_definition['expanded'] = !empty($form_state['values']['expanded']['value']) ? 1 : 0; - $new_definition['hidden'] = empty($form_state['values']['enabled']) ? 1 : 0; - list($menu_name, $parent) = explode(':', $form_state['values']['menu_parent'], 2); + $new_definition['expanded'] = !$form_state->isValueEmpty(array('expanded', 'value')) ? 1 : 0; + $new_definition['hidden'] = $form_state->isValueEmpty('enabled') ? 1 : 0; + list($menu_name, $parent) = explode(':', $form_state->getValue('menu_parent'), 2); if (!empty($menu_name)) { $new_definition['menu_name'] = $menu_name; } $new_definition['parent'] = isset($parent) ? $parent : ''; - $extracted = $this->extractUrl($form_state['values']['url']); + $extracted = $this->extractUrl($form_state->getValue('url')); $new_definition['url'] = $extracted['url']; $new_definition['route_name'] = $extracted['route_name']; $new_definition['route_parameters'] = $extracted['route_parameters']; @@ -231,9 +231,9 @@ class MenuLinkContentForm extends ContentEntityForm implements MenuLinkFormInter if ($extracted['fragment']) { $new_definition['options']['fragment'] = $extracted['fragment']; } - $new_definition['title'] = $form_state['values']['title'][0]['value']; - $new_definition['description'] = $form_state['values']['description'][0]['value']; - $new_definition['weight'] = (int) $form_state['values']['weight'][0]['value']; + $new_definition['title'] = $form_state->getValue(array('title', 0, 'value')); + $new_definition['description'] = $form_state->getValue(array('description', 0, 'value')); + $new_definition['weight'] = (int) $form_state->getValue(array('weight', 0, 'value')); return $new_definition; } @@ -386,7 +386,7 @@ class MenuLinkContentForm extends ContentEntityForm implements MenuLinkFormInter * The current state of the form. */ protected function doValidate(array $form, FormStateInterface $form_state) { - $extracted = $this->extractUrl($form_state['values']['url']); + $extracted = $this->extractUrl($form_state->getValue('url')); // If both URL and route_name are empty, the entered value is not valid. $valid = FALSE; @@ -399,7 +399,7 @@ class MenuLinkContentForm extends ContentEntityForm implements MenuLinkFormInter $valid = $this->accessManager->checkNamedRoute($extracted['route_name'], $extracted['route_parameters'], $this->account); } if (!$valid) { - $form_state->setErrorByName('url', $this->t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $form_state['values']['url']))); + $form_state->setErrorByName('url', $this->t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $form_state->getValue('url')))); } elseif ($extracted['route_name']) { // The user entered a Drupal path. diff --git a/core/modules/menu_ui/menu_ui.module b/core/modules/menu_ui/menu_ui.module index 092154fd4ce..83528b5195a 100644 --- a/core/modules/menu_ui/menu_ui.module +++ b/core/modules/menu_ui/menu_ui.module @@ -408,8 +408,8 @@ function menu_ui_form_node_form_alter(&$form, FormStateInterface $form_state) { * @see menu_ui_form_node_form_alter() */ function menu_ui_node_submit(EntityInterface $node, $form, FormStateInterface $form_state) { - if (!empty($form_state['values']['menu'])) { - $definition = $form_state['values']['menu']; + if (!$form_state->isValueEmpty('menu')) { + $definition = $form_state->getValue('menu'); if (empty($definition['enabled'])) { if ($definition['entity_id']) { $entity = entity_load('menu_link_content', $definition['entity_id']); @@ -495,17 +495,17 @@ function menu_ui_form_node_type_form_alter(&$form, FormStateInterface $form_stat * @see menu_ui_form_node_type_form_alter(). */ function menu_ui_form_node_type_form_validate(&$form, FormStateInterface $form_state) { - $available_menus = array_filter($form_state['values']['menu_options']); + $available_menus = array_filter($form_state->getValue('menu_options')); // If there is at least one menu allowed, the selected item should be in // one of them. if (count($available_menus)) { - $menu_item_id_parts = explode(':', $form_state['values']['menu_parent']); + $menu_item_id_parts = explode(':', $form_state->getValue('menu_parent')); if (!in_array($menu_item_id_parts[0], $available_menus)) { form_set_error('menu_parent', $form_state, t('The selected menu item is not under one of the selected menus.')); } } else { - $form_state['values']['menu_parent'] = ''; + $form_state->setValue('menu_parent', ''); } } @@ -517,8 +517,8 @@ function menu_ui_form_node_type_form_validate(&$form, FormStateInterface $form_s function menu_ui_form_node_type_form_submit(&$form, FormStateInterface $form_state) { $type = $form_state['controller']->getEntity(); \Drupal::config('menu.entity.node.' . $type->id()) - ->set('available_menus', array_values(array_filter($form_state['values']['menu_options']))) - ->set('parent', $form_state['values']['menu_parent']) + ->set('available_menus', array_values(array_filter($form_state->getValue('menu_options')))) + ->set('parent', $form_state->getValue('menu_parent')) ->save(); } diff --git a/core/modules/menu_ui/src/MenuSettingsForm.php b/core/modules/menu_ui/src/MenuSettingsForm.php index 77c3c157de3..9037bb54bd4 100644 --- a/core/modules/menu_ui/src/MenuSettingsForm.php +++ b/core/modules/menu_ui/src/MenuSettingsForm.php @@ -63,8 +63,8 @@ class MenuSettingsForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('menu_ui.settings') - ->set('main_links', $form_state['values']['menu_main_links_source']) - ->set('secondary_links', $form_state['values']['menu_secondary_links_source']) + ->set('main_links', $form_state->getValue('menu_main_links_source')) + ->set('secondary_links', $form_state->getValue('menu_secondary_links_source')) ->save(); parent::submitForm($form, $form_state); diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php index 9ac1c40b8f5..7f3c8f61e72 100644 --- a/core/modules/node/node.api.php +++ b/core/modules/node/node.api.php @@ -439,7 +439,7 @@ function hook_node_validate(\Drupal\node\NodeInterface $node, $form, \Drupal\Cor * "Preview" button, after form values have been copied to the form state's node * object, but before the node is saved or previewed. It is a chance for modules * to adjust the node's properties from what they are simply after a copy from - * $form_state['values']. This hook is intended for adjusting non-field-related + * $form_state->getValues(). This hook is intended for adjusting non-field-related * properties. * * @param \Drupal\node\NodeInterface $node @@ -454,8 +454,9 @@ function hook_node_validate(\Drupal\node\NodeInterface $node, $form, \Drupal\Cor function hook_node_submit(\Drupal\node\NodeInterface $node, $form, \Drupal\Core\Form\FormStateInterface $form_state) { // Decompose the selected menu parent option into 'menu_name' and 'parent', if // the form used the default parent selection widget. - if (!empty($form_state['values']['menu']['parent'])) { - list($node->menu['menu_name'], $node->menu['parent']) = explode(':', $form_state['values']['menu']['parent']); + $parent = $form_state->getValue(array('menu', 'parent')); + if (!empty($parent)) { + list($node->menu['menu_name'], $node->menu['parent']) = explode(':', $parent); } } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index ff8812505ec..3cd3607177d 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1074,7 +1074,7 @@ function node_form_system_site_information_settings_form_alter(&$form, FormState */ function node_form_system_site_information_settings_form_submit($form, FormStateInterface $form_state) { \Drupal::config('node.settings') - ->set('items_per_page', $form_state['values']['default_nodes_main']) + ->set('items_per_page', $form_state->getValue('default_nodes_main')) ->save(); } @@ -1101,7 +1101,7 @@ function node_form_system_themes_admin_form_alter(&$form, FormStateInterface $fo */ function node_form_system_themes_admin_form_submit($form, FormStateInterface $form_state) { \Drupal::config('node.settings') - ->set('use_admin_theme', $form_state['values']['use_admin_theme']) + ->set('use_admin_theme', $form_state->getValue('use_admin_theme')) ->save(); \Drupal::service('router.builder')->setRebuildNeeded(); } diff --git a/core/modules/node/src/Form/DeleteMultiple.php b/core/modules/node/src/Form/DeleteMultiple.php index 86b81ecfb21..3257e2bda4a 100644 --- a/core/modules/node/src/Form/DeleteMultiple.php +++ b/core/modules/node/src/Form/DeleteMultiple.php @@ -117,7 +117,7 @@ class DeleteMultiple extends ConfirmFormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - if ($form_state['values']['confirm'] && !empty($this->nodes)) { + if ($form_state->getValue('confirm') && !empty($this->nodes)) { $this->storage->delete($this->nodes); $this->tempStoreFactory->get('node_multiple_delete_confirm')->delete(\Drupal::currentUser()->id()); $count = count($this->nodes); diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php index d1dd6545ecc..0965b16229b 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -301,11 +301,11 @@ class NodeForm extends ContentEntityForm { } // Validate the "authored by" field. - if (!empty($form_state['values']['uid']) && !user_load_by_name($form_state['values']['uid'])) { + if (!$form_state->isValueEmpty('uid') && !user_load_by_name($form_state->getValue('uid'))) { // The use of empty() is mandatory in the context of usernames // as the empty string denotes the anonymous user. In case we // are dealing with an anonymous user we set the user ID to 0. - $form_state->setErrorByName('uid', $this->t('The username %name does not exist.', array('%name' => $form_state['values']['uid']))); + $form_state->setErrorByName('uid', $this->t('The username %name does not exist.', array('%name' => $form_state->getValue('uid')))); } // Validate the "authored on" field. @@ -338,7 +338,7 @@ class NodeForm extends ContentEntityForm { $node = parent::submit($form, $form_state); // Save as a new revision if requested to do so. - if (!empty($form_state['values']['revision']) && $form_state['values']['revision'] != FALSE) { + if (!$form_state->isValueEmpty('revision') && $form_state->getValue('revision') != FALSE) { $node->setNewRevision(); // If a new revision is created, save the current user as revision author. $node->setRevisionCreationTime(REQUEST_TIME); @@ -409,15 +409,15 @@ class NodeForm extends ContentEntityForm { $entity = parent::buildEntity($form, $form_state); // A user might assign the node author by entering a user name in the node // form, which we then need to translate to a user ID. - if (!empty($form_state['values']['uid']) && $account = user_load_by_name($form_state['values']['uid'])) { + if (!$form_state->isValueEmpty('uid') && $account = user_load_by_name($form_state->getValue('uid'))) { $entity->setOwnerId($account->id()); } else { $entity->setOwnerId(0); } - if (!empty($form_state['values']['created']) && $form_state['values']['created'] instanceOf DrupalDateTime) { - $entity->setCreatedTime($form_state['values']['created']->getTimestamp()); + if (!$form_state->isValueEmpty('created') && $form_state->getValue('created') instanceOf DrupalDateTime) { + $entity->setCreatedTime($form_state->getValue('created')->getTimestamp()); } else { $entity->setCreatedTime(REQUEST_TIME); @@ -446,7 +446,7 @@ class NodeForm extends ContentEntityForm { } if ($node->id()) { - $form_state['values']['nid'] = $node->id(); + $form_state->setValue('nid', $node->id()); $form_state['nid'] = $node->id(); if ($node->access('view')) { $form_state->setRedirect( diff --git a/core/modules/node/src/NodeTranslationHandler.php b/core/modules/node/src/NodeTranslationHandler.php index 02afb6c26bb..cdcf11f4d7e 100644 --- a/core/modules/node/src/NodeTranslationHandler.php +++ b/core/modules/node/src/NodeTranslationHandler.php @@ -75,14 +75,14 @@ class NodeTranslationHandler extends ContentTranslationHandler { * {@inheritdoc} */ public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state) { - if (isset($form_state['values']['content_translation'])) { + if ($form_state->hasValue('content_translation')) { $form_controller = content_translation_form_controller($form_state); - $translation = &$form_state['values']['content_translation']; + $translation = &$form_state->getValue('content_translation'); $translation['status'] = $form_controller->getEntity()->isPublished(); // $form['content_translation']['name'] is the equivalent field // for translation author uid. - $translation['name'] = $form_state['values']['uid']; - $translation['created'] = $form_state['values']['created']; + $translation['name'] = $form_state->getValue('uid'); + $translation['created'] = $form_state->getValue('created'); } parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state); } diff --git a/core/modules/node/src/NodeTypeForm.php b/core/modules/node/src/NodeTypeForm.php index d6e4a2953f2..c99045f5a7a 100644 --- a/core/modules/node/src/NodeTypeForm.php +++ b/core/modules/node/src/NodeTypeForm.php @@ -166,7 +166,7 @@ class NodeTypeForm extends EntityForm { public function validate(array $form, FormStateInterface $form_state) { parent::validate($form, $form_state); - $id = trim($form_state['values']['type']); + $id = trim($form_state->getValue('type')); // '0' is invalid, since elsewhere we check it using empty(). if ($id == '0') { $form_state->setErrorByName('type', $this->t("Invalid machine-readable name. Enter a name other than %invalid.", array('%invalid' => $id))); diff --git a/core/modules/node/src/Plugin/Action/AssignOwnerNode.php b/core/modules/node/src/Plugin/Action/AssignOwnerNode.php index b2ead476bd1..c80f7c6d57c 100644 --- a/core/modules/node/src/Plugin/Action/AssignOwnerNode.php +++ b/core/modules/node/src/Plugin/Action/AssignOwnerNode.php @@ -119,7 +119,7 @@ class AssignOwnerNode extends ConfigurableActionBase implements ContainerFactory * {@inheritdoc} */ public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { - $exists = (bool) $this->connection->queryRange('SELECT 1 FROM {users} WHERE name = :name', 0, 1, array(':name' => $form_state['values']['owner_name']))->fetchField(); + $exists = (bool) $this->connection->queryRange('SELECT 1 FROM {users} WHERE name = :name', 0, 1, array(':name' => $form_state->getValue('owner_name')))->fetchField(); if (!$exists) { form_set_error('owner_name', $form_state, t('Enter a valid username.')); } @@ -129,7 +129,7 @@ class AssignOwnerNode extends ConfigurableActionBase implements ContainerFactory * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['owner_uid'] = $this->connection->query('SELECT uid from {users} WHERE name = :name', array(':name' => $form_state['values']['owner_name']))->fetchField(); + $this->configuration['owner_uid'] = $this->connection->query('SELECT uid from {users} WHERE name = :name', array(':name' => $form_state->getValue('owner_name')))->fetchField(); } } diff --git a/core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php b/core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php index 7dab8be862b..60bd83652c6 100644 --- a/core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php +++ b/core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php @@ -62,7 +62,7 @@ class UnpublishByKeywordNode extends ConfigurableActionBase { * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['keywords'] = Tags::explode($form_state['values']['keywords']); + $this->configuration['keywords'] = Tags::explode($form_state->getValue('keywords')); } } diff --git a/core/modules/node/src/Plugin/Condition/NodeType.php b/core/modules/node/src/Plugin/Condition/NodeType.php index 9727bed8446..9a2b35b4827 100644 --- a/core/modules/node/src/Plugin/Condition/NodeType.php +++ b/core/modules/node/src/Plugin/Condition/NodeType.php @@ -88,7 +88,7 @@ class NodeType extends ConditionPluginBase implements ContainerFactoryPluginInte * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['bundles'] = array_filter($form_state['values']['bundles']); + $this->configuration['bundles'] = array_filter($form_state->getValue('bundles')); parent::submitConfigurationForm($form, $form_state); } diff --git a/core/modules/node/src/Plugin/Search/NodeSearch.php b/core/modules/node/src/Plugin/Search/NodeSearch.php index d595d160fd8..8ebb9ccb0a5 100644 --- a/core/modules/node/src/Plugin/Search/NodeSearch.php +++ b/core/modules/node/src/Plugin/Search/NodeSearch.php @@ -483,44 +483,44 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter public function buildSearchUrlQuery(FormStateInterface $form_state) { // Read keyword and advanced search information from the form values, // and put these into the GET parameters. - $keys = trim($form_state['values']['keys']); + $keys = trim($form_state->getValue('keys')); // Collect extra filters. $filters = array(); - if (isset($form_state['values']['type']) && is_array($form_state['values']['type'])) { + if ($form_state->hasValue('type') && is_array($form_state->getValue('type'))) { // Retrieve selected types - Form API sets the value of unselected // checkboxes to 0. - foreach ($form_state['values']['type'] as $type) { + foreach ($form_state->getValue('type') as $type) { if ($type) { $filters[] = 'type:' . $type; } } } - if (isset($form_state['values']['term']) && is_array($form_state['values']['term'])) { - foreach ($form_state['values']['term'] as $term) { + if ($form_state->hasValue('term') && is_array($form_state->getValue('term'))) { + foreach ($form_state->getValue('term') as $term) { $filters[] = 'term:' . $term; } } - if (isset($form_state['values']['language']) && is_array($form_state['values']['language'])) { - foreach ($form_state['values']['language'] as $language) { + if ($form_state->hasValue('language') && is_array($form_state->getValue('language'))) { + foreach ($form_state->getValue('language') as $language) { if ($language) { $filters[] = 'language:' . $language; } } } - if ($form_state['values']['or'] != '') { - if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' ' . $form_state['values']['or'], $matches)) { + if ($form_state->getValue('or') != '') { + if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' ' . $form_state->getValue('or'), $matches)) { $keys .= ' ' . implode(' OR ', $matches[1]); } } - if ($form_state['values']['negative'] != '') { - if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' ' . $form_state['values']['negative'], $matches)) { + if ($form_state->getValue('negative') != '') { + if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' ' . $form_state->getValue('negative'), $matches)) { $keys .= ' -' . implode(' -', $matches[1]); } } - if ($form_state['values']['phrase'] != '') { - $keys .= ' "' . str_replace('"', ' ', $form_state['values']['phrase']) . '"'; + if ($form_state->getValue('phrase') != '') { + $keys .= ' "' . str_replace('"', ' ', $form_state->getValue('phrase')) . '"'; } $keys = trim($keys); @@ -592,8 +592,8 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { foreach ($this->getRankings() as $var => $values) { - if (!empty($form_state['values']["rankings_$var"])) { - $this->configuration['rankings'][$var] = $form_state['values']["rankings_$var"]; + if (!$form_state->isValueEmpty("rankings_$var")) { + $this->configuration['rankings'][$var] = $form_state->getValue("rankings_$var"); } else { unset($this->configuration['rankings'][$var]); diff --git a/core/modules/node/src/Plugin/views/wizard/Node.php b/core/modules/node/src/Plugin/views/wizard/Node.php index 0a18ea73e40..93401db13ee 100644 --- a/core/modules/node/src/Plugin/views/wizard/Node.php +++ b/core/modules/node/src/Plugin/views/wizard/Node.php @@ -160,17 +160,18 @@ class Node extends WizardPluginBase { protected function defaultDisplayFiltersUser(array $form, FormStateInterface $form_state) { $filters = parent::defaultDisplayFiltersUser($form, $form_state); - if (!empty($form_state['values']['show']['tagged_with']['tids'])) { + $tids = $form_state->getValue(array('show', 'tagged_with', 'tids')); + if (!empty($tids)) { $filters['tid'] = array( 'id' => 'tid', 'table' => 'taxonomy_index', 'field' => 'tid', - 'value' => $form_state['values']['show']['tagged_with']['tids'], - 'vocabulary' => $form_state['values']['show']['tagged_with']['vocabulary'], + 'value' => $tids, + 'vocabulary' => $form_state->getValue(array('show', 'tagged_with', 'vocabulary')), ); // If the user entered more than one valid term in the autocomplete // field, they probably intended both of them to be applied. - if (count($form_state['values']['show']['tagged_with']['tids']) > 1) { + if (count($tids) > 1) { $filters['tid']['operator'] = 'and'; // Sort the terms so the filter will be displayed as it normally would // on the edit screen. @@ -186,8 +187,8 @@ class Node extends WizardPluginBase { */ protected function pageDisplayOptions(array $form, FormStateInterface $form_state) { $display_options = parent::pageDisplayOptions($form, $form_state); - $row_plugin = isset($form_state['values']['page']['style']['row_plugin']) ? $form_state['values']['page']['style']['row_plugin'] : NULL; - $row_options = isset($form_state['values']['page']['style']['row_options']) ? $form_state['values']['page']['style']['row_options'] : array(); + $row_plugin = $form_state->getValue(array('page', 'style', 'row_plugin')); + $row_options = $form_state->getValue(array('page', 'style', 'row_options'), array()); $this->display_options_row($display_options, $row_plugin, $row_options); return $display_options; } @@ -197,8 +198,8 @@ class Node extends WizardPluginBase { */ protected function blockDisplayOptions(array $form, FormStateInterface $form_state) { $display_options = parent::blockDisplayOptions($form, $form_state); - $row_plugin = isset($form_state['values']['block']['style']['row_plugin']) ? $form_state['values']['block']['style']['row_plugin'] : NULL; - $row_options = isset($form_state['values']['block']['style']['row_options']) ? $form_state['values']['block']['style']['row_options'] : array(); + $row_plugin = $form_state->getValue(array('block', 'style', 'row_plugin')); + $row_options = $form_state->getValue(array('block', 'style', 'row_options'), array()); $this->display_options_row($display_options, $row_plugin, $row_options); return $display_options; } diff --git a/core/modules/path/src/Form/EditForm.php b/core/modules/path/src/Form/EditForm.php index 2dd99b0d371..e86c3ec4227 100644 --- a/core/modules/path/src/Form/EditForm.php +++ b/core/modules/path/src/Form/EditForm.php @@ -54,7 +54,7 @@ class EditForm extends PathFormBase { */ public function deleteSubmit(array &$form, FormStateInterface $form_state) { $url = new Url('path.delete', array( - 'pid' => $form_state['values']['pid'], + 'pid' => $form_state->getValue('pid'), )); if ($this->getRequest()->query->has('destination')) { diff --git a/core/modules/path/src/Form/PathFilterForm.php b/core/modules/path/src/Form/PathFilterForm.php index a9de1eac5c6..42e50a45610 100644 --- a/core/modules/path/src/Form/PathFilterForm.php +++ b/core/modules/path/src/Form/PathFilterForm.php @@ -61,7 +61,7 @@ class PathFilterForm extends FormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $form_state->setRedirect('path.admin_overview_filter', array( - 'keys' => trim($form_state['values']['filter']), + 'keys' => trim($form_state->getValue('filter')), )); } diff --git a/core/modules/path/src/Form/PathFormBase.php b/core/modules/path/src/Form/PathFormBase.php index 94eb0792beb..62df767bda8 100644 --- a/core/modules/path/src/Form/PathFormBase.php +++ b/core/modules/path/src/Form/PathFormBase.php @@ -136,12 +136,12 @@ abstract class PathFormBase extends FormBase { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - $source = &$form_state['values']['source']; + $source = &$form_state->getValue('source'); $source = $this->aliasManager->getPathByAlias($source); - $alias = $form_state['values']['alias']; + $alias = $form_state->getValue('alias'); // Language is only set if language.module is enabled, otherwise save for all // languages. - $langcode = isset($form_state['values']['langcode']) ? $form_state['values']['langcode'] : LanguageInterface::LANGCODE_NOT_SPECIFIED; + $langcode = $form_state->getValue('langcode', LanguageInterface::LANGCODE_NOT_SPECIFIED); if ($this->aliasStorage->aliasExists($alias, $langcode, $source)) { $form_state->setErrorByName('alias', t('The alias %alias is already in use in this language.', array('%alias' => $alias))); @@ -158,13 +158,13 @@ abstract class PathFormBase extends FormBase { // Remove unnecessary values. form_state_values_clean($form_state); - $pid = isset($form_state['values']['pid']) ? $form_state['values']['pid'] : 0; - $source = &$form_state['values']['source']; + $pid = $form_state->getValue('pid', 0); + $source = &$form_state->getValue('source'); $source = $this->aliasManager->getPathByAlias($source); - $alias = $form_state['values']['alias']; + $alias = $form_state->getValue('alias'); // Language is only set if language.module is enabled, otherwise save for all // languages. - $langcode = isset($form_state['values']['langcode']) ? $form_state['values']['langcode'] : LanguageInterface::LANGCODE_NOT_SPECIFIED; + $langcode = $form_state->getValue('langcode', LanguageInterface::LANGCODE_NOT_SPECIFIED); $this->aliasStorage->save($source, $alias, $langcode, $pid); diff --git a/core/modules/responsive_image/src/ResponsiveImageMappingForm.php b/core/modules/responsive_image/src/ResponsiveImageMappingForm.php index cfa3d3f77e0..180c75a6ee9 100644 --- a/core/modules/responsive_image/src/ResponsiveImageMappingForm.php +++ b/core/modules/responsive_image/src/ResponsiveImageMappingForm.php @@ -102,13 +102,13 @@ class ResponsiveImageMappingForm extends EntityForm { $responsive_image_mapping = $this->entity; // Only validate on edit. - if (isset($form_state['values']['mappings'])) { - $responsive_image_mapping->setMappings($form_state['values']['mappings']); + if ($form_state->hasValue('mappings')) { + $responsive_image_mapping->setMappings($form_state->getValue('mappings')); // Check if another breakpoint group is selected. - if ($form_state['values']['breakpointGroup'] != $form_state['complete_form']['breakpointGroup']['#default_value']) { + if ($form_state->getValue('breakpointGroup') != $form_state['complete_form']['breakpointGroup']['#default_value']) { // Remove the mappings. - unset($form_state['values']['mappings']); + $form_state->unsetValue('mappings'); } // Make sure at least one mapping is defined. elseif (!$responsive_image_mapping->isNew() && !$responsive_image_mapping->hasMappings()) { diff --git a/core/modules/rest/src/Plugin/views/row/DataFieldRow.php b/core/modules/rest/src/Plugin/views/row/DataFieldRow.php index 68668bab88e..821ed48424e 100644 --- a/core/modules/rest/src/Plugin/views/row/DataFieldRow.php +++ b/core/modules/rest/src/Plugin/views/row/DataFieldRow.php @@ -123,7 +123,7 @@ class DataFieldRow extends RowPluginBase { */ public function validateOptionsForm(&$form, FormStateInterface $form_state) { // Collect an array of aliases to validate. - $aliases = static::extractFromOptionsArray('alias', $form_state['values']['row_options']['field_options']); + $aliases = static::extractFromOptionsArray('alias', $form_state->getValue(array('row_options', 'field_options'))); // If array filter returns empty, no values have been entered. Unique keys // should only be validated if we have some. diff --git a/core/modules/rest/src/Plugin/views/style/Serializer.php b/core/modules/rest/src/Plugin/views/style/Serializer.php index 66529634c2c..e32e332b248 100644 --- a/core/modules/rest/src/Plugin/views/style/Serializer.php +++ b/core/modules/rest/src/Plugin/views/style/Serializer.php @@ -107,7 +107,8 @@ class Serializer extends StylePluginBase { public function submitOptionsForm(&$form, FormStateInterface $form_state) { parent::submitOptionsForm($form, $form_state); - $form_state['values']['style_options']['formats'] = array_filter($form_state['values']['style_options']['formats']); + $formats = $form_state->getValue(array('style_options', 'formats')); + $form_state->setValue(array('style_options', 'formats'), array_filter($formats)); } /** diff --git a/core/modules/search/src/Form/SearchPageFormBase.php b/core/modules/search/src/Form/SearchPageFormBase.php index 0610a205803..7c49fd857c6 100644 --- a/core/modules/search/src/Form/SearchPageFormBase.php +++ b/core/modules/search/src/Form/SearchPageFormBase.php @@ -149,8 +149,8 @@ abstract class SearchPageFormBase extends EntityForm { // Ensure each path is unique. $path = $this->entityQuery->get('search_page') - ->condition('path', $form_state['values']['path']) - ->condition('id', $form_state['values']['id'], '<>') + ->condition('path', $form_state->getValue('path')) + ->condition('id', $form_state->getValue('id'), '<>') ->execute(); if ($path) { $form_state->setErrorByName('path', $this->t('The search page path must be unique.')); diff --git a/core/modules/search/src/Plugin/SearchPluginBase.php b/core/modules/search/src/Plugin/SearchPluginBase.php index bf208dcb7fb..75d030f4550 100644 --- a/core/modules/search/src/Plugin/SearchPluginBase.php +++ b/core/modules/search/src/Plugin/SearchPluginBase.php @@ -114,7 +114,7 @@ abstract class SearchPluginBase extends PluginBase implements ContainerFactoryPl */ public function buildSearchUrlQuery(FormStateInterface $form_state) { // Grab the keywords entered in the form and put them as 'keys' in the GET. - $keys = trim($form_state['values']['keys']); + $keys = trim($form_state->getValue('keys')); $query = array('keys' => $keys); return $query; diff --git a/core/modules/search/src/Plugin/views/filter/Search.php b/core/modules/search/src/Plugin/views/filter/Search.php index e885ce94618..20d60b65dc1 100644 --- a/core/modules/search/src/Plugin/views/filter/Search.php +++ b/core/modules/search/src/Plugin/views/filter/Search.php @@ -105,8 +105,8 @@ class Search extends FilterPluginBase { } $key = $this->options['expose']['identifier']; - if (!empty($form_state['values'][$key])) { - $this->queryParseSearchExpression($form_state['values'][$key]); + if (!$form_state->isValueEmpty($key)) { + $this->queryParseSearchExpression($form_state->getValue($key)); if (count($this->searchQuery->words()) == 0) { form_set_error($key, $form_state, format_plural(\Drupal::config('search.settings')->get('index.minimum_word_size'), 'You must include at least one positive keyword with 1 character or more.', 'You must include at least one positive keyword with @count characters or more.')); } diff --git a/core/modules/search/src/SearchPageListBuilder.php b/core/modules/search/src/SearchPageListBuilder.php index a5c2d188aa9..c5b939ac6bb 100644 --- a/core/modules/search/src/SearchPageListBuilder.php +++ b/core/modules/search/src/SearchPageListBuilder.php @@ -330,16 +330,16 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac $search_settings = $this->configFactory->get('search.settings'); // If these settings change, the index needs to be rebuilt. - if (($search_settings->get('index.minimum_word_size') != $form_state['values']['minimum_word_size']) || ($search_settings->get('index.overlap_cjk') != $form_state['values']['overlap_cjk'])) { - $search_settings->set('index.minimum_word_size', $form_state['values']['minimum_word_size']); - $search_settings->set('index.overlap_cjk', $form_state['values']['overlap_cjk']); + if (($search_settings->get('index.minimum_word_size') != $form_state->getValue('minimum_word_size')) || ($search_settings->get('index.overlap_cjk') != $form_state->getValue('overlap_cjk'))) { + $search_settings->set('index.minimum_word_size', $form_state->getValue('minimum_word_size')); + $search_settings->set('index.overlap_cjk', $form_state->getValue('overlap_cjk')); drupal_set_message($this->t('The index will be rebuilt.')); search_reindex(); } $search_settings - ->set('index.cron_limit', $form_state['values']['cron_limit']) - ->set('logging', $form_state['values']['logging']) + ->set('index.cron_limit', $form_state->getValue('cron_limit')) + ->set('logging', $form_state->getValue('logging')) ->save(); drupal_set_message($this->t('The configuration options have been saved.')); @@ -358,7 +358,7 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac * Form validation handler for adding a new search page. */ public function validateAddSearchPage(array &$form, FormStateInterface $form_state) { - if (empty($form_state['values']['search_type'])) { + if ($form_state->isValueEmpty('search_type')) { $form_state->setErrorByName('search_type', $this->t('You must select the new search page type.')); } } @@ -369,7 +369,7 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac public function submitAddSearchPage(array &$form, FormStateInterface $form_state) { $form_state->setRedirect( 'search.add_type', - array('search_plugin_id' => $form_state['values']['search_type']) + array('search_plugin_id' => $form_state->getValue('search_type')) ); } diff --git a/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php b/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php index 2c3401030c8..b8f7c73e275 100644 --- a/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php +++ b/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php @@ -114,7 +114,7 @@ class SearchExtraTypeSearch extends ConfigurableSearchPluginBase { * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['boost'] = $form_state['values']['extra_type_settings']['boost']; + $this->configuration['boost'] = $form_state->getValue(array('extra_type_settings', 'boost')); } /** diff --git a/core/modules/shortcut/src/Form/SetCustomize.php b/core/modules/shortcut/src/Form/SetCustomize.php index d6afd909caa..d19381d6dc7 100644 --- a/core/modules/shortcut/src/Form/SetCustomize.php +++ b/core/modules/shortcut/src/Form/SetCustomize.php @@ -102,7 +102,8 @@ class SetCustomize extends EntityForm { */ public function save(array $form, FormStateInterface $form_state) { foreach ($this->entity->getShortcuts() as $shortcut) { - $shortcut->setWeight($form_state['values']['shortcuts']['links'][$shortcut->id()]['weight']); + $weight = $form_state->getValue(array('shortcuts', 'links', $shortcut->id(), 'weight')); + $shortcut->setWeight($weight); $shortcut->save(); } drupal_set_message(t('The shortcut set has been updated.')); diff --git a/core/modules/shortcut/src/Form/SwitchShortcutSet.php b/core/modules/shortcut/src/Form/SwitchShortcutSet.php index 2e5c92efac7..c4d065a1668 100644 --- a/core/modules/shortcut/src/Form/SwitchShortcutSet.php +++ b/core/modules/shortcut/src/Form/SwitchShortcutSet.php @@ -171,14 +171,14 @@ class SwitchShortcutSet extends FormBase { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - if ($form_state['values']['set'] == 'new') { + if ($form_state->getValue('set') == 'new') { // Check to prevent creating a shortcut set with an empty title. - if (trim($form_state['values']['label']) == '') { + if (trim($form_state->getValue('label')) == '') { $form_state->setErrorByName('new', $this->t('The new set label is required.')); } // Check to prevent a duplicate title. - if (shortcut_set_title_exists($form_state['values']['label'])) { - $form_state->setErrorByName('label', $this->t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['label']))); + if (shortcut_set_title_exists($form_state->getValue('label'))) { + $form_state->setErrorByName('label', $this->t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state->getValue('label')))); } } } @@ -190,12 +190,12 @@ class SwitchShortcutSet extends FormBase { $account = $this->currentUser(); $account_is_user = $this->user->id() == $account->id(); - if ($form_state['values']['set'] == 'new') { + if ($form_state->getValue('set') == 'new') { // Save a new shortcut set with links copied from the user's default set. /* @var \Drupal\shortcut\Entity\ShortcutSet $set */ $set = $this->shortcutSetStorage->create(array( - 'id' => $form_state['values']['id'], - 'label' => $form_state['values']['label'], + 'id' => $form_state->getValue('id'), + 'label' => $form_state->getValue('label'), )); $set->save(); $replacements = array( @@ -219,7 +219,7 @@ class SwitchShortcutSet extends FormBase { else { // Switch to a different shortcut set. /* @var \Drupal\shortcut\Entity\ShortcutSet $set */ - $set = $this->shortcutSetStorage->load($form_state['values']['set']); + $set = $this->shortcutSetStorage->load($form_state->getValue('set')); $replacements = array( '%user' => $this->user->label(), '%set_name' => $set->label(), diff --git a/core/modules/shortcut/src/ShortcutForm.php b/core/modules/shortcut/src/ShortcutForm.php index 2666046f056..1c70d5258a2 100644 --- a/core/modules/shortcut/src/ShortcutForm.php +++ b/core/modules/shortcut/src/ShortcutForm.php @@ -56,7 +56,7 @@ class ShortcutForm extends ContentEntityForm { // Set the computed 'path' value so it can used in the preSave() method to // derive the route name and parameters. - $entity->path->value = $form_state['values']['path']; + $entity->path->value = $form_state->getValue('path'); return $entity; } @@ -65,7 +65,7 @@ class ShortcutForm extends ContentEntityForm { * {@inheritdoc} */ public function validate(array $form, FormStateInterface $form_state) { - if (!shortcut_valid_link($form_state['values']['path'])) { + if (!shortcut_valid_link($form_state->getValue('path'))) { $form_state->setErrorByName('path', $this->t('The shortcut must correspond to a valid path on the site.')); } diff --git a/core/modules/shortcut/src/ShortcutSetForm.php b/core/modules/shortcut/src/ShortcutSetForm.php index 0d3b7adc927..cb5f43fada7 100644 --- a/core/modules/shortcut/src/ShortcutSetForm.php +++ b/core/modules/shortcut/src/ShortcutSetForm.php @@ -55,8 +55,8 @@ class ShortcutSetForm extends EntityForm { parent::validate($form, $form_state); $entity = $this->entity; // Check to prevent a duplicate title. - if ($form_state['values']['label'] != $entity->label() && shortcut_set_title_exists($form_state['values']['label'])) { - $form_state->setErrorByName('label', $this->t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['label']))); + if ($form_state->getValue('label') != $entity->label() && shortcut_set_title_exists($form_state->getValue('label'))) { + $form_state->setErrorByName('label', $this->t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state->getValue('label')))); } } diff --git a/core/modules/simpletest/src/Form/SimpletestResultsForm.php b/core/modules/simpletest/src/Form/SimpletestResultsForm.php index 7e8269041a5..02e63073261 100644 --- a/core/modules/simpletest/src/Form/SimpletestResultsForm.php +++ b/core/modules/simpletest/src/Form/SimpletestResultsForm.php @@ -252,13 +252,13 @@ class SimpletestResultsForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $pass = $form_state['values']['filter_pass'] ? explode(',', $form_state['values']['filter_pass']) : array(); - $fail = $form_state['values']['filter_fail'] ? explode(',', $form_state['values']['filter_fail']) : array(); + $pass = $form_state->getValue('filter_pass') ? explode(',', $form_state->getValue('filter_pass')) : array(); + $fail = $form_state->getValue('filter_fail') ? explode(',', $form_state->getValue('filter_fail')) : array(); - if ($form_state['values']['filter'] == 'all') { + if ($form_state->getValue('filter') == 'all') { $classes = array_merge($pass, $fail); } - elseif ($form_state['values']['filter'] == 'pass') { + elseif ($form_state->getValue('filter') == 'pass') { $classes = $pass; } else { diff --git a/core/modules/simpletest/src/Form/SimpletestSettingsForm.php b/core/modules/simpletest/src/Form/SimpletestSettingsForm.php index f376f44627c..d4e719773b6 100644 --- a/core/modules/simpletest/src/Form/SimpletestSettingsForm.php +++ b/core/modules/simpletest/src/Form/SimpletestSettingsForm.php @@ -91,13 +91,13 @@ class SimpletestSettingsForm extends ConfigFormBase { $config = $this->config('simpletest.settings'); // If a username was provided but a password wasn't, preserve the existing // password. - if (!empty($form_state['values']['simpletest_httpauth_username']) && empty($form_state['values']['simpletest_httpauth_password'])) { - $form_state['values']['simpletest_httpauth_password'] = $config->get('httpauth.password'); + if (!$form_state->isValueEmpty('simpletest_httpauth_username') && $form_state->isValueEmpty('simpletest_httpauth_password')) { + $form_state->setValue('simpletest_httpauth_password', $config->get('httpauth.password')); } // If a password was provided but a username wasn't, the credentials are // incorrect, so throw an error. - if (empty($form_state['values']['simpletest_httpauth_username']) && !empty($form_state['values']['simpletest_httpauth_password'])) { + if ($form_state->isValueEmpty('simpletest_httpauth_username') && !$form_state->isValueEmpty('simpletest_httpauth_password')) { $form_state->setErrorByName('simpletest_httpauth_username', $this->t('HTTP authentication credentials must include a username in addition to a password.')); } @@ -109,11 +109,11 @@ class SimpletestSettingsForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('simpletest.settings') - ->set('clear_results', $form_state['values']['simpletest_clear_results']) - ->set('verbose', $form_state['values']['simpletest_verbose']) - ->set('httpauth.method', $form_state['values']['simpletest_httpauth_method']) - ->set('httpauth.username', $form_state['values']['simpletest_httpauth_username']) - ->set('httpauth.password', $form_state['values']['simpletest_httpauth_password']) + ->set('clear_results', $form_state->getValue('simpletest_clear_results')) + ->set('verbose', $form_state->getValue('simpletest_verbose')) + ->set('httpauth.method', $form_state->getValue('simpletest_httpauth_method')) + ->set('httpauth.username', $form_state->getValue('simpletest_httpauth_username')) + ->set('httpauth.password', $form_state->getValue('simpletest_httpauth_password')) ->save(); parent::submitForm($form, $form_state); diff --git a/core/modules/simpletest/src/Form/SimpletestTestForm.php b/core/modules/simpletest/src/Form/SimpletestTestForm.php index 6f19a387d3f..e1fe6c2beb8 100644 --- a/core/modules/simpletest/src/Form/SimpletestTestForm.php +++ b/core/modules/simpletest/src/Form/SimpletestTestForm.php @@ -197,12 +197,12 @@ class SimpletestTestForm extends FormBase { // entire form more easily, BUT retaining routing access security and // retaining Form API CSRF #token security validation, and without having // to rely on form caching. - if (empty($form_state['values']['tests']) && !empty($form_state['input']['tests'])) { - $form_state['values']['tests'] = $form_state['input']['tests']; + if ($form_state->isValueEmpty('tests') && !empty($form_state['input']['tests'])) { + $form_state->setValue('tests', $form_state['input']['tests']); } $tests_list = array(); - foreach ($form_state['values']['tests'] as $class_name => $value) { + foreach ($form_state->getValue('tests') as $class_name => $value) { if ($value === $class_name) { if (is_subclass_of($class_name, 'PHPUnit_Framework_TestCase')) { $test_type = 'phpunit'; diff --git a/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php b/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php index 62745b75683..8a664b01f12 100644 --- a/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php +++ b/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php @@ -110,9 +110,9 @@ class StatisticsPopularBlock extends BlockBase { * {@inheritdoc} */ public function blockSubmit($form, FormStateInterface $form_state) { - $this->configuration['top_day_num'] = $form_state['values']['statistics_block_top_day_num']; - $this->configuration['top_all_num'] = $form_state['values']['statistics_block_top_all_num']; - $this->configuration['top_last_num'] = $form_state['values']['statistics_block_top_last_num']; + $this->configuration['top_day_num'] = $form_state->getValue('statistics_block_top_day_num'); + $this->configuration['top_all_num'] = $form_state->getValue('statistics_block_top_all_num'); + $this->configuration['top_last_num'] = $form_state->getValue('statistics_block_top_last_num'); } /** diff --git a/core/modules/statistics/src/StatisticsSettingsForm.php b/core/modules/statistics/src/StatisticsSettingsForm.php index cac15a19135..47411d7b38f 100644 --- a/core/modules/statistics/src/StatisticsSettingsForm.php +++ b/core/modules/statistics/src/StatisticsSettingsForm.php @@ -82,7 +82,7 @@ class StatisticsSettingsForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('statistics.settings') - ->set('count_content_views', $form_state['values']['statistics_count_content_views']) + ->set('count_content_views', $form_state->getValue('statistics_count_content_views')) ->save(); // The popular statistics block is dependent on these settings, so clear the diff --git a/core/modules/syslog/syslog.module b/core/modules/syslog/syslog.module index baee84f0053..85a7311a6a5 100644 --- a/core/modules/syslog/syslog.module +++ b/core/modules/syslog/syslog.module @@ -66,9 +66,9 @@ function syslog_form_system_logging_settings_alter(&$form, FormStateInterface $f */ function syslog_logging_settings_submit($form, FormStateInterface $form_state) { \Drupal::config('syslog.settings') - ->set('identity', $form_state['values']['syslog_identity']) - ->set('facility', $form_state['values']['syslog_facility']) - ->set('format', $form_state['values']['syslog_format']) + ->set('identity', $form_state->getValue('syslog_identity')) + ->set('facility', $form_state->getValue('syslog_facility')) + ->set('format', $form_state->getValue('syslog_format')) ->save(); } diff --git a/core/modules/system/src/Form/CronForm.php b/core/modules/system/src/Form/CronForm.php index 27f9f1daf85..63a17d1014a 100644 --- a/core/modules/system/src/Form/CronForm.php +++ b/core/modules/system/src/Form/CronForm.php @@ -126,7 +126,7 @@ class CronForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('system.cron') - ->set('threshold.autorun', $form_state['values']['cron_safe_threshold']) + ->set('threshold.autorun', $form_state->getValue('cron_safe_threshold')) ->save(); parent::submitForm($form, $form_state); diff --git a/core/modules/system/src/Form/DateFormatFormBase.php b/core/modules/system/src/Form/DateFormatFormBase.php index abbc7459a3f..311f5db7933 100644 --- a/core/modules/system/src/Form/DateFormatFormBase.php +++ b/core/modules/system/src/Form/DateFormatFormBase.php @@ -92,8 +92,8 @@ abstract class DateFormatFormBase extends EntityForm { */ public static function dateTimeLookup(array $form, FormStateInterface $form_state) { $format = ''; - if (!empty($form_state['values']['date_format_pattern'])) { - $format = t('Displayed as %date_format', array('%date_format' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', $form_state['values']['date_format_pattern']))); + if (!$form_state->isValueEmpty('date_format_pattern')) { + $format = t('Displayed as %date_format', array('%date_format' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', $form_state->getValue('date_format_pattern')))); } // Return a command instead of a string, since the Ajax framework // automatically prepends an additional empty DIV element for a string, which @@ -161,7 +161,7 @@ abstract class DateFormatFormBase extends EntityForm { // The machine name field should already check to see if the requested // machine name is available. Regardless of machine_name or human readable // name, check to see if the provided pattern exists. - $pattern = trim($form_state['values']['date_format_pattern']); + $pattern = trim($form_state->getValue('date_format_pattern')); foreach ($this->dateFormatStorage->loadMultiple() as $format) { if ($format->getPattern() == $pattern && ($this->entity->isNew() || $format->id() != $this->entity->id())) { $form_state->setErrorByName('date_format_pattern', $this->t('This format already exists. Enter a unique format string.')); @@ -175,7 +175,7 @@ abstract class DateFormatFormBase extends EntityForm { */ public function submit(array $form, FormStateInterface $form_state) { $form_state->setRedirect('system.date_format_list'); - $form_state['values']['pattern'] = trim($form_state['values']['date_format_pattern']); + $form_state->setValue('pattern', trim($form_state->getValue('date_format_pattern'))); parent::submit($form, $form_state); $this->entity->save(); diff --git a/core/modules/system/src/Form/FileSystemForm.php b/core/modules/system/src/Form/FileSystemForm.php index 44958f20a84..010b9c40a73 100644 --- a/core/modules/system/src/Form/FileSystemForm.php +++ b/core/modules/system/src/Form/FileSystemForm.php @@ -122,12 +122,12 @@ class FileSystemForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->config('system.file') - ->set('path.private', $form_state['values']['file_private_path']) - ->set('path.temporary', $form_state['values']['file_temporary_path']) - ->set('temporary_maximum_age', $form_state['values']['temporary_maximum_age']); + ->set('path.private', $form_state->getValue('file_private_path')) + ->set('path.temporary', $form_state->getValue('file_temporary_path')) + ->set('temporary_maximum_age', $form_state->getValue('temporary_maximum_age')); - if (isset($form_state['values']['file_default_scheme'])) { - $config->set('default_scheme', $form_state['values']['file_default_scheme']); + if ($form_state->hasValue('file_default_scheme')) { + $config->set('default_scheme', $form_state->getValue('file_default_scheme')); } $config->save(); diff --git a/core/modules/system/src/Form/ImageToolkitForm.php b/core/modules/system/src/Form/ImageToolkitForm.php index 15378db645b..69032f69892 100644 --- a/core/modules/system/src/Form/ImageToolkitForm.php +++ b/core/modules/system/src/Form/ImageToolkitForm.php @@ -98,7 +98,7 @@ class ImageToolkitForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('system.image') - ->set('toolkit', $form_state['values']['image_toolkit']) + ->set('toolkit', $form_state->getValue('image_toolkit')) ->save(); // Call the form submit handler for each of the toolkits. diff --git a/core/modules/system/src/Form/LoggingForm.php b/core/modules/system/src/Form/LoggingForm.php index ddb7e3ce35d..500fed033ab 100644 --- a/core/modules/system/src/Form/LoggingForm.php +++ b/core/modules/system/src/Form/LoggingForm.php @@ -48,7 +48,7 @@ class LoggingForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('system.logging') - ->set('error_level', $form_state['values']['error_level']) + ->set('error_level', $form_state->getValue('error_level')) ->save(); parent::submitForm($form, $form_state); diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php index 6edbcb4bfb3..6d9cd8834f3 100644 --- a/core/modules/system/src/Form/ModulesListForm.php +++ b/core/modules/system/src/Form/ModulesListForm.php @@ -416,7 +416,7 @@ class ModulesListForm extends FormBase { * An array of modules to install and their dependencies. */ protected function buildModuleList(FormStateInterface $form_state) { - $packages = $form_state['values']['modules']; + $packages = $form_state->getValue('modules'); // Build a list of modules to install. $modules = array( diff --git a/core/modules/system/src/Form/ModulesUninstallForm.php b/core/modules/system/src/Form/ModulesUninstallForm.php index a8427b5537d..4285956e7b7 100644 --- a/core/modules/system/src/Form/ModulesUninstallForm.php +++ b/core/modules/system/src/Form/ModulesUninstallForm.php @@ -151,7 +151,7 @@ class ModulesUninstallForm extends FormBase { */ public function validateForm(array &$form, FormStateInterface $form_state) { // Form submitted, but no modules selected. - if (!array_filter($form_state['values']['uninstall'])) { + if (!array_filter($form_state->getValue('uninstall'))) { drupal_set_message($this->t('No modules selected.'), 'error'); $form_state->setRedirect('system.modules_uninstall'); } @@ -162,7 +162,7 @@ class ModulesUninstallForm extends FormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { // Save all the values in an expirable key value store. - $modules = $form_state['values']['uninstall']; + $modules = $form_state->getValue('uninstall'); $uninstall = array_keys(array_filter($modules)); $account = $this->currentUser()->id(); $this->keyValueExpirable->setWithExpire($account, $uninstall, 60); diff --git a/core/modules/system/src/Form/PerformanceForm.php b/core/modules/system/src/Form/PerformanceForm.php index b4274e75161..85d24154081 100644 --- a/core/modules/system/src/Form/PerformanceForm.php +++ b/core/modules/system/src/Form/PerformanceForm.php @@ -165,11 +165,11 @@ class PerformanceForm extends ConfigFormBase { $this->renderCache->deleteAll(); $this->config('system.performance') - ->set('cache.page.use_internal', $form_state['values']['cache']) - ->set('cache.page.max_age', $form_state['values']['page_cache_maximum_age']) - ->set('response.gzip', $form_state['values']['page_compression']) - ->set('css.preprocess', $form_state['values']['preprocess_css']) - ->set('js.preprocess', $form_state['values']['preprocess_js']) + ->set('cache.page.use_internal', $form_state->getValue('cache')) + ->set('cache.page.max_age', $form_state->getValue('page_cache_maximum_age')) + ->set('response.gzip', $form_state->getValue('page_compression')) + ->set('css.preprocess', $form_state->getValue('preprocess_css')) + ->set('js.preprocess', $form_state->getValue('preprocess_js')) ->save(); parent::submitForm($form, $form_state); diff --git a/core/modules/system/src/Form/RegionalForm.php b/core/modules/system/src/Form/RegionalForm.php index 7ac2159b4d3..c62e68f3b74 100644 --- a/core/modules/system/src/Form/RegionalForm.php +++ b/core/modules/system/src/Form/RegionalForm.php @@ -144,12 +144,12 @@ class RegionalForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('system.date') - ->set('country.default', $form_state['values']['site_default_country']) - ->set('first_day', $form_state['values']['date_first_day']) - ->set('timezone.default', $form_state['values']['date_default_timezone']) - ->set('timezone.user.configurable', $form_state['values']['configurable_timezones']) - ->set('timezone.user.warn', $form_state['values']['empty_timezone_message']) - ->set('timezone.user.default', $form_state['values']['user_default_timezone']) + ->set('country.default', $form_state->getValue('site_default_country')) + ->set('first_day', $form_state->getValue('date_first_day')) + ->set('timezone.default', $form_state->getValue('date_default_timezone')) + ->set('timezone.user.configurable', $form_state->getValue('configurable_timezones')) + ->set('timezone.user.warn', $form_state->getValue('empty_timezone_message')) + ->set('timezone.user.default', $form_state->getValue('user_default_timezone')) ->save(); parent::submitForm($form, $form_state); diff --git a/core/modules/system/src/Form/RssFeedsForm.php b/core/modules/system/src/Form/RssFeedsForm.php index 5ba8e6d588f..84f18fa7929 100644 --- a/core/modules/system/src/Form/RssFeedsForm.php +++ b/core/modules/system/src/Form/RssFeedsForm.php @@ -61,9 +61,9 @@ class RssFeedsForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('system.rss') - ->set('channel.description', $form_state['values']['feed_description']) - ->set('items.limit', $form_state['values']['feed_default_items']) - ->set('items.view_mode', $form_state['values']['feed_view_mode']) + ->set('channel.description', $form_state->getValue('feed_description')) + ->set('items.limit', $form_state->getValue('feed_default_items')) + ->set('items.view_mode', $form_state->getValue('feed_view_mode')) ->save(); parent::submitForm($form, $form_state); diff --git a/core/modules/system/src/Form/SiteInformationForm.php b/core/modules/system/src/Form/SiteInformationForm.php index 04e22466bac..fea627f8bc9 100644 --- a/core/modules/system/src/Form/SiteInformationForm.php +++ b/core/modules/system/src/Form/SiteInformationForm.php @@ -134,32 +134,32 @@ class SiteInformationForm extends ConfigFormBase { */ public function validateForm(array &$form, FormStateInterface $form_state) { // Check for empty front page path. - if (empty($form_state['values']['site_frontpage'])) { + if ($form_state->isValueEmpty('site_frontpage')) { // Set to default "user". form_set_value($form['front_page']['site_frontpage'], 'user', $form_state); } else { // Get the normal path of the front page. - form_set_value($form['front_page']['site_frontpage'], $this->aliasManager->getPathByAlias($form_state['values']['site_frontpage']), $form_state); + form_set_value($form['front_page']['site_frontpage'], $this->aliasManager->getPathByAlias($form_state->getValue('site_frontpage')), $form_state); } // Validate front page path. - if (!drupal_valid_path($form_state['values']['site_frontpage'])) { - $form_state->setErrorByName('site_frontpage', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_frontpage']))); + if (!drupal_valid_path($form_state->getValue('site_frontpage'))) { + $form_state->setErrorByName('site_frontpage', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_frontpage')))); } // Get the normal paths of both error pages. - if (!empty($form_state['values']['site_403'])) { - form_set_value($form['error_page']['site_403'], $this->aliasManager->getPathByAlias($form_state['values']['site_403']), $form_state); + if (!$form_state->isValueEmpty('site_403')) { + form_set_value($form['error_page']['site_403'], $this->aliasManager->getPathByAlias($form_state->getValue('site_403')), $form_state); } - if (!empty($form_state['values']['site_404'])) { - form_set_value($form['error_page']['site_404'], $this->aliasManager->getPathByAlias($form_state['values']['site_404']), $form_state); + if (!$form_state->isValueEmpty('site_404')) { + form_set_value($form['error_page']['site_404'], $this->aliasManager->getPathByAlias($form_state->getValue('site_404')), $form_state); } // Validate 403 error path. - if (!empty($form_state['values']['site_403']) && !drupal_valid_path($form_state['values']['site_403'])) { - $form_state->setErrorByName('site_403', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_403']))); + if (!$form_state->isValueEmpty('site_403') && !drupal_valid_path($form_state->getValue('site_403'))) { + $form_state->setErrorByName('site_403', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_403')))); } // Validate 404 error path. - if (!empty($form_state['values']['site_404']) && !drupal_valid_path($form_state['values']['site_404'])) { - $form_state->setErrorByName('site_404', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_404']))); + if (!$form_state->isValueEmpty('site_404') && !drupal_valid_path($form_state->getValue('site_404'))) { + $form_state->setErrorByName('site_404', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_404')))); } parent::validateForm($form, $form_state); @@ -170,12 +170,12 @@ class SiteInformationForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('system.site') - ->set('name', $form_state['values']['site_name']) - ->set('mail', $form_state['values']['site_mail']) - ->set('slogan', $form_state['values']['site_slogan']) - ->set('page.front', $form_state['values']['site_frontpage']) - ->set('page.403', $form_state['values']['site_403']) - ->set('page.404', $form_state['values']['site_404']) + ->set('name', $form_state->getValue('site_name')) + ->set('mail', $form_state->getValue('site_mail')) + ->set('slogan', $form_state->getValue('site_slogan')) + ->set('page.front', $form_state->getValue('site_frontpage')) + ->set('page.403', $form_state->getValue('site_403')) + ->set('page.404', $form_state->getValue('site_404')) ->save(); parent::submitForm($form, $form_state); diff --git a/core/modules/system/src/Form/SiteMaintenanceModeForm.php b/core/modules/system/src/Form/SiteMaintenanceModeForm.php index 1ee0aa69a7f..1e400b3e2e8 100644 --- a/core/modules/system/src/Form/SiteMaintenanceModeForm.php +++ b/core/modules/system/src/Form/SiteMaintenanceModeForm.php @@ -79,10 +79,10 @@ class SiteMaintenanceModeForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('system.maintenance') - ->set('message', $form_state['values']['maintenance_mode_message']) + ->set('message', $form_state->getValue('maintenance_mode_message')) ->save(); - $this->state->set('system.maintenance_mode', $form_state['values']['maintenance_mode']); + $this->state->set('system.maintenance_mode', $form_state->getValue('maintenance_mode')); parent::submitForm($form, $form_state); } diff --git a/core/modules/system/src/Form/ThemeAdminForm.php b/core/modules/system/src/Form/ThemeAdminForm.php index 627c2b33c5b..2cee8c582ed 100644 --- a/core/modules/system/src/Form/ThemeAdminForm.php +++ b/core/modules/system/src/Form/ThemeAdminForm.php @@ -51,7 +51,7 @@ class ThemeAdminForm extends FormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { drupal_set_message($this->t('The configuration options have been saved.')); - $this->config('system.theme')->set('admin', $form_state['values']['admin_theme'])->save(); + $this->config('system.theme')->set('admin', $form_state->getValue('admin_theme'))->save(); } } diff --git a/core/modules/system/src/Form/ThemeSettingsForm.php b/core/modules/system/src/Form/ThemeSettingsForm.php index 20effcfdd51..235134aa0a4 100644 --- a/core/modules/system/src/Form/ThemeSettingsForm.php +++ b/core/modules/system/src/Form/ThemeSettingsForm.php @@ -330,7 +330,7 @@ class ThemeSettingsForm extends ConfigFormBase { // File upload was attempted. if ($file) { // Put the temporary file in form_values so we can save it on submit. - $form_state['values']['logo_upload'] = $file; + $form_state->setValue('logo_upload', $file); } else { // File upload failed. @@ -346,7 +346,7 @@ class ThemeSettingsForm extends ConfigFormBase { // File upload was attempted. if ($file) { // Put the temporary file in form_values so we can save it on submit. - $form_state['values']['favicon_upload'] = $file; + $form_state->setValue('favicon_upload', $file); } else { // File upload failed. @@ -356,14 +356,14 @@ class ThemeSettingsForm extends ConfigFormBase { // If the user provided a path for a logo or favicon file, make sure a file // exists at that path. - if ($form_state['values']['logo_path']) { - $path = $this->validatePath($form_state['values']['logo_path']); + if ($form_state->getValue('logo_path')) { + $path = $this->validatePath($form_state->getValue('logo_path')); if (!$path) { $form_state->setErrorByName('logo_path', $this->t('The custom logo path is invalid.')); } } - if ($form_state['values']['favicon_path']) { - $path = $this->validatePath($form_state['values']['favicon_path']); + if ($form_state->getValue('favicon_path')) { + $path = $this->validatePath($form_state->getValue('favicon_path')); if (!$path) { $form_state->setErrorByName('favicon_path', $this->t('The custom favicon path is invalid.')); } @@ -377,14 +377,14 @@ class ThemeSettingsForm extends ConfigFormBase { public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); - $config = $this->config($form_state['values']['config_key']); + $config = $this->config($form_state->getValue('config_key')); // Exclude unnecessary elements before saving. form_state_values_clean($form_state); - unset($form_state['values']['var']); - unset($form_state['values']['config_key']); + $form_state->unsetValue('var'); + $form_state->unsetValue('config_key'); - $values = $form_state['values']; + $values = $form_state->getValues(); // If the user uploaded a new logo or favicon, save it to a permanent location // and use it in place of the default theme-provided file. diff --git a/core/modules/system/src/Plugin/Block/SystemBrandingBlock.php b/core/modules/system/src/Plugin/Block/SystemBrandingBlock.php index 0cecf2b84c0..d7289692cce 100644 --- a/core/modules/system/src/Plugin/Block/SystemBrandingBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemBrandingBlock.php @@ -175,9 +175,10 @@ class SystemBrandingBlock extends BlockBase implements ContainerFactoryPluginInt * {@inheritdoc} */ public function blockSubmit($form, FormStateInterface $form_state) { - $this->configuration['use_site_logo'] = $form_state['values']['block_branding']['use_site_logo']; - $this->configuration['use_site_name'] = $form_state['values']['block_branding']['use_site_name']; - $this->configuration['use_site_slogan'] = $form_state['values']['block_branding']['use_site_slogan']; + $block_branding = $form_state->getValue('block_branding'); + $this->configuration['use_site_logo'] = $block_branding['use_site_logo']; + $this->configuration['use_site_name'] = $block_branding['use_site_name']; + $this->configuration['use_site_slogan'] = $block_branding['use_site_slogan']; } /** diff --git a/core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php b/core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php index 1ccd1f9c0de..89991ef34c0 100644 --- a/core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php +++ b/core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php @@ -109,7 +109,7 @@ class CurrentThemeCondition extends ConditionPluginBase implements ContainerFact * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['theme'] = $form_state['values']['theme']; + $this->configuration['theme'] = $form_state->getValue('theme'); parent::submitConfigurationForm($form, $form_state); } diff --git a/core/modules/system/src/Plugin/Condition/RequestPath.php b/core/modules/system/src/Plugin/Condition/RequestPath.php index c6314d573b7..a5f56139d1b 100644 --- a/core/modules/system/src/Plugin/Condition/RequestPath.php +++ b/core/modules/system/src/Plugin/Condition/RequestPath.php @@ -112,7 +112,7 @@ class RequestPath extends ConditionPluginBase implements ContainerFactoryPluginI * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['pages'] = $form_state['values']['pages']; + $this->configuration['pages'] = $form_state->getValue('pages'); parent::submitConfigurationForm($form, $form_state); } diff --git a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php index 3cbdbd9e8ac..1fd0c77e9da 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php @@ -79,7 +79,7 @@ class GDToolkit extends ImageToolkitBase { */ public function settingsFormSubmit($form, FormStateInterface $form_state) { \Drupal::config('system.image.gd') - ->set('jpeg_quality', $form_state['values']['gd']['image_jpeg_quality']) + ->set('jpeg_quality', $form_state->getValue(array('gd', 'image_jpeg_quality'))) ->save(); } diff --git a/core/modules/system/src/Plugin/views/field/BulkForm.php b/core/modules/system/src/Plugin/views/field/BulkForm.php index c910ba1c5c1..130dc33485e 100644 --- a/core/modules/system/src/Plugin/views/field/BulkForm.php +++ b/core/modules/system/src/Plugin/views/field/BulkForm.php @@ -126,7 +126,8 @@ class BulkForm extends FieldPluginBase { public function validateOptionsForm(&$form, FormStateInterface $form_state) { parent::validateOptionsForm($form, $form_state); - $form_state['values']['options']['selected_actions'] = array_filter($form_state['values']['options']['selected_actions']); + $selected_actions = $form_state->getValue(array('options', 'selected_actions')); + $form_state->getValue(array('options', 'selected_actions'), array_filter($selected_actions)); } /** @@ -176,7 +177,7 @@ class BulkForm extends FieldPluginBase { // only output a generic label. '#title' => t('Update this item'), '#title_display' => 'invisible', - '#default_value' => !empty($form_state['values'][$this->options['id']][$row_index]) ? 1 : NULL, + '#default_value' => !empty($form_state->getValue($this->options['id'])[$row_index]) ? 1 : NULL, ); } @@ -252,14 +253,14 @@ class BulkForm extends FieldPluginBase { public function viewsFormSubmit(&$form, FormStateInterface $form_state) { if ($form_state['step'] == 'views_form_views_form') { // Filter only selected checkboxes. - $selected = array_filter($form_state['values'][$this->options['id']]); + $selected = array_filter($form_state->getValue($this->options['id'])); $entities = array(); foreach (array_intersect_key($this->view->result, $selected) as $row) { $entity = $this->getEntity($row); $entities[$entity->id()] = $entity; } - $action = $this->actions[$form_state['values']['action']]; + $action = $this->actions[$form_state->getValue('action')]; $action->execute($entities); $operation_definition = $action->getPluginDefinition(); @@ -267,7 +268,7 @@ class BulkForm extends FieldPluginBase { $form_state->setRedirect($operation_definition['confirm_form_route_name']); } - $count = count(array_filter($form_state['values'][$this->options['id']])); + $count = count(array_filter($form_state->getValue($this->options['id']))); if ($count) { drupal_set_message($this->formatPlural($count, '%action was applied to @count item.', '%action was applied to @count items.', array( '%action' => $action->label(), @@ -291,7 +292,7 @@ class BulkForm extends FieldPluginBase { * {@inheritdoc} */ public function viewsFormValidate(&$form, FormStateInterface $form_state) { - $selected = array_filter($form_state['values'][$this->options['id']]); + $selected = array_filter($form_state->getValue($this->options['id'])); if (empty($selected)) { form_set_error('', $form_state, $this->emptySelectedMessage()); } diff --git a/core/modules/system/src/Tests/Form/CheckboxTest.php b/core/modules/system/src/Tests/Form/CheckboxTest.php index b913f5ead23..b667295ad40 100644 --- a/core/modules/system/src/Tests/Form/CheckboxTest.php +++ b/core/modules/system/src/Tests/Form/CheckboxTest.php @@ -58,7 +58,7 @@ class CheckboxTest extends WebTestBase { } } - // Ensure that $form_state['values'] is populated correctly for a checkboxes + // Ensure that $form_state->getValues() is populated correctly for a checkboxes // group that includes a 0-indexed array of options. $results = json_decode($this->drupalPostForm('form-test/checkboxes-zero', array(), 'Save')); $this->assertIdentical($results->checkbox_off, array(0, 0, 0), 'All three in checkbox_off are zeroes: off.'); diff --git a/core/modules/system/src/Tests/Form/FormTest.php b/core/modules/system/src/Tests/Form/FormTest.php index 9a9874601e2..80d064f9869 100644 --- a/core/modules/system/src/Tests/Form/FormTest.php +++ b/core/modules/system/src/Tests/Form/FormTest.php @@ -503,7 +503,7 @@ class FormTest extends WebTestBase { } // Submit the form with no input, as the browser does for disabled elements, - // and fetch the $form_state['values'] that is passed to the submit handler. + // and fetch the $form_state->getValues() that is passed to the submit handler. $this->drupalPostForm('form-test/disabled-elements', array(), t('Submit')); $returned_values['normal'] = Json::decode($this->content); diff --git a/core/modules/system/src/Tests/Form/ProgrammaticTest.php b/core/modules/system/src/Tests/Form/ProgrammaticTest.php index 2eba5ead24d..16c11b36ae0 100644 --- a/core/modules/system/src/Tests/Form/ProgrammaticTest.php +++ b/core/modules/system/src/Tests/Form/ProgrammaticTest.php @@ -99,11 +99,10 @@ class ProgrammaticTest extends WebTestBase { * Test the programmed_bypass_access_check flag. */ public function testProgrammaticAccessBypass() { - $form_state = new FormState(); - $form_state['values'] = array( + $form_state = new FormState(array('values' => array( '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 diff --git a/core/modules/system/src/Tests/Form/TriggeringElementProgrammedUnitTest.php b/core/modules/system/src/Tests/Form/TriggeringElementProgrammedUnitTest.php index e4a50c40222..e5bee9b2ab2 100644 --- a/core/modules/system/src/Tests/Form/TriggeringElementProgrammedUnitTest.php +++ b/core/modules/system/src/Tests/Form/TriggeringElementProgrammedUnitTest.php @@ -76,8 +76,7 @@ class TriggeringElementProgrammedUnitTest extends DrupalUnitTestBase implements function testLimitValidationErrors() { // Programmatically submit the form. $form_state = new FormState(); - $form_state['values'] = array(); - $form_state['values']['section'] = 'one'; + $form_state->setValue('section', 'one'); $form_builder = $this->container->get('form_builder'); $form_builder->submitForm($this, $form_state); @@ -87,8 +86,8 @@ class TriggeringElementProgrammedUnitTest extends DrupalUnitTestBase implements $this->assertFalse(isset($errors['two']), "Section 'two' was not validated."); // Verify that there are only values for the specified section. - $this->assertTrue(isset($form_state['values']['one']), "Values for section 'one' found."); - $this->assertFalse(isset($form_state['values']['two']), "Values for section 'two' not found."); + $this->assertTrue($form_state->hasValue('one'), "Values for section 'one' found."); + $this->assertFalse($form_state->hasValue('two'), "Values for section 'two' not found."); } } diff --git a/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module b/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module index bc97fe6942c..20402befa76 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module +++ b/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module @@ -191,7 +191,7 @@ function ajax_forms_test_advanced_commands_settings_with_merging_callback($form, */ function ajax_forms_test_validation_form_callback($form, FormStateInterface $form_state) { drupal_set_message("ajax_forms_test_validation_form_callback invoked"); - drupal_set_message(t("Callback: drivertext=%drivertext, spare_required_field=%spare_required_field", array('%drivertext' => $form_state['values']['drivertext'], '%spare_required_field' => $form_state['values']['spare_required_field']))); + drupal_set_message(t("Callback: drivertext=%drivertext, spare_required_field=%spare_required_field", array('%drivertext' => $form_state->getValue('drivertext'), '%spare_required_field' => $form_state->getValue('spare_required_field')))); return '<div id="message_area">ajax_forms_test_validation_form_callback at ' . date('c') . '</div>'; } @@ -200,7 +200,7 @@ function ajax_forms_test_validation_form_callback($form, FormStateInterface $for */ function ajax_forms_test_validation_number_form_callback($form, FormStateInterface $form_state) { drupal_set_message("ajax_forms_test_validation_number_form_callback invoked"); - drupal_set_message(t("Callback: drivernumber=%drivernumber, spare_required_field=%spare_required_field", array('%drivernumber' => $form_state['values']['drivernumber'], '%spare_required_field' => $form_state['values']['spare_required_field']))); + drupal_set_message(t("Callback: drivernumber=%drivernumber, spare_required_field=%spare_required_field", array('%drivernumber' => $form_state->getValue('drivernumber'), '%spare_required_field' => $form_state->getValue('spare_required_field')))); return '<div id="message_area_number">ajax_forms_test_validation_number_form_callback at ' . date('c') . '</div>'; } diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php b/core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php index e9830973385..d66373477fa 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php +++ b/core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php @@ -22,8 +22,8 @@ class Callbacks { */ function selectCallback($form, FormStateInterface $form_state) { $response = new AjaxResponse(); - $response->addCommand(new HtmlCommand('#ajax_selected_color', $form_state['values']['select'])); - $response->addCommand(new DataCommand('#ajax_selected_color', 'form_state_value_select', $form_state['values']['select'])); + $response->addCommand(new HtmlCommand('#ajax_selected_color', $form_state->getValue('select'))); + $response->addCommand(new DataCommand('#ajax_selected_color', 'form_state_value_select', $form_state->getValue('select'))); return $response; } @@ -32,8 +32,8 @@ class Callbacks { */ function checkboxCallback($form, FormStateInterface $form_state) { $response = new AjaxResponse(); - $response->addCommand(new HtmlCommand('#ajax_checkbox_value', (int) $form_state['values']['checkbox'])); - $response->addCommand(new DataCommand('#ajax_checkbox_value', 'form_state_value_select', (int) $form_state['values']['checkbox'])); + $response->addCommand(new HtmlCommand('#ajax_checkbox_value', (int) $form_state->getValue('checkbox'))); + $response->addCommand(new DataCommand('#ajax_checkbox_value', 'form_state_value_select', (int) $form_state->getValue('checkbox'))); return $response; } } diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestLazyLoadForm.php b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestLazyLoadForm.php index 762c30606cd..a54fcd7f1ed 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestLazyLoadForm.php +++ b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestLazyLoadForm.php @@ -56,7 +56,7 @@ class AjaxFormsTestLazyLoadForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - if ($form_state['values']['add_files']) { + if ($form_state->getValue('add_files')) { $path = drupal_get_path('module', 'system'); $attached = array( '#attached' => array( diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestValidationForm.php b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestValidationForm.php index bf7064e7821..4646956705e 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestValidationForm.php +++ b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestValidationForm.php @@ -30,7 +30,7 @@ class AjaxFormsTestValidationForm extends FormBase { '#title' => $this->t('AJAX-enabled textfield.'), '#description' => $this->t("When this one AJAX-triggers and the spare required field is empty, you should not get an error."), '#type' => 'textfield', - '#default_value' => !empty($form_state['values']['drivertext']) ? $form_state['values']['drivertext'] : "", + '#default_value' => $form_state->getValue('drivertext', ''), '#ajax' => array( 'callback' => 'ajax_forms_test_validation_form_callback', 'wrapper' => 'message_area', @@ -43,7 +43,7 @@ class AjaxFormsTestValidationForm extends FormBase { '#title' => $this->t('AJAX-enabled number field.'), '#description' => $this->t("When this one AJAX-triggers and the spare required field is empty, you should not get an error."), '#type' => 'number', - '#default_value' => !empty($form_state['values']['drivernumber']) ? $form_state['values']['drivernumber'] : "", + '#default_value' => $form_state->getValue('drivernumber', ''), '#ajax' => array( 'callback' => 'ajax_forms_test_validation_number_form_callback', 'wrapper' => 'message_area_number', diff --git a/core/modules/system/tests/modules/batch_test/src/Form/BatchTestChainedForm.php b/core/modules/system/tests/modules/batch_test/src/Form/BatchTestChainedForm.php index b2491271387..a2251a78b6b 100644 --- a/core/modules/system/tests/modules/batch_test/src/Form/BatchTestChainedForm.php +++ b/core/modules/system/tests/modules/batch_test/src/Form/BatchTestChainedForm.php @@ -59,9 +59,10 @@ class BatchTestChainedForm extends FormBase { batch_test_stack(NULL, TRUE); batch_test_stack('submit handler 1'); - batch_test_stack('value = ' . $form_state['values']['value']); + batch_test_stack('value = ' . $form_state->getValue('value')); - $form_state['values']['value']++; + $value = &$form_state->getValue('value'); + $value++; batch_set(_batch_test_batch_1()); $form_state->setRedirect('batch_test.redirect'); @@ -72,9 +73,10 @@ class BatchTestChainedForm extends FormBase { */ public static function batchTestChainedFormSubmit2($form, FormStateInterface $form_state) { batch_test_stack('submit handler 2'); - batch_test_stack('value = ' . $form_state['values']['value']); + batch_test_stack('value = ' . $form_state->getValue('value')); - $form_state['values']['value']++; + $value = &$form_state->getValue('value'); + $value++; batch_set(_batch_test_batch_2()); $form_state->setRedirect('batch_test.redirect'); @@ -85,9 +87,10 @@ class BatchTestChainedForm extends FormBase { */ public static function batchTestChainedFormSubmit3($form, FormStateInterface $form_state) { batch_test_stack('submit handler 3'); - batch_test_stack('value = ' . $form_state['values']['value']); + batch_test_stack('value = ' . $form_state->getValue('value')); - $form_state['values']['value']++; + $value = &$form_state->getValue('value'); + $value++; $form_state->setRedirect('batch_test.redirect'); } @@ -97,9 +100,10 @@ class BatchTestChainedForm extends FormBase { */ public static function batchTestChainedFormSubmit4($form, FormStateInterface $form_state) { batch_test_stack('submit handler 4'); - batch_test_stack('value = ' . $form_state['values']['value']); + batch_test_stack('value = ' . $form_state->getValue('value')); - $form_state['values']['value']++; + $value = &$form_state->getValue('value'); + $value++; batch_set(_batch_test_batch_3()); $form_state->setRedirect('batch_test.redirect'); diff --git a/core/modules/system/tests/modules/batch_test/src/Form/BatchTestMockForm.php b/core/modules/system/tests/modules/batch_test/src/Form/BatchTestMockForm.php index f72fc29e500..06eff66d2a2 100644 --- a/core/modules/system/tests/modules/batch_test/src/Form/BatchTestMockForm.php +++ b/core/modules/system/tests/modules/batch_test/src/Form/BatchTestMockForm.php @@ -42,7 +42,7 @@ class BatchTestMockForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - batch_test_stack('mock form submitted with value = ' . $form_state['values']['test_value']); + batch_test_stack('mock form submitted with value = ' . $form_state->getValue('test_value')); } } diff --git a/core/modules/system/tests/modules/batch_test/src/Form/BatchTestSimpleForm.php b/core/modules/system/tests/modules/batch_test/src/Form/BatchTestSimpleForm.php index f43c873f666..aa37fbba99d 100644 --- a/core/modules/system/tests/modules/batch_test/src/Form/BatchTestSimpleForm.php +++ b/core/modules/system/tests/modules/batch_test/src/Form/BatchTestSimpleForm.php @@ -51,7 +51,7 @@ class BatchTestSimpleForm extends FormBase { public function submitForm(array &$form, FormStateInterface $form_state) { batch_test_stack(NULL, TRUE); - $function = '_batch_test_' . $form_state['values']['batch']; + $function = '_batch_test_' . $form_state->getValue('batch'); batch_set($function()); $form_state->setRedirect('batch_test.redirect'); diff --git a/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php b/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php index 0b5db442a1c..9b0aaa30efd 100644 --- a/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php +++ b/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php @@ -69,7 +69,7 @@ class EntityTestForm extends ContentEntityForm { $entity = parent::submit($form, $form_state); // Save as a new revision if requested to do so. - if (!empty($form_state['values']['revision'])) { + if (!$form_state->isValueEmpty('revision')) { $entity->setNewRevision(); } 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 73fd437f09a..bababe62595 100644 --- a/core/modules/system/tests/modules/form_test/src/Callbacks.php +++ b/core/modules/system/tests/modules/form_test/src/Callbacks.php @@ -19,7 +19,7 @@ class Callbacks { */ public function validateName(&$element, FormStateInterface $form_state) { $triggered = FALSE; - if ($form_state['values']['name'] == 'element_validate') { + if ($form_state->getValue('name') == 'element_validate') { // Alter the form element. $element['#value'] = '#value changed by #element_validate'; // Alter the submitted value in $form_state. @@ -27,8 +27,8 @@ class Callbacks { $triggered = TRUE; } - if ($form_state['values']['name'] == 'element_validate_access') { - $form_state['storage']['form_test_name'] = $form_state['values']['name']; + if ($form_state->getValue('name') == 'element_validate_access') { + $form_state['storage']['form_test_name'] = $form_state->getValue('name'); // Alter the form element. $element['#access'] = FALSE; @@ -43,7 +43,7 @@ class Callbacks { if ($triggered) { // Output the element's value from $form_state. - drupal_set_message(t('@label value: @value', array('@label' => $element['#title'], '@value' => $form_state['values']['name']))); + drupal_set_message(t('@label value: @value', array('@label' => $element['#title'], '@value' => $form_state->getValue('name')))); // Trigger a form validation error to see our changes. form_set_error('', $form_state); diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxForm.php index 63f8ebbe42e..51a42ee06ea 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxForm.php @@ -92,7 +92,7 @@ class FormTestCheckboxForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $form_state->setResponse(new JsonResponse($form_state['values'])); + $form_state->setResponse(new JsonResponse($form_state->getValues())); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxesRadiosForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxesRadiosForm.php index 1077c425e7c..7bd43747a21 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxesRadiosForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxesRadiosForm.php @@ -84,7 +84,7 @@ class FormTestCheckboxesRadiosForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $form_state->setResponse(new JsonResponse($form_state['values'])); + $form_state->setResponse(new JsonResponse($form_state->getValues())); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxesZeroForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxesZeroForm.php index 557fd647fb2..a302fb0141c 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxesZeroForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestCheckboxesZeroForm.php @@ -57,7 +57,7 @@ class FormTestCheckboxesZeroForm extends FormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { if (!empty($form_state['json'])) { - $form_state->setResponse(new JsonResponse($form_state['values'])); + $form_state->setResponse(new JsonResponse($form_state->getValues())); } else { $form_state['no_redirect'] = TRUE; diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestColorForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestColorForm.php index 9d37c5af47b..93280745e4b 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestColorForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestColorForm.php @@ -42,7 +42,7 @@ class FormTestColorForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $form_state->setResponse(new JsonResponse($form_state['values'])); + $form_state->setResponse(new JsonResponse($form_state->getValues())); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestDisabledElementsForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestDisabledElementsForm.php index 09a2ed9b875..485d081472e 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestDisabledElementsForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestDisabledElementsForm.php @@ -229,7 +229,7 @@ class FormTestDisabledElementsForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $form_state->setResponse(new JsonResponse($form_state['values'])); + $form_state->setResponse(new JsonResponse($form_state->getValues())); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestEmailForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestEmailForm.php index f5ceece94d3..09c33b71938 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestEmailForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestEmailForm.php @@ -49,7 +49,7 @@ class FormTestEmailForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $form_state->setResponse(new JsonResponse($form_state['values'])); + $form_state->setResponse(new JsonResponse($form_state->getValues())); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestFormStateValuesCleanForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestFormStateValuesCleanForm.php index c8b39e3985c..f23177ae35f 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestFormStateValuesCleanForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestFormStateValuesCleanForm.php @@ -46,7 +46,7 @@ class FormTestFormStateValuesCleanForm extends FormBase { form_state_values_clean($form_state); // This won't have a proper JSON header, but Drupal doesn't check for that // anyway so this is fine until it's replaced with a JsonResponse. - print Json::encode($form_state['values']); + print Json::encode($form_state->getValues()); exit; } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestInputForgeryForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestInputForgeryForm.php index e3a31e9777d..96829b2c65a 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestInputForgeryForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestInputForgeryForm.php @@ -46,7 +46,7 @@ class FormTestInputForgeryForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - return new JsonResponse($form_state['values']); + return new JsonResponse($form_state->getValues()); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestLanguageSelectForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestLanguageSelectForm.php index e0f9900c658..e0198f0269d 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestLanguageSelectForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestLanguageSelectForm.php @@ -67,7 +67,7 @@ class FormTestLanguageSelectForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $form_state->setResponse(new JsonResponse($form_state['values'])); + $form_state->setResponse(new JsonResponse($form_state->getValues())); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestLimitValidationErrorsForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestLimitValidationErrorsForm.php index b8f4c524c23..8f260be9e70 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestLimitValidationErrorsForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestLimitValidationErrorsForm.php @@ -106,7 +106,7 @@ class FormTestLimitValidationErrorsForm extends FormBase { public function partialSubmitForm(array &$form, FormStateInterface $form_state) { // The title has not been validated, thus its value - in case of the test case // an empty string - may not be set. - if (!isset($form_state['values']['title']) && isset($form_state['values']['test'])) { + if (!$form_state->hasValue('title') && $form_state->hasValue('test')) { drupal_set_message('Only validated values appear in the form values.'); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestProgrammaticForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestProgrammaticForm.php index 68b4368feba..d782ef5121e 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestProgrammaticForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestProgrammaticForm.php @@ -89,7 +89,7 @@ class FormTestProgrammaticForm extends FormBase { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - if (empty($form_state['values']['textfield'])) { + if ($form_state->isValueEmpty('textfield')) { form_set_error('textfield', $form_state, t('Textfield is required.')); } } @@ -98,7 +98,7 @@ class FormTestProgrammaticForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $form_state['storage']['programmatic_form_submit'] = $form_state['values']; + $form_state['storage']['programmatic_form_submit'] = $form_state->getValues(); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestRangeForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestRangeForm.php index b7119df2c57..fbe2d27190c 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestRangeForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestRangeForm.php @@ -70,7 +70,7 @@ class FormTestRangeForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $form_state->setResponse(new JsonResponse($form_state['values'])); + $form_state->setResponse(new JsonResponse($form_state->getValues())); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestRebuildPreserveValuesForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestRebuildPreserveValuesForm.php index 2e6ed8bd245..47f1f392adf 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestRebuildPreserveValuesForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestRebuildPreserveValuesForm.php @@ -97,7 +97,7 @@ class FormTestRebuildPreserveValuesForm extends FormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { // Finish the workflow. Do not rebuild. - drupal_set_message(t('Form values: %values', array('%values' => var_export($form_state['values'], TRUE)))); + drupal_set_message(t('Form values: %values', array('%values' => var_export($form_state->getValues(), TRUE)))); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestRedirectForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestRedirectForm.php index 1c6437d5d0d..c00dc1b56e3 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestRedirectForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestRedirectForm.php @@ -52,9 +52,9 @@ class FormTestRedirectForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - if (!empty($form_state['values']['redirection'])) { - if (!empty($form_state['values']['destination'])) { - $form_state->setRedirectUrl(Url::createFromPath($GLOBALS['base_url'] . '/' . $form_state['values']['destination'])); + if (!$form_state->isValueEmpty('redirection')) { + if (!$form_state->isValueEmpty('destination')) { + $form_state->setRedirectUrl(Url::createFromPath($GLOBALS['base_url'] . '/' . $form_state->getValue('destination'))); } } else { diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestSelectForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestSelectForm.php index c7a38f99503..dab04346f39 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestSelectForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestSelectForm.php @@ -128,7 +128,7 @@ class FormTestSelectForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $form_state->setResponse(new JsonResponse($form_state['values'])); + $form_state->setResponse(new JsonResponse($form_state->getValues())); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestStorageForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestStorageForm.php index b6499507bac..59ae6edcb6e 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestStorageForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestStorageForm.php @@ -98,7 +98,7 @@ class FormTestStorageForm extends FormBase { // This presumes that another submitted form value triggers a validation error // elsewhere in the form. Form API should still update the cached form storage // though. - if (\Drupal::request()->get('cache') && $form_state['values']['value'] == 'change_title') { + if (\Drupal::request()->get('cache') && $form_state->getValue('value') == 'change_title') { $form_state['storage']['thing']['changed'] = TRUE; } } @@ -107,8 +107,8 @@ class FormTestStorageForm extends FormBase { * {@inheritdoc} */ public function continueSubmitForm(array &$form, FormStateInterface $form_state) { - $form_state['storage']['thing']['title'] = $form_state['values']['title']; - $form_state['storage']['thing']['value'] = $form_state['values']['value']; + $form_state['storage']['thing']['title'] = $form_state->getValue('title'); + $form_state['storage']['thing']['value'] = $form_state->getValue('value'); $form_state['rebuild'] = TRUE; } @@ -116,7 +116,7 @@ class FormTestStorageForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - drupal_set_message("Title: " . String::checkPlain($form_state['values']['title'])); + drupal_set_message("Title: " . String::checkPlain($form_state->getValue('title'))); drupal_set_message("Form constructions: " . $_SESSION['constructions']); if (isset($form_state['storage']['thing']['changed'])) { drupal_set_message("The thing has been changed."); diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectMultipleFalseForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectMultipleFalseForm.php index 5f0b457b3d9..1f1f5d17608 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectMultipleFalseForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectMultipleFalseForm.php @@ -29,7 +29,7 @@ class FormTestTableSelectMultipleFalseForm extends FormTestTableSelectFormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - drupal_set_message(t('Submitted: @value', array('@value' => $form_state['values']['tableselect']))); + drupal_set_message(t('Submitted: @value', array('@value' => $form_state->getValue('tableselect')))); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectMultipleTrueForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectMultipleTrueForm.php index 4d9a0e6d9ec..8c2a6f5af96 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectMultipleTrueForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectMultipleTrueForm.php @@ -29,7 +29,7 @@ class FormTestTableSelectMultipleTrueForm extends FormTestTableSelectFormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $selected = $form_state['values']['tableselect']; + $selected = $form_state->getValue('tableselect'); foreach ($selected as $key => $value) { drupal_set_message(t('Submitted: @key = @value', array('@key' => $key, '@value' => $value))); } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestUrlForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestUrlForm.php index fe95e91bdc5..3fc34be819e 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestUrlForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestUrlForm.php @@ -49,7 +49,7 @@ class FormTestUrlForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $form_state->setResponse(new JsonResponse($form_state['values'])); + $form_state->setResponse(new JsonResponse($form_state->getValues())); } } 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 6467520f815..27f31edebe3 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 @@ -17,7 +17,7 @@ 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['values'] without affecting the form element. + * $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 @@ -60,13 +60,13 @@ class FormTestValidateForm extends FormBase { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - if ($form_state['values']['name'] == 'validate') { + if ($form_state->getValue('name') == 'validate') { // 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); // Output the element's value from $form_state. - drupal_set_message(t('@label value: @value', array('@label' => $form['name']['#title'], '@value' => $form_state['values']['name']))); + drupal_set_message(t('@label value: @value', array('@label' => $form['name']['#title'], '@value' => $form_state->getValue('name')))); // Trigger a form validation error to see our changes. form_set_error('', $form_state); diff --git a/core/modules/system/tests/modules/form_test/src/FormTestArgumentsObject.php b/core/modules/system/tests/modules/form_test/src/FormTestArgumentsObject.php index dd5843599a2..da7b4d58330 100644 --- a/core/modules/system/tests/modules/form_test/src/FormTestArgumentsObject.php +++ b/core/modules/system/tests/modules/form_test/src/FormTestArgumentsObject.php @@ -56,7 +56,7 @@ class FormTestArgumentsObject extends FormBase { public function submitForm(array &$form, FormStateInterface $form_state) { drupal_set_message($this->t('The FormTestArgumentsObject::submitForm() method was used for this form.')); $this->config('form_test.object') - ->set('bananas', $form_state['values']['bananas']) + ->set('bananas', $form_state->getValue('bananas')) ->save(); } diff --git a/core/modules/system/tests/modules/form_test/src/FormTestControllerObject.php b/core/modules/system/tests/modules/form_test/src/FormTestControllerObject.php index 4ccc8ad4a68..a3e50643428 100644 --- a/core/modules/system/tests/modules/form_test/src/FormTestControllerObject.php +++ b/core/modules/system/tests/modules/form_test/src/FormTestControllerObject.php @@ -66,7 +66,7 @@ class FormTestControllerObject extends FormBase { public function submitForm(array &$form, FormStateInterface $form_state) { drupal_set_message($this->t('The FormTestControllerObject::submitForm() method was used for this form.')); $this->config('form_test.object') - ->set('bananas', $form_state['values']['bananas']) + ->set('bananas', $form_state->getValue('bananas')) ->save(); } diff --git a/core/modules/system/tests/modules/form_test/src/FormTestObject.php b/core/modules/system/tests/modules/form_test/src/FormTestObject.php index a6c6da356f6..4669bfec651 100644 --- a/core/modules/system/tests/modules/form_test/src/FormTestObject.php +++ b/core/modules/system/tests/modules/form_test/src/FormTestObject.php @@ -57,7 +57,7 @@ class FormTestObject extends FormBase { public function submitForm(array &$form, FormStateInterface $form_state) { drupal_set_message($this->t('The FormTestObject::submitForm() method was used for this form.')); $this->config('form_test.object') - ->set('bananas', $form_state['values']['bananas']) + ->set('bananas', $form_state->getValue('bananas')) ->save(); } diff --git a/core/modules/system/tests/modules/form_test/src/FormTestServiceObject.php b/core/modules/system/tests/modules/form_test/src/FormTestServiceObject.php index 40682cb86b5..de4e6c0fdcd 100644 --- a/core/modules/system/tests/modules/form_test/src/FormTestServiceObject.php +++ b/core/modules/system/tests/modules/form_test/src/FormTestServiceObject.php @@ -55,7 +55,7 @@ class FormTestServiceObject extends FormBase { public function submitForm(array &$form, FormStateInterface $form_state) { drupal_set_message($this->t('The FormTestServiceObject::submitForm() method was used for this form.')); $this->config('form_test.object') - ->set('bananas', $form_state['values']['bananas']) + ->set('bananas', $form_state->getValue('bananas')) ->save(); } diff --git a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/TestToolkit.php b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/TestToolkit.php index 36ab20ce4ca..3c1ceec5896 100644 --- a/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/TestToolkit.php +++ b/core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/TestToolkit.php @@ -63,7 +63,7 @@ class TestToolkit extends ImageToolkitBase { */ public function settingsFormSubmit($form, FormStateInterface $form_state) { \Drupal::config('system.image.test_toolkit') - ->set('test_parameter', $form_state['values']['test']['test_parameter']) + ->set('test_parameter', $form_state->getValue(array('test', 'test_parameter'))) ->save(); } diff --git a/core/modules/system/tests/modules/session_test/src/Form/SessionTestForm.php b/core/modules/system/tests/modules/session_test/src/Form/SessionTestForm.php index 3cf17f80a9f..f8d5614a336 100644 --- a/core/modules/system/tests/modules/session_test/src/Form/SessionTestForm.php +++ b/core/modules/system/tests/modules/session_test/src/Form/SessionTestForm.php @@ -46,7 +46,7 @@ class SessionTestForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - drupal_set_message(String::format('Ok: @input', array('@input' => $form_state['values']['input']))); + drupal_set_message(String::format('Ok: @input', array('@input' => $form_state->getValue('input')))); } } diff --git a/core/modules/taxonomy/src/Form/OverviewTerms.php b/core/modules/taxonomy/src/Form/OverviewTerms.php index 88addad40bb..dcd56c91007 100644 --- a/core/modules/taxonomy/src/Form/OverviewTerms.php +++ b/core/modules/taxonomy/src/Form/OverviewTerms.php @@ -366,7 +366,7 @@ class OverviewTerms extends FormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { // Sort term order based on weight. - uasort($form_state['values']['terms'], array('Drupal\Component\Utility\SortArray', 'sortByWeightElement')); + uasort($form_state->getValue('terms'), array('Drupal\Component\Utility\SortArray', 'sortByWeightElement')); $vocabulary = $form_state['taxonomy']['vocabulary']; // Update the current hierarchy type as we go. @@ -396,7 +396,7 @@ class OverviewTerms extends FormBase { // Renumber the current page weights and assign any new parents. $level_weights = array(); - foreach ($form_state['values']['terms'] as $tid => $values) { + foreach ($form_state->getValue('terms') as $tid => $values) { if (isset($form['terms'][$tid]['#term'])) { $term = $form['terms'][$tid]['#term']; // Give terms at the root level a weight in sequence with terms on previous pages. diff --git a/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php index 35c4c7373d6..0bbf925a26b 100644 --- a/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php @@ -217,11 +217,9 @@ class TaxonomyIndexTid extends ManyToOne { return; } - $values = Tags::explode($form_state['values']['options']['value']); - $tids = $this->validate_term_strings($form['value'], $values, $form_state); - - if ($tids) { - $form_state['values']['options']['value'] = $tids; + $values = Tags::explode($form_state->getValue('options', 'value')); + if ($tids = $this->validate_term_strings($form['value'], $values, $form_state)) { + $form_state->setValue(array('options', 'value'), $tids); } } @@ -261,8 +259,8 @@ class TaxonomyIndexTid extends ManyToOne { // We only validate if they've chosen the text field style. if ($this->options['type'] != 'textfield') { - if ($form_state['values'][$identifier] != 'All') { - $this->validated_exposed_input = (array) $form_state['values'][$identifier]; + if ($form_state->getValue($identifier) != 'All') { + $this->validated_exposed_input = (array) $form_state->getValue($identifier); } return; } @@ -271,7 +269,7 @@ class TaxonomyIndexTid extends ManyToOne { return; } - $values = Tags::explode($form_state['values'][$identifier]); + $values = Tags::explode($form_state->getValue($identifier)); $tids = $this->validate_term_strings($form[$identifier], $values, $form_state); if ($tids) { diff --git a/core/modules/taxonomy/src/TermForm.php b/core/modules/taxonomy/src/TermForm.php index 1af2453f84b..4a82e6731e6 100644 --- a/core/modules/taxonomy/src/TermForm.php +++ b/core/modules/taxonomy/src/TermForm.php @@ -108,7 +108,7 @@ class TermForm extends ContentEntityForm { parent::validate($form, $form_state); // Ensure numeric values. - if (isset($form_state['values']['weight']) && !is_numeric($form_state['values']['weight'])) { + if ($form_state->hasValue('weight') && !is_numeric($form_state->getValue('weight'))) { $form_state->setErrorByName('weight', $this->t('Weight value must be numeric.')); } } @@ -123,7 +123,7 @@ class TermForm extends ContentEntityForm { $term->setName(trim($term->getName())); // Assign parents with proper delta values starting from 0. - $term->parent = array_keys($form_state['values']['parent']); + $term->parent = array_keys($form_state->getValue('parent')); return $term; } @@ -145,18 +145,18 @@ class TermForm extends ContentEntityForm { break; } - $current_parent_count = count($form_state['values']['parent']); + $current_parent_count = count($form_state->getValue('parent')); $previous_parent_count = count($form_state['taxonomy']['parent']); // Root doesn't count if it's the only parent. - if ($current_parent_count == 1 && isset($form_state['values']['parent'][0])) { + if ($current_parent_count == 1 && $form_state->hasValue(array('parent', 0))) { $current_parent_count = 0; - $form_state['values']['parent'] = array(); + $form_state->setValue('parent', array()); } // If the number of parents has been reduced to one or none, do a check on the // parents of every term in the vocabulary value. if ($current_parent_count < $previous_parent_count && $current_parent_count < 2) { - taxonomy_check_vocabulary_hierarchy($form_state['taxonomy']['vocabulary'], $form_state['values']); + taxonomy_check_vocabulary_hierarchy($form_state['taxonomy']['vocabulary'], $form_state->getValues()); } // If we've increased the number of parents and this is a single or flat // hierarchy, update the vocabulary immediately. @@ -165,7 +165,7 @@ class TermForm extends ContentEntityForm { $form_state['taxonomy']['vocabulary']->save(); } - $form_state['values']['tid'] = $term->id(); + $form_state->setValue('tid', $term->id()); $form_state['tid'] = $term->id(); } diff --git a/core/modules/taxonomy/src/VocabularyForm.php b/core/modules/taxonomy/src/VocabularyForm.php index 3a8a8b390b1..d34d3e2464d 100644 --- a/core/modules/taxonomy/src/VocabularyForm.php +++ b/core/modules/taxonomy/src/VocabularyForm.php @@ -119,13 +119,13 @@ class VocabularyForm extends EntityForm { $vocabulary = $this->entity; // Delete the old language settings for the vocabulary, if the machine name // is changed. - if ($vocabulary && $vocabulary->id() && $vocabulary->id() != $form_state['values']['vid']) { + if ($vocabulary && $vocabulary->id() && $vocabulary->id() != $form_state->getValue('vid')) { language_clear_default_configuration('taxonomy_term', $vocabulary->id()); } // Since the machine name is not known yet, and it can be changed anytime, // we have to also update the bundle property for the default language // configuration in order to have the correct bundle value. - $form_state['language']['default_language']['bundle'] = $form_state['values']['vid']; + $form_state['language']['default_language']['bundle'] = $form_state->getValue('vid'); } /** @@ -153,7 +153,7 @@ class VocabularyForm extends EntityForm { break; } - $form_state['values']['vid'] = $vocabulary->id(); + $form_state->setValue('vid', $vocabulary->id()); $form_state['vid'] = $vocabulary->id(); } diff --git a/core/modules/update/src/Form/UpdateManagerInstall.php b/core/modules/update/src/Form/UpdateManagerInstall.php index 58a49a0495b..3198a288e4a 100644 --- a/core/modules/update/src/Form/UpdateManagerInstall.php +++ b/core/modules/update/src/Form/UpdateManagerInstall.php @@ -104,7 +104,7 @@ class UpdateManagerInstall extends FormBase { */ public function validateForm(array &$form, FormStateInterface $form_state) { $uploaded_file = $this->getRequest()->files->get('files[project_upload]', NULL, TRUE); - if (!($form_state['values']['project_url'] XOR !empty($uploaded_file))) { + if (!($form_state->getValue('project_url') XOR !empty($uploaded_file))) { $form_state->setErrorByName('project_url', $this->t('You must either provide a URL or upload an archive file to install.')); } } @@ -114,10 +114,10 @@ class UpdateManagerInstall extends FormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $local_cache = NULL; - if ($form_state['values']['project_url']) { - $local_cache = update_manager_file_get($form_state['values']['project_url']); + if ($form_state->getValue('project_url')) { + $local_cache = update_manager_file_get($form_state->getValue('project_url')); if (!$local_cache) { - drupal_set_message($this->t('Unable to retrieve Drupal project from %url.', array('%url' => $form_state['values']['project_url'])), 'error'); + drupal_set_message($this->t('Unable to retrieve Drupal project from %url.', array('%url' => $form_state->getValue('project_url'))), 'error'); return; } } diff --git a/core/modules/update/src/Form/UpdateManagerUpdate.php b/core/modules/update/src/Form/UpdateManagerUpdate.php index 745abb60992..c90247f9e1a 100644 --- a/core/modules/update/src/Form/UpdateManagerUpdate.php +++ b/core/modules/update/src/Form/UpdateManagerUpdate.php @@ -287,11 +287,11 @@ class UpdateManagerUpdate extends FormBase { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - if (!empty($form_state['values']['projects'])) { - $enabled = array_filter($form_state['values']['projects']); + if (!$form_state->isValueEmpty('projects')) { + $enabled = array_filter($form_state->getValue('projects')); } - if (!empty($form_state['values']['disabled_projects'])) { - $disabled = array_filter($form_state['values']['disabled_projects']); + if (!$form_state->isValueEmpty('disabled_projects')) { + $disabled = array_filter($form_state->getValue('disabled_projects')); } if (empty($enabled) && empty($disabled)) { $form_state->setErrorByName('projects', $this->t('You must select at least one project to update.')); @@ -305,8 +305,8 @@ class UpdateManagerUpdate extends FormBase { $this->moduleHandler->loadInclude('update', 'inc', 'update.manager'); $projects = array(); foreach (array('projects', 'disabled_projects') as $type) { - if (!empty($form_state['values'][$type])) { - $projects = array_merge($projects, array_keys(array_filter($form_state['values'][$type]))); + if (!$form_state->isValueEmpty($type)) { + $projects = array_merge($projects, array_keys(array_filter($form_state->getValue($type)))); } } $operations = array(); @@ -315,7 +315,7 @@ class UpdateManagerUpdate extends FormBase { 'update_manager_batch_project_get', array( $project, - $form_state['values']['project_downloads'][$project], + $form_state->getValue(array('project_downloads', $project)), ), ); } diff --git a/core/modules/update/src/Form/UpdateReady.php b/core/modules/update/src/Form/UpdateReady.php index 71bb44176bf..66e94de488a 100644 --- a/core/modules/update/src/Form/UpdateReady.php +++ b/core/modules/update/src/Form/UpdateReady.php @@ -100,7 +100,7 @@ class UpdateReady extends FormBase { public function submitForm(array &$form, FormStateInterface $form_state) { // Store maintenance_mode setting so we can restore it when done. $_SESSION['maintenance_mode'] = $this->state->get('system.maintenance_mode'); - if ($form_state['values']['maintenance_mode'] == TRUE) { + if ($form_state->getValue('maintenance_mode') == TRUE) { $this->state->set('system.maintenance_mode', TRUE); } diff --git a/core/modules/update/src/UpdateSettingsForm.php b/core/modules/update/src/UpdateSettingsForm.php index ed6e81febaf..b1e0f3297b0 100644 --- a/core/modules/update/src/UpdateSettingsForm.php +++ b/core/modules/update/src/UpdateSettingsForm.php @@ -73,10 +73,10 @@ class UpdateSettingsForm extends ConfigFormBase { */ public function validateForm(array &$form, FormStateInterface $form_state) { $form_state['notify_emails'] = array(); - if (!empty($form_state['values']['update_notify_emails'])) { + if (!$form_state->isValueEmpty('update_notify_emails')) { $valid = array(); $invalid = array(); - foreach (explode("\n", trim($form_state['values']['update_notify_emails'])) as $email) { + foreach (explode("\n", trim($form_state->getValue('update_notify_emails'))) as $email) { $email = trim($email); if (!empty($email)) { if (valid_email_address($email)) { @@ -108,15 +108,15 @@ class UpdateSettingsForm extends ConfigFormBase { $config = $this->config('update.settings'); // See if the update_check_disabled setting is being changed, and if so, // invalidate all update status data. - if ($form_state['values']['update_check_disabled'] != $config->get('check.disabled_extensions')) { + if ($form_state->getValue('update_check_disabled') != $config->get('check.disabled_extensions')) { update_storage_clear(); } $config - ->set('check.disabled_extensions', $form_state['values']['update_check_disabled']) - ->set('check.interval_days', $form_state['values']['update_check_frequency']) + ->set('check.disabled_extensions', $form_state->getValue('update_check_disabled')) + ->set('check.interval_days', $form_state->getValue('update_check_frequency')) ->set('notification.emails', $form_state['notify_emails']) - ->set('notification.threshold', $form_state['values']['update_notification_threshold']) + ->set('notification.threshold', $form_state->getValue('update_notification_threshold')) ->save(); parent::submitForm($form, $form_state); diff --git a/core/modules/user/src/AccountForm.php b/core/modules/user/src/AccountForm.php index 5a8fe2e2b50..15df478c7a2 100644 --- a/core/modules/user/src/AccountForm.php +++ b/core/modules/user/src/AccountForm.php @@ -311,8 +311,8 @@ abstract class AccountForm extends ContentEntityForm { // numeric keys. Allow to override this per field. As this function is // called twice, we have to prevent it from getting the array keys twice. - if (is_string(key($form_state['values']['roles']))) { - $form_state['values']['roles'] = array_keys(array_filter($form_state['values']['roles'])); + if (is_string(key($form_state->getValue('roles')))) { + $form_state->setValue('roles', array_keys(array_filter($form_state->getValue('roles')))); } return parent::buildEntity($form, $form_state); } @@ -325,8 +325,8 @@ abstract class AccountForm extends ContentEntityForm { $account = $this->entity; // Validate new or changing username. - if (isset($form_state['values']['name'])) { - if ($error = user_validate_name($form_state['values']['name'])) { + if ($form_state->hasValue('name')) { + if ($error = user_validate_name($form_state->getValue('name'))) { $form_state->setErrorByName('name', $error); } // Cast the user ID as an integer. It might have been set to NULL, which @@ -334,18 +334,18 @@ abstract class AccountForm extends ContentEntityForm { else { $name_taken = (bool) $this->entityQuery->get('user') ->condition('uid', (int) $account->id(), '<>') - ->condition('name', $form_state['values']['name']) + ->condition('name', $form_state->getValue('name')) ->range(0, 1) ->count() ->execute(); if ($name_taken) { - $form_state->setErrorByName('name', $this->t('The name %name is already taken.', array('%name' => $form_state['values']['name']))); + $form_state->setErrorByName('name', $this->t('The name %name is already taken.', array('%name' => $form_state->getValue('name')))); } } } - $mail = $form_state['values']['mail']; + $mail = $form_state->getValue('mail'); if (!empty($mail)) { $mail_taken = (bool) $this->entityQuery->get('user') @@ -368,17 +368,17 @@ abstract class AccountForm extends ContentEntityForm { // Make sure the signature isn't longer than the size of the database field. // Signatures are disabled by default, so make sure it exists first. - if (isset($form_state['values']['signature'])) { + if ($signature = $form_state->getValue('signature')) { // Move text format for user signature into 'signature_format'. - $form_state['values']['signature_format'] = $form_state['values']['signature']['format']; + $form_state->setValue('signature_format', $signature['format']); // Move text value for user signature into 'signature'. - $form_state['values']['signature'] = $form_state['values']['signature']['value']; + $form_state->setValue('signature', $signature['value']); // @todo Make the user signature field use a widget to benefit from // automatic typed data validation in https://drupal.org/node/2227381. $field_definitions = $this->entityManager->getFieldDefinitions('user', $this->getEntity()->bundle()); $max_length = $field_definitions['signature']->getSetting('max_length'); - if (drupal_strlen($form_state['values']['signature']) > $max_length) { + if (drupal_strlen($form_state->getValue('signature')) > $max_length) { $form_state->setErrorByName('signature', $this->t('The signature is too long: it must be %max characters or less.', array('%max' => $max_length))); } } diff --git a/core/modules/user/src/AccountSettingsForm.php b/core/modules/user/src/AccountSettingsForm.php index 06e1a091040..8fc998bb4b4 100644 --- a/core/modules/user/src/AccountSettingsForm.php +++ b/core/modules/user/src/AccountSettingsForm.php @@ -413,37 +413,37 @@ class AccountSettingsForm extends ConfigFormBase { parent::submitForm($form, $form_state); $this->config('user.settings') - ->set('anonymous', $form_state['values']['anonymous']) - ->set('admin_role', $form_state['values']['user_admin_role']) - ->set('register', $form_state['values']['user_register']) - ->set('password_strength', $form_state['values']['user_password_strength']) - ->set('verify_mail', $form_state['values']['user_email_verification']) - ->set('signatures', $form_state['values']['user_signatures']) - ->set('cancel_method', $form_state['values']['user_cancel_method']) - ->set('notify.status_activated', $form_state['values']['user_mail_status_activated_notify']) - ->set('notify.status_blocked', $form_state['values']['user_mail_status_blocked_notify']) - ->set('notify.status_canceled', $form_state['values']['user_mail_status_canceled_notify']) + ->set('anonymous', $form_state->getValue('anonymous')) + ->set('admin_role', $form_state->getValue('user_admin_role')) + ->set('register', $form_state->getValue('user_register')) + ->set('password_strength', $form_state->getValue('user_password_strength')) + ->set('verify_mail', $form_state->getValue('user_email_verification')) + ->set('signatures', $form_state->getValue('user_signatures')) + ->set('cancel_method', $form_state->getValue('user_cancel_method')) + ->set('notify.status_activated', $form_state->getValue('user_mail_status_activated_notify')) + ->set('notify.status_blocked', $form_state->getValue('user_mail_status_blocked_notify')) + ->set('notify.status_canceled', $form_state->getValue('user_mail_status_canceled_notify')) ->save(); $this->config('user.mail') - ->set('cancel_confirm.body', $form_state['values']['user_mail_cancel_confirm_body']) - ->set('cancel_confirm.subject', $form_state['values']['user_mail_cancel_confirm_subject']) - ->set('password_reset.body', $form_state['values']['user_mail_password_reset_body']) - ->set('password_reset.subject', $form_state['values']['user_mail_password_reset_subject']) - ->set('register_admin_created.body', $form_state['values']['user_mail_register_admin_created_body']) - ->set('register_admin_created.subject', $form_state['values']['user_mail_register_admin_created_subject']) - ->set('register_no_approval_required.body', $form_state['values']['user_mail_register_no_approval_required_body']) - ->set('register_no_approval_required.subject', $form_state['values']['user_mail_register_no_approval_required_subject']) - ->set('register_pending_approval.body', $form_state['values']['user_mail_register_pending_approval_body']) - ->set('register_pending_approval.subject', $form_state['values']['user_mail_register_pending_approval_subject']) - ->set('status_activated.body', $form_state['values']['user_mail_status_activated_body']) - ->set('status_activated.subject', $form_state['values']['user_mail_status_activated_subject']) - ->set('status_blocked.body', $form_state['values']['user_mail_status_blocked_body']) - ->set('status_blocked.subject', $form_state['values']['user_mail_status_blocked_subject']) - ->set('status_canceled.body', $form_state['values']['user_mail_status_canceled_body']) - ->set('status_canceled.subject', $form_state['values']['user_mail_status_canceled_subject']) + ->set('cancel_confirm.body', $form_state->getValue('user_mail_cancel_confirm_body')) + ->set('cancel_confirm.subject', $form_state->getValue('user_mail_cancel_confirm_subject')) + ->set('password_reset.body', $form_state->getValue('user_mail_password_reset_body')) + ->set('password_reset.subject', $form_state->getValue('user_mail_password_reset_subject')) + ->set('register_admin_created.body', $form_state->getValue('user_mail_register_admin_created_body')) + ->set('register_admin_created.subject', $form_state->getValue('user_mail_register_admin_created_subject')) + ->set('register_no_approval_required.body', $form_state->getValue('user_mail_register_no_approval_required_body')) + ->set('register_no_approval_required.subject', $form_state->getValue('user_mail_register_no_approval_required_subject')) + ->set('register_pending_approval.body', $form_state->getValue('user_mail_register_pending_approval_body')) + ->set('register_pending_approval.subject', $form_state->getValue('user_mail_register_pending_approval_subject')) + ->set('status_activated.body', $form_state->getValue('user_mail_status_activated_body')) + ->set('status_activated.subject', $form_state->getValue('user_mail_status_activated_subject')) + ->set('status_blocked.body', $form_state->getValue('user_mail_status_blocked_body')) + ->set('status_blocked.subject', $form_state->getValue('user_mail_status_blocked_subject')) + ->set('status_canceled.body', $form_state->getValue('user_mail_status_canceled_body')) + ->set('status_canceled.subject', $form_state->getValue('user_mail_status_canceled_subject')) ->save(); $this->config('system.site') - ->set('mail_notification', $form_state['values']['mail_notification_address']) + ->set('mail_notification', $form_state->getValue('mail_notification_address')) ->save(); } diff --git a/core/modules/user/src/Form/UserCancelForm.php b/core/modules/user/src/Form/UserCancelForm.php index 25a7f1df124..2dcef4eb9eb 100644 --- a/core/modules/user/src/Form/UserCancelForm.php +++ b/core/modules/user/src/Form/UserCancelForm.php @@ -122,16 +122,16 @@ class UserCancelForm extends ContentEntityConfirmFormBase { // Cancel account immediately, if the current user has administrative // privileges, no confirmation mail shall be sent, and the user does not // attempt to cancel the own account. - if ($this->currentUser()->hasPermission('administer users') && empty($form_state['values']['user_cancel_confirm']) && $this->entity->id() != $this->currentUser()->id()) { - user_cancel($form_state['values'], $this->entity->id(), $form_state['values']['user_cancel_method']); + if ($this->currentUser()->hasPermission('administer users') && $form_state->isValueEmpty('user_cancel_confirm') && $this->entity->id() != $this->currentUser()->id()) { + user_cancel($form_state->getValues(), $this->entity->id(), $form_state->getValue('user_cancel_method')); $form_state->setRedirect('user.admin_account'); } else { // Store cancelling method and whether to notify the user in // $this->entity for user_cancel_confirm(). - $this->entity->user_cancel_method = $form_state['values']['user_cancel_method']; - $this->entity->user_cancel_notify = $form_state['values']['user_cancel_notify']; + $this->entity->user_cancel_method = $form_state->getValue('user_cancel_method'); + $this->entity->user_cancel_notify = $form_state->getValue('user_cancel_notify'); $this->entity->save(); _user_mail_notify('cancel_confirm', $this->entity); drupal_set_message($this->t('A confirmation request to cancel your account has been sent to your email address.')); diff --git a/core/modules/user/src/Form/UserLoginForm.php b/core/modules/user/src/Form/UserLoginForm.php index 8f5f586bd57..104358fac51 100644 --- a/core/modules/user/src/Form/UserLoginForm.php +++ b/core/modules/user/src/Form/UserLoginForm.php @@ -136,9 +136,9 @@ class UserLoginForm extends FormBase { * Sets an error if supplied username has been blocked. */ public function validateName(array &$form, FormStateInterface $form_state) { - if (!empty($form_state['values']['name']) && user_is_blocked($form_state['values']['name'])) { + if (!$form_state->isValueEmpty('name') && user_is_blocked($form_state->getValue('name'))) { // Blocked in user administration. - $form_state->setErrorByName('name', $this->t('The username %name has not been activated or is blocked.', array('%name' => $form_state['values']['name']))); + $form_state->setErrorByName('name', $this->t('The username %name has not been activated or is blocked.', array('%name' => $form_state->getValue('name')))); } } @@ -148,9 +148,9 @@ class UserLoginForm extends FormBase { * If successful, $form_state['uid'] is set to the matching user ID. */ public function validateAuthentication(array &$form, FormStateInterface $form_state) { - $password = trim($form_state['values']['pass']); + $password = trim($form_state->getValue('pass')); $flood_config = $this->config('user.flood'); - if (!empty($form_state['values']['name']) && !empty($password)) { + if (!$form_state->isValueEmpty('name') && !empty($password)) { // Do not allow any login from the current user's IP if the limit has been // reached. Default is 50 failed attempts allowed in one hour. This is // independent of the per-user limit to catch attempts from one IP to log @@ -160,7 +160,7 @@ class UserLoginForm extends FormBase { $form_state['flood_control_triggered'] = 'ip'; return; } - $accounts = $this->userStorage->loadByProperties(array('name' => $form_state['values']['name'], 'status' => 1)); + $accounts = $this->userStorage->loadByProperties(array('name' => $form_state->getValue('name'), 'status' => 1)); $account = reset($accounts); if ($account) { if ($flood_config->get('uid_only')) { @@ -185,7 +185,7 @@ class UserLoginForm extends FormBase { } // We are not limited by flood control, so try to authenticate. // Set $form_state['uid'] as a flag for self::validateFinal(). - $form_state['uid'] = $this->userAuth->authenticate($form_state['values']['name'], $password); + $form_state['uid'] = $this->userAuth->authenticate($form_state->getValue('name'), $password); } } @@ -214,10 +214,10 @@ class UserLoginForm extends FormBase { } } else { - $form_state->setErrorByName('name', $this->t('Sorry, unrecognized username or password. <a href="@password">Have you forgotten your password?</a>', array('@password' => url('user/password', array('query' => array('name' => $form_state['values']['name'])))))); - $accounts = $this->userStorage->loadByProperties(array('name' => $form_state['values']['name'])); + $form_state->setErrorByName('name', $this->t('Sorry, unrecognized username or password. <a href="@password">Have you forgotten your password?</a>', array('@password' => url('user/password', array('query' => array('name' => $form_state->getValue('name'))))))); + $accounts = $this->userStorage->loadByProperties(array('name' => $form_state->getValue('name'))); if (!empty($accounts)) { - $this->logger('user')->notice('Login attempt failed for %user.', array('%user' => $form_state['values']['name'])); + $this->logger('user')->notice('Login attempt failed for %user.', array('%user' => $form_state->getValue('name'))); } else { // If the username entered is not a valid user, diff --git a/core/modules/user/src/Form/UserMultipleCancelConfirm.php b/core/modules/user/src/Form/UserMultipleCancelConfirm.php index cb0960c67e2..1c832fa373d 100644 --- a/core/modules/user/src/Form/UserMultipleCancelConfirm.php +++ b/core/modules/user/src/Form/UserMultipleCancelConfirm.php @@ -174,8 +174,8 @@ class UserMultipleCancelConfirm extends ConfirmFormBase { // Clear out the accounts from the temp store. $this->tempStoreFactory->get('user_user_operations_cancel')->delete($current_user_id); - if ($form_state['values']['confirm']) { - foreach ($form_state['values']['accounts'] as $uid => $value) { + if ($form_state->getValue('confirm')) { + foreach ($form_state->getValue('accounts') as $uid => $value) { // Prevent programmatic form submissions from cancelling user 1. if ($uid <= 1) { continue; @@ -184,7 +184,7 @@ class UserMultipleCancelConfirm extends ConfirmFormBase { if ($uid == $current_user_id) { $admin_form_mock = array(); $admin_form_state = $form_state; - unset($admin_form_state['values']['user_cancel_confirm']); + $admin_form_state->unsetValue('user_cancel_confirm'); // The $user global is not a complete user entity, so load the full // entity. $account = $this->userStorage->load($uid); @@ -195,7 +195,7 @@ class UserMultipleCancelConfirm extends ConfirmFormBase { $admin_form->submit($admin_form_mock, $admin_form_state); } else { - user_cancel($form_state['values'], $uid, $form_state['values']['user_cancel_method']); + user_cancel($form_state->getValues(), $uid, $form_state->getValue('user_cancel_method')); } } } diff --git a/core/modules/user/src/Form/UserPasswordForm.php b/core/modules/user/src/Form/UserPasswordForm.php index 4ba6f6fc1ea..bda1a35d470 100644 --- a/core/modules/user/src/Form/UserPasswordForm.php +++ b/core/modules/user/src/Form/UserPasswordForm.php @@ -108,7 +108,7 @@ class UserPasswordForm extends FormBase { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - $name = trim($form_state['values']['name']); + $name = trim($form_state->getValue('name')); // Try to load by email. $users = $this->userStorage->loadByProperties(array('mail' => $name, 'status' => '1')); if (empty($users)) { @@ -130,7 +130,7 @@ class UserPasswordForm extends FormBase { public function submitForm(array &$form, FormStateInterface $form_state) { $langcode = $this->languageManager->getCurrentLanguage()->id; - $account = $form_state['values']['account']; + $account = $form_state->getValue('account'); // Mail one time login URL and instructions using current language. $mail = _user_mail_notify('password_reset', $account, $langcode); if (!empty($mail)) { diff --git a/core/modules/user/src/Form/UserPasswordResetForm.php b/core/modules/user/src/Form/UserPasswordResetForm.php index 5b49d6b2a26..5709c36e8c5 100644 --- a/core/modules/user/src/Form/UserPasswordResetForm.php +++ b/core/modules/user/src/Form/UserPasswordResetForm.php @@ -101,9 +101,9 @@ class UserPasswordResetForm extends FormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { /** @var $user \Drupal\user\UserInterface */ - $user = $form_state['values']['user']; + $user = $form_state->getValue('user'); user_login_finalize($user); - $this->logger->notice('User %name used one-time login link at time %timestamp.', array('%name' => $user->getUsername(), '%timestamp' => $form_state['values']['timestamp'])); + $this->logger->notice('User %name used one-time login link at time %timestamp.', array('%name' => $user->getUsername(), '%timestamp' => $form_state->getValue('timestamp'))); drupal_set_message($this->t('You have just used your one-time login link. It is no longer necessary to use this link to log in. Please change your password.')); // Let the user's password be changed without the current password check. $token = Crypt::randomBytesBase64(55); diff --git a/core/modules/user/src/Form/UserPermissionsForm.php b/core/modules/user/src/Form/UserPermissionsForm.php index 8e5ac1d4f70..bf34063ba49 100644 --- a/core/modules/user/src/Form/UserPermissionsForm.php +++ b/core/modules/user/src/Form/UserPermissionsForm.php @@ -186,8 +186,8 @@ class UserPermissionsForm extends FormBase { * {@inheritdoc} */ function submitForm(array &$form, FormStateInterface $form_state) { - foreach ($form_state['values']['role_names'] as $role_name => $name) { - user_role_change_permissions($role_name, $form_state['values'][$role_name]); + foreach ($form_state->getValue('role_names') as $role_name => $name) { + user_role_change_permissions($role_name, $form_state->getValue($role_name)); } drupal_set_message($this->t('The changes have been saved.')); diff --git a/core/modules/user/src/Plugin/Action/ChangeUserRoleBase.php b/core/modules/user/src/Plugin/Action/ChangeUserRoleBase.php index c6fb44afd76..62c421466ae 100644 --- a/core/modules/user/src/Plugin/Action/ChangeUserRoleBase.php +++ b/core/modules/user/src/Plugin/Action/ChangeUserRoleBase.php @@ -77,7 +77,7 @@ abstract class ChangeUserRoleBase extends ConfigurableActionBase implements Cont * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['rid'] = $form_state['values']['rid']; + $this->configuration['rid'] = $form_state->getValue('rid'); } /** diff --git a/core/modules/user/src/Plugin/Condition/UserRole.php b/core/modules/user/src/Plugin/Condition/UserRole.php index 5400d4ecd7e..1462c8f7d04 100644 --- a/core/modules/user/src/Plugin/Condition/UserRole.php +++ b/core/modules/user/src/Plugin/Condition/UserRole.php @@ -52,7 +52,7 @@ class UserRole extends ConditionPluginBase { * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $this->configuration['roles'] = array_filter($form_state['values']['roles']); + $this->configuration['roles'] = array_filter($form_state->getValue('roles')); parent::submitConfigurationForm($form, $form_state); } diff --git a/core/modules/user/src/Plugin/views/access/Role.php b/core/modules/user/src/Plugin/views/access/Role.php index c63a5a46d5c..7008b902177 100644 --- a/core/modules/user/src/Plugin/views/access/Role.php +++ b/core/modules/user/src/Plugin/views/access/Role.php @@ -82,14 +82,14 @@ class Role extends AccessPluginBase { } public function validateOptionsForm(&$form, FormStateInterface $form_state) { - if (!array_filter($form_state['values']['access_options']['role'])) { + $role = $form_state->getValue(array('access_options', 'role')); + $role = array_filter($role); + + if (!$role) { form_error($form['role'], $form_state, t('You must select at least one role if type is "by role"')); } - } - public function submitOptionsForm(&$form, FormStateInterface $form_state) { - // I hate checkboxes. - $form_state['values']['access_options']['role'] = array_filter($form_state['values']['access_options']['role']); + $form_state->setValue(array('access_options', 'role'), $role); } } diff --git a/core/modules/user/src/Plugin/views/filter/Name.php b/core/modules/user/src/Plugin/views/filter/Name.php index 8bdb0016f8f..996001ce2ea 100644 --- a/core/modules/user/src/Plugin/views/filter/Name.php +++ b/core/modules/user/src/Plugin/views/filter/Name.php @@ -52,11 +52,9 @@ class Name extends InOperator { } protected function valueValidate($form, FormStateInterface $form_state) { - $values = Tags::explode($form_state['values']['options']['value']); - $uids = $this->validate_user_strings($form['value'], $form_state, $values); - - if ($uids) { - $form_state['values']['options']['value'] = $uids; + $values = Tags::explode($form_state->getValue(array('options', 'value'))); + if ($uids = $this->validate_user_strings($form['value'], $form_state, $values)) { + $form_state->setValue(array('options', 'value'), $uids); } } @@ -83,7 +81,7 @@ class Name extends InOperator { } $identifier = $this->options['expose']['identifier']; - $input = $form_state['values'][$identifier]; + $input = $form_state->getValue($identifier); if ($this->options['is_grouped'] && isset($this->options['group_info']['group_items'][$input])) { $this->operator = $this->options['group_info']['group_items'][$input]['operator']; diff --git a/core/modules/user/src/ProfileForm.php b/core/modules/user/src/ProfileForm.php index f9a0a94c6b3..4f0f0885d38 100644 --- a/core/modules/user/src/ProfileForm.php +++ b/core/modules/user/src/ProfileForm.php @@ -49,7 +49,7 @@ class ProfileForm extends AccountForm { public function save(array $form, FormStateInterface $form_state) { $account = $this->entity; $account->save(); - $form_state['values']['uid'] = $account->id(); + $form_state->setValue('uid', $account->id()); drupal_set_message($this->t('The changes have been saved.')); } diff --git a/core/modules/user/src/RegisterForm.php b/core/modules/user/src/RegisterForm.php index 5a6bfb63630..2a9cb41d0f1 100644 --- a/core/modules/user/src/RegisterForm.php +++ b/core/modules/user/src/RegisterForm.php @@ -76,10 +76,10 @@ class RegisterForm extends AccountForm { * Overrides Drupal\Core\Entity\EntityForm::submit(). */ public function submit(array $form, FormStateInterface $form_state) { - $admin = $form_state['values']['administer_users']; + $admin = $form_state->getValue('administer_users'); if (!\Drupal::config('user.settings')->get('verify_mail') || $admin) { - $pass = $form_state['values']['pass']; + $pass = $form_state->getValue('pass'); } else { $pass = user_password(); @@ -88,8 +88,8 @@ class RegisterForm extends AccountForm { // Remove unneeded values. form_state_values_clean($form_state); - $form_state['values']['pass'] = $pass; - $form_state['values']['init'] = $form_state['values']['mail']; + $form_state->setValue('pass', $pass); + $form_state->setValue('init', $form_state->getValue('mail')); parent::submit($form, $form_state); } @@ -100,17 +100,17 @@ class RegisterForm extends AccountForm { public function save(array $form, FormStateInterface $form_state) { $account = $this->entity; $pass = $account->getPassword(); - $admin = $form_state['values']['administer_users']; - $notify = !empty($form_state['values']['notify']); + $admin = $form_state->getValue('administer_users'); + $notify = !$form_state->isValueEmpty('notify'); // Save has no return value so this cannot be tested. // Assume save has gone through correctly. $account->save(); $form_state['user'] = $account; - $form_state['values']['uid'] = $account->id(); + $form_state->setValue('uid', $account->id()); - $this->logger('user')->notice('New user: %name %email.', array('%name' => $form_state['values']['name'], '%email' => '<' . $form_state['values']['mail'] . '>', 'type' => l($this->t('Edit'), 'user/' . $account->id() . '/edit'))); + $this->logger('user')->notice('New user: %name %email.', array('%name' => $form_state->getValue('name'), '%email' => '<' . $form_state->getValue('mail') . '>', 'type' => l($this->t('Edit'), 'user/' . $account->id() . '/edit'))); // Add plain text password into user account to generate mail tokens. $account->password = $pass; diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 2254e16750e..ad2aceb03a8 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -488,7 +488,7 @@ function _user_language_selector_langcode_value($element, $input, FormStateInter if (isset($form_state['complete_form']['language']['preferred_langcode']['#description'])) { $form_state['complete_form']['language']['preferred_langcode']['#description'] .= ' ' . t("This is also assumed to be the primary language of this account's profile information."); } - return $form_state['values']['preferred_langcode']; + return $form_state->getValue('preferred_langcode'); } /** @@ -498,13 +498,13 @@ function _user_language_selector_langcode_value($element, $input, FormStateInter */ function user_validate_current_pass(&$form, FormStateInterface $form_state) { $account = $form_state['user']; - foreach ($form_state['values']['current_pass_required_values'] as $key => $name) { + foreach ($form_state->getValue('current_pass_required_values') as $key => $name) { // This validation only works for required textfields (like mail) or // form values like password_confirm that have their own validation // that prevent them from being empty if they are changed. $current_value = $account->hasField($key) ? $account->get($key)->value : $account->$key; - if ((strlen(trim($form_state['values'][$key])) > 0) && ($form_state['values'][$key] != $current_value)) { - $current_pass_failed = empty($form_state['values']['current_pass']) || !\Drupal::service('password')->check($form_state['values']['current_pass'], $account); + if ((strlen(trim($form_state->getValue($key))) > 0) && ($form_state->getValue($key) != $current_value)) { + $current_pass_failed = $form_state->isValueEmpty('current_pass') || !\Drupal::service('password')->check($form_state->getValue('current_pass'), $account); if ($current_pass_failed) { form_set_error('current_pass', $form_state, t("Your current password is missing or incorrect; it's required to change the %name.", array('%name' => $name))); form_set_error($key, $form_state); diff --git a/core/modules/views/src/Form/ViewsExposedForm.php b/core/modules/views/src/Form/ViewsExposedForm.php index 2c78f5f2be5..4bc76fd173d 100644 --- a/core/modules/views/src/Form/ViewsExposedForm.php +++ b/core/modules/views/src/Form/ViewsExposedForm.php @@ -156,7 +156,7 @@ class ViewsExposedForm extends FormBase { $handlers[$key]->submitExposed($form, $form_state); } } - $form_state['view']->exposed_data = $form_state['values']; + $form_state['view']->exposed_data = $form_state->getValues(); $form_state['view']->exposed_raw_input = array(); $exclude = array('submit', 'form_build_id', 'form_id', 'form_token', 'exposed_form_plugin', '', 'reset'); @@ -164,7 +164,7 @@ class ViewsExposedForm extends FormBase { $exposed_form_plugin = $form_state['exposed_form_plugin']; $exposed_form_plugin->exposedFormSubmit($form, $form_state, $exclude); - foreach ($form_state['values'] as $key => $value) { + foreach ($form_state->getValues() as $key => $value) { if (!in_array($key, $exclude)) { $form_state['view']->exposed_raw_input[$key] = $value; } diff --git a/core/modules/views/src/Plugin/Block/ViewsBlockBase.php b/core/modules/views/src/Plugin/Block/ViewsBlockBase.php index 1d4dd9826d9..42b176f102f 100644 --- a/core/modules/views/src/Plugin/Block/ViewsBlockBase.php +++ b/core/modules/views/src/Plugin/Block/ViewsBlockBase.php @@ -165,8 +165,8 @@ abstract class ViewsBlockBase extends BlockBase implements ContainerFactoryPlugi * {@inheritdoc} */ public function blockSubmit($form, FormStateInterface $form_state) { - if (!empty($form_state['values']['views_label_checkbox'])) { - $this->configuration['views_label'] = $form_state['values']['views_label']; + if (!$form_state->isValueEmpty('views_label_checkbox')) { + $this->configuration['views_label'] = $form_state->getValue('views_label'); } else { $this->configuration['views_label'] = ''; diff --git a/core/modules/views/src/Plugin/Menu/Form/ViewsMenuLinkForm.php b/core/modules/views/src/Plugin/Menu/Form/ViewsMenuLinkForm.php index e1dc0033a7b..4eaf8c38569 100644 --- a/core/modules/views/src/Plugin/Menu/Form/ViewsMenuLinkForm.php +++ b/core/modules/views/src/Plugin/Menu/Form/ViewsMenuLinkForm.php @@ -75,8 +75,8 @@ class ViewsMenuLinkForm extends MenuLinkDefaultForm { */ public function extractFormValues(array &$form, FormStateInterface $form_state) { $definition = parent::extractFormValues($form, $form_state); - $definition['title'] = $form_state['values']['title']; - $definition['description'] = $form_state['values']['description']; + $definition['title'] = $form_state->getValue('title'); + $definition['description'] = $form_state->getValue('description'); return $definition; } diff --git a/core/modules/views/src/Plugin/views/HandlerBase.php b/core/modules/views/src/Plugin/views/HandlerBase.php index 368b4aceb44..33c8d81a9fd 100644 --- a/core/modules/views/src/Plugin/views/HandlerBase.php +++ b/core/modules/views/src/Plugin/views/HandlerBase.php @@ -281,7 +281,7 @@ abstract class HandlerBase extends PluginBase { */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { // Some form elements belong in a fieldset for presentation, but can't - // be moved into one because of the form_state['values'] hierarchy. Those + // be moved into one because of the $form_state->getValues() hierarchy. Those // elements can add a #fieldset => 'fieldset_name' property, and they'll // be moved to their fieldset during pre_render. $form['#pre_render'][] = array(get_class($this), 'preRenderAddFieldsetMarkup'); @@ -377,7 +377,7 @@ abstract class HandlerBase extends PluginBase { * There is no need for this function to actually store the data. */ public function submitGroupByForm(&$form, FormStateInterface $form_state) { - $form_state['handler']->options['group_type'] = $form_state['values']['options']['group_type']; + $form_state['handler']->options['group_type'] = $form_state->getValue(array('options', 'group_type')); } /** @@ -944,7 +944,7 @@ abstract class HandlerBase extends PluginBase { // Add the incoming options to existing options because items using // the extra form may not have everything in the form here. - $options = $form_state['values']['options'] + $this->options; + $options = $form_state->getValue('options') + $this->options; // This unpacks only options that are in the definition, ensuring random // extra stuff on the form is not sent through. diff --git a/core/modules/views/src/Plugin/views/PluginBase.php b/core/modules/views/src/Plugin/views/PluginBase.php index c2a48694017..132ceec8fdf 100644 --- a/core/modules/views/src/Plugin/views/PluginBase.php +++ b/core/modules/views/src/Plugin/views/PluginBase.php @@ -219,7 +219,7 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { // Some form elements belong in a fieldset for presentation, but can't - // be moved into one because of the form_state['values'] hierarchy. Those + // be moved into one because of the $form_state->getValues() hierarchy. Those // elements can add a #fieldset => 'fieldset_name' property, and they'll // be moved to their fieldset during pre_render. $form['#pre_render'][] = array(get_class($this), 'preRenderAddFieldsetMarkup'); @@ -375,7 +375,7 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor * easier storage. Moving the form elements into fieldsets during form * building would break up that hierarchy. Therefore, we wait until the * pre_render stage, where any changes we make affect presentation only and - * aren't reflected in $form_state['values']. + * aren't reflected in $form_state->getValues(). * * @param array $form * The form build array to alter. diff --git a/core/modules/views/src/Plugin/views/area/Text.php b/core/modules/views/src/Plugin/views/area/Text.php index 5a137c595b9..b5ca94982e6 100644 --- a/core/modules/views/src/Plugin/views/area/Text.php +++ b/core/modules/views/src/Plugin/views/area/Text.php @@ -48,8 +48,9 @@ class Text extends TokenizeAreaPluginBase { * {@inheritdoc} */ public function submitOptionsForm(&$form, FormStateInterface $form_state) { - $form_state['values']['options']['format'] = $form_state['values']['options']['content']['format']; - $form_state['values']['options']['content'] = $form_state['values']['options']['content']['value']; + $content = $form_state->getValue(array('options', 'content')); + $form_state->setValue(array('options', 'format'), $content['format']); + $form_state->setValue(array('options', 'content'), $content['value']); parent::submitOptionsForm($form, $form_state); } diff --git a/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php b/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php index 3a8bf48250d..81a3182c7b7 100644 --- a/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php +++ b/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php @@ -345,74 +345,75 @@ abstract class ArgumentPluginBase extends HandlerBase { } public function validateOptionsForm(&$form, FormStateInterface $form_state) { - if (empty($form_state['values']['options'])) { + $option_values = &$form_state->getValue('options'); + if (empty($option_values)) { return; } // Let the plugins do validation. - $default_id = $form_state['values']['options']['default_argument_type']; + $default_id = $option_values['default_argument_type']; $plugin = $this->getPlugin('argument_default', $default_id); if ($plugin) { - $plugin->validateOptionsForm($form['argument_default'][$default_id], $form_state, $form_state['values']['options']['argument_default'][$default_id]); + $plugin->validateOptionsForm($form['argument_default'][$default_id], $form_state, $option_values['argument_default'][$default_id]); } // summary plugin - $summary_id = $form_state['values']['options']['summary']['format']; + $summary_id = $option_values['summary']['format']; $plugin = $this->getPlugin('style', $summary_id); if ($plugin) { - $plugin->validateOptionsForm($form['summary']['options'][$summary_id], $form_state, $form_state['values']['options']['summary']['options'][$summary_id]); + $plugin->validateOptionsForm($form['summary']['options'][$summary_id], $form_state, $option_values['summary']['options'][$summary_id]); } - $sanitized_id = $form_state['values']['options']['validate']['type']; + $sanitized_id = $option_values['validate']['type']; // Correct ID for js sanitized version. $validate_id = static::decodeValidatorId($sanitized_id); $plugin = $this->getPlugin('argument_validator', $validate_id); if ($plugin) { - $plugin->validateOptionsForm($form['validate']['options'][$default_id], $form_state, $form_state['values']['options']['validate']['options'][$sanitized_id]); + $plugin->validateOptionsForm($form['validate']['options'][$default_id], $form_state, $option_values['validate']['options'][$sanitized_id]); } } public function submitOptionsForm(&$form, FormStateInterface $form_state) { - if (empty($form_state['values']['options'])) { + $option_values = &$form_state->getValue('options'); + if (empty($option_values)) { return; } // Let the plugins make submit modifications if necessary. - $default_id = $form_state['values']['options']['default_argument_type']; + $default_id = $option_values['default_argument_type']; $plugin = $this->getPlugin('argument_default', $default_id); if ($plugin) { - $options = &$form_state['values']['options']['argument_default'][$default_id]; + $options = &$option_values['argument_default'][$default_id]; $plugin->submitOptionsForm($form['argument_default'][$default_id], $form_state, $options); // Copy the now submitted options to their final resting place so they get saved. - $form_state['values']['options']['default_argument_options'] = $options; + $option_values['default_argument_options'] = $options; } // summary plugin - $summary_id = $form_state['values']['options']['summary']['format']; + $summary_id = $option_values['summary']['format']; $plugin = $this->getPlugin('style', $summary_id); if ($plugin) { - $options = &$form_state['values']['options']['summary']['options'][$summary_id]; + $options = &$option_values['summary']['options'][$summary_id]; $plugin->submitOptionsForm($form['summary']['options'][$summary_id], $form_state, $options); // Copy the now submitted options to their final resting place so they get saved. - $form_state['values']['options']['summary_options'] = $options; + $option_values['summary_options'] = $options; } - $sanitized_id = $form_state['values']['options']['validate']['type']; + $sanitized_id = $option_values['validate']['type']; // Correct ID for js sanitized version. - $form_state['values']['options']['validate']['type'] = $validate_id = static::decodeValidatorId($sanitized_id); + $option_values['validate']['type'] = $validate_id = static::decodeValidatorId($sanitized_id); $plugin = $this->getPlugin('argument_validator', $validate_id); if ($plugin) { - $options = &$form_state['values']['options']['validate']['options'][$sanitized_id]; + $options = &$option_values['validate']['options'][$sanitized_id]; $plugin->submitOptionsForm($form['validate']['options'][$sanitized_id], $form_state, $options); // Copy the now submitted options to their final resting place so they get saved. - $form_state['values']['options']['validate_options'] = $options; + $option_values['validate_options'] = $options; } // Clear out the content of title if it's not enabled. - $options = &$form_state['values']['options']; - if (empty($options['title_enable'])) { - $options['title'] = ''; + if (empty($option_values['title_enable'])) { + $option_values['title'] = ''; } } diff --git a/core/modules/views/src/Plugin/views/cache/Time.php b/core/modules/views/src/Plugin/views/cache/Time.php index 4b6984fd727..5cca1a1fef8 100644 --- a/core/modules/views/src/Plugin/views/cache/Time.php +++ b/core/modules/views/src/Plugin/views/cache/Time.php @@ -127,7 +127,8 @@ class Time extends CachePluginBase { public function validateOptionsForm(&$form, FormStateInterface $form_state) { $custom_fields = array('output_lifespan', 'results_lifespan'); foreach ($custom_fields as $field) { - if ($form_state['values']['cache_options'][$field] == 'custom' && !is_numeric($form_state['values']['cache_options'][$field . '_custom'])) { + $cache_options = $form_state->getValue('cache_options'); + if ($cache_options[$field] == 'custom' && !is_numeric($cache_options[$field . '_custom'])) { form_error($form[$field .'_custom'], $form_state, t('Custom time values must be numeric.')); } } diff --git a/core/modules/views/src/Plugin/views/display/Attachment.php b/core/modules/views/src/Plugin/views/display/Attachment.php index 1382933e56b..30870a0d8b0 100644 --- a/core/modules/views/src/Plugin/views/display/Attachment.php +++ b/core/modules/views/src/Plugin/views/display/Attachment.php @@ -220,13 +220,13 @@ class Attachment extends DisplayPluginBase { parent::submitOptionsForm($form, $form_state); switch ($form_state['section']) { case 'displays': - $form_state['values'][$form_state['section']] = array_filter($form_state['values'][$form_state['section']]); + $form_state->setValue($form_state['section'], array_filter($form_state->getValue($form_state['section']))); case 'inherit_arguments': case 'inherit_pager': case 'render_pager': case 'inherit_exposed_filters': case 'attachment_position': - $this->setOption($form_state['section'], $form_state['values'][$form_state['section']]); + $this->setOption($form_state['section'], $form_state->getValue($form_state['section'])); break; } } diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index b2245672a7d..31f30bc5f66 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -1871,24 +1871,24 @@ abstract class DisplayPluginBase extends PluginBase { public function validateOptionsForm(&$form, FormStateInterface $form_state) { switch ($form_state['section']) { case 'display_title': - if (empty($form_state['values']['display_title'])) { + if ($form_state->isValueEmpty('display_title')) { form_error($form['display_title'], $form_state, t('Display title may not be empty.')); } break; case 'css_class': - $css_class = $form_state['values']['css_class']; + $css_class = $form_state->getValue('css_class'); if (preg_match('/[^a-zA-Z0-9-_ ]/', $css_class)) { form_error($form['css_class'], $form_state, t('CSS classes must be alphanumeric or dashes only.')); } break; case 'display_id': - if ($form_state['values']['display_id']) { - if (preg_match('/[^a-z0-9_]/', $form_state['values']['display_id'])) { + if ($form_state->getValue('display_id')) { + if (preg_match('/[^a-z0-9_]/', $form_state->getValue('display_id'))) { form_error($form['display_id'], $form_state, t('Display name must be letters, numbers, or underscores only.')); } foreach ($this->view->displayHandlers as $id => $display) { - if ($id != $this->view->current_display && ($form_state['values']['display_id'] == $id || (isset($display->new_id) && $form_state['values']['display_id'] == $display->new_id))) { + if ($id != $this->view->current_display && ($form_state->getValue('display_id') == $id || (isset($display->new_id) && $form_state->getValue('display_id') == $display->new_id))) { form_error($form['display_id'], $form_state, t('Display id should be unique.')); } } @@ -1930,45 +1930,45 @@ abstract class DisplayPluginBase extends PluginBase { $section = $form_state['section']; switch ($section) { case 'display_id': - if (isset($form_state['values']['display_id'])) { - $this->display['new_id'] = $form_state['values']['display_id']; + if ($form_state->hasValue('display_id')) { + $this->display['new_id'] = $form_state->getValue('display_id'); } break; case 'display_title': - $this->display['display_title'] = $form_state['values']['display_title']; - $this->setOption('display_description', $form_state['values']['display_description']); + $this->display['display_title'] = $form_state->getValue('display_title'); + $this->setOption('display_description', $form_state->getValue('display_description')); break; case 'query': $plugin = $this->getPlugin('query'); if ($plugin) { $plugin->submitOptionsForm($form['query']['options'], $form_state); - $this->setOption('query', $form_state['values'][$section]); + $this->setOption('query', $form_state->getValue($section)); } break; case 'link_display': - $this->setOption('link_url', $form_state['values']['link_url']); + $this->setOption('link_url', $form_state->getValue('link_url')); case 'title': case 'css_class': case 'display_comment': case 'distinct': case 'group_by': - $this->setOption($section, $form_state['values'][$section]); + $this->setOption($section, $form_state->getValue($section)); break; case 'field_langcode': - $this->setOption('field_langcode', $form_state['values']['field_langcode']); - $this->setOption('field_langcode_add_to_query', $form_state['values']['field_langcode_add_to_query']); + $this->setOption('field_langcode', $form_state->getValue('field_langcode')); + $this->setOption('field_langcode_add_to_query', $form_state->getValue('field_langcode_add_to_query')); break; case 'use_ajax': case 'hide_attachment_summary': case 'show_admin_links': case 'exposed_block': - $this->setOption($section, (bool) $form_state['values'][$section]); + $this->setOption($section, (bool) $form_state->getValue($section)); break; case 'use_more': - $this->setOption($section, intval($form_state['values'][$section])); - $this->setOption('use_more_always', intval($form_state['values']['use_more_always'])); - $this->setOption('use_more_text', $form_state['values']['use_more_text']); + $this->setOption($section, intval($form_state->getValue($section))); + $this->setOption('use_more_always', intval($form_state->getValue('use_more_always'))); + $this->setOption('use_more_text', $form_state->getValue('use_more_text')); break; case 'access': @@ -1979,12 +1979,13 @@ abstract class DisplayPluginBase extends PluginBase { case 'style': $plugin_type = $section; $plugin_options = $this->getOption($plugin_type); - if ($plugin_options['type'] != $form_state['values'][$plugin_type]['type']) { - $plugin = Views::pluginManager($plugin_type)->createInstance($form_state['values'][$plugin_type]['type']); + $type = $form_state->getValue(array($plugin_type, 'type')); + if ($plugin_options['type'] != $type) { + $plugin = Views::pluginManager($plugin_type)->createInstance($type); if ($plugin) { $plugin->init($this->view, $this, $plugin_options['options']); $plugin_options = array( - 'type' => $form_state['values'][$plugin_type]['type'], + 'type' => $type, 'options' => $plugin->options, 'provider' => $plugin->definition['provider'] ); @@ -2008,7 +2009,7 @@ abstract class DisplayPluginBase extends PluginBase { if ($plugin = $this->getPlugin($plugin_type)) { $plugin_options = $this->getOption($plugin_type); $plugin->submitOptionsForm($form[$plugin_type . '_options'], $form_state); - $plugin_options['options'] = $form_state['values'][$section]; + $plugin_options['options'] = $form_state->getValue($section); $this->setOption($plugin_type, $plugin_options); } break; diff --git a/core/modules/views/src/Plugin/views/display/Feed.php b/core/modules/views/src/Plugin/views/display/Feed.php index a6e6fdda081..bd84581591e 100644 --- a/core/modules/views/src/Plugin/views/display/Feed.php +++ b/core/modules/views/src/Plugin/views/display/Feed.php @@ -244,10 +244,10 @@ class Feed extends PathPluginBase { parent::submitOptionsForm($form, $form_state); switch ($form_state['section']) { case 'title': - $this->setOption('sitename_title', $form_state['values']['sitename_title']); + $this->setOption('sitename_title', $form_state->getValue('sitename_title')); break; case 'displays': - $this->setOption($form_state['section'], $form_state['values'][$form_state['section']]); + $this->setOption($form_state['section'], $form_state->getValue($form_state['section'])); break; } } diff --git a/core/modules/views/src/Plugin/views/display/Page.php b/core/modules/views/src/Plugin/views/display/Page.php index 0ad1c8719b1..a2fab2391ed 100644 --- a/core/modules/views/src/Plugin/views/display/Page.php +++ b/core/modules/views/src/Plugin/views/display/Page.php @@ -383,11 +383,12 @@ class Page extends PathPluginBase { if ($form_state['section'] == 'menu') { $path = $this->getOption('path'); - if ($form_state['values']['menu']['type'] == 'normal' && strpos($path, '%') !== FALSE) { + $menu_type = $form_state->getValue(array('menu', 'type')); + if ($menu_type == 'normal' && strpos($path, '%') !== FALSE) { form_error($form['menu']['type'], $form_state, t('Views cannot create normal menu items for paths with a % in them.')); } - if ($form_state['values']['menu']['type'] == 'default tab' || $form_state['values']['menu']['type'] == 'tab') { + if ($menu_type == 'default tab' || $menu_type == 'tab') { $bits = explode('/', $path); $last = array_pop($bits); if ($last == '%') { @@ -395,7 +396,7 @@ class Page extends PathPluginBase { } } - if ($form_state['values']['menu']['type'] != 'none' && empty($form_state['values']['menu']['title'])) { + if ($menu_type != 'none' && $form_state->isValueEmpty(array('menu', 'title'))) { form_error($form['menu']['title'], $form_state, t('Title is required for this menu type.')); } } @@ -409,14 +410,14 @@ class Page extends PathPluginBase { switch ($form_state['section']) { case 'menu': - $this->setOption('menu', $form_state['values']['menu']); + $this->setOption('menu', $form_state->getValue('menu')); // send ajax form to options page if we use it. - if ($form_state['values']['menu']['type'] == 'default tab') { + if ($form_state->getValue(array('menu', 'type')) == 'default tab') { $form_state['view']->addFormToStack('display', $this->display['id'], 'tab_options'); } break; case 'tab_options': - $this->setOption('tab_options', $form_state['values']['tab_options']); + $this->setOption('tab_options', $form_state->getValue('tab_options')); break; } } diff --git a/core/modules/views/src/Plugin/views/display/PathPluginBase.php b/core/modules/views/src/Plugin/views/display/PathPluginBase.php index 14169db5b34..0f64d36f51f 100644 --- a/core/modules/views/src/Plugin/views/display/PathPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/PathPluginBase.php @@ -404,13 +404,13 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter parent::validateOptionsForm($form, $form_state); if ($form_state['section'] == 'path') { - $errors = $this->validatePath($form_state['values']['path']); + $errors = $this->validatePath($form_state->getValue('path')); foreach ($errors as $error) { $form_state->setError($form['path'], $error); } // Automatically remove '/' and trailing whitespace from path. - $form_state['values']['path'] = trim($form_state['values']['path'], '/ '); + $form_state->setValue('path', trim($form_state->getValue('path'), '/ ')); } } @@ -421,7 +421,7 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter parent::submitOptionsForm($form, $form_state); if ($form_state['section'] == 'path') { - $this->setOption('path', $form_state['values']['path']); + $this->setOption('path', $form_state->getValue('path')); } } diff --git a/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php index 62e80890a8d..8fb09e0484d 100644 --- a/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php +++ b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php @@ -294,7 +294,7 @@ abstract class ExposedFormPluginBase extends PluginBase { * $view->exposed_raw_input */ public function exposedFormSubmit(&$form, FormStateInterface $form_state, &$exclude) { - if (!empty($form_state['values']['op']) && $form_state['values']['op'] == $this->options['reset_button_label']) { + if (!$form_state->isValueEmpty('op') && $form_state->getValue('op') == $this->options['reset_button_label']) { $this->resetForm($form, $form_state); } if (isset($form_state['pager_plugin'])) { @@ -325,7 +325,7 @@ abstract class ExposedFormPluginBase extends PluginBase { $this->view->exposed_data = array(); } - $form_state['values'] = array(); + $form_state['redirect'] = current_path(); } } diff --git a/core/modules/views/src/Plugin/views/exposed_form/InputRequired.php b/core/modules/views/src/Plugin/views/exposed_form/InputRequired.php index af186179d63..4fb14f0c8f5 100644 --- a/core/modules/views/src/Plugin/views/exposed_form/InputRequired.php +++ b/core/modules/views/src/Plugin/views/exposed_form/InputRequired.php @@ -45,8 +45,9 @@ class InputRequired extends ExposedFormPluginBase { } public function submitOptionsForm(&$form, FormStateInterface $form_state) { - $form_state['values']['exposed_form_options']['text_input_required_format'] = $form_state['values']['exposed_form_options']['text_input_required']['format']; - $form_state['values']['exposed_form_options']['text_input_required'] = $form_state['values']['exposed_form_options']['text_input_required']['value']; + $exposed_form_options = $form_state->getValue('exposed_form_options'); + $form_state->setValue(array('exposed_form_options', 'text_input_required_format'), $exposed_form_options['text_input_required']['format']); + $form_state->setValue(array('exposed_form_options', 'text_input_required'), $exposed_form_options['text_input_required']['value']); parent::submitOptionsForm($form, $form_state); } diff --git a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php index ab7b97cd07f..d4e04f943ed 100644 --- a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php @@ -484,7 +484,7 @@ abstract class FieldPluginBase extends HandlerBase { * Performs some cleanup tasks on the options array before saving it. */ public function submitOptionsForm(&$form, FormStateInterface $form_state) { - $options = &$form_state['values']['options']; + $options = &$form_state->getValue('options'); $types = array('element_type', 'element_label_type', 'element_wrapper_type'); $classes = array_combine(array('element_class', 'element_label_class', 'element_wrapper_class'), $types); diff --git a/core/modules/views/src/Plugin/views/field/Serialized.php b/core/modules/views/src/Plugin/views/field/Serialized.php index 5d8c27b867c..c9d0dd2361b 100644 --- a/core/modules/views/src/Plugin/views/field/Serialized.php +++ b/core/modules/views/src/Plugin/views/field/Serialized.php @@ -56,7 +56,7 @@ class Serialized extends FieldPluginBase { public function validateOptionsForm(&$form, FormStateInterface $form_state) { // Require a key if the format is key. - if ($form_state['values']['options']['format'] == 'key' && $form_state['values']['options']['key'] == '') { + if ($form_state->getValue(array('options', 'format')) == 'key' && $form_state->getValue(array('options', 'key')) == '') { form_error($form['key'], $form_state, t('You have to enter a key if you want to display a key of the data.')); } } diff --git a/core/modules/views/src/Plugin/views/filter/BooleanOperator.php b/core/modules/views/src/Plugin/views/filter/BooleanOperator.php index e0d2ed46b7a..c635eb6f795 100644 --- a/core/modules/views/src/Plugin/views/filter/BooleanOperator.php +++ b/core/modules/views/src/Plugin/views/filter/BooleanOperator.php @@ -164,7 +164,7 @@ class BooleanOperator extends FilterPluginBase { } protected function valueValidate($form, FormStateInterface $form_state) { - if (isset($form_state['values']['options']['value']) && $form_state['values']['options']['value'] == 'All' && !empty($form_state['values']['options']['expose']['required'])) { + if ($form_state->getValue(array('options', 'value')) == 'All' && !$form_state->isValueEmpty(array('options', 'expose', 'required'))) { form_set_error('value', $form_state, t('You must select a value unless this is an non-required exposed filter.')); } } diff --git a/core/modules/views/src/Plugin/views/filter/Date.php b/core/modules/views/src/Plugin/views/filter/Date.php index ead1f1d366a..c0e1b9adf1c 100644 --- a/core/modules/views/src/Plugin/views/filter/Date.php +++ b/core/modules/views/src/Plugin/views/filter/Date.php @@ -48,12 +48,12 @@ class Date extends Numeric { public function validateOptionsForm(&$form, FormStateInterface $form_state) { parent::validateOptionsForm($form, $form_state); - if (!empty($this->options['exposed']) && empty($form_state['values']['options']['expose']['required'])) { + if (!empty($this->options['exposed']) && $form_state->isValueEmpty(array('options', 'expose', 'required'))) { // Who cares what the value is if it's exposed and non-required. return; } - $this->validateValidTime($form['value'], $form_state, $form_state['values']['options']['operator'], $form_state['values']['options']['value']); + $this->validateValidTime($form['value'], $form_state, $form_state->getValue(array('options', 'operator')), $form_state->getValue(array('options', 'value'))); } public function validateExposed(&$form, FormStateInterface $form_state) { @@ -66,9 +66,9 @@ class Date extends Numeric { return; } - $value = &$form_state['values'][$this->options['expose']['identifier']]; + $value = &$form_state->getValue($this->options['expose']['identifier']); if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator_id'])) { - $operator = $form_state['values'][$this->options['expose']['operator_id']]; + $operator = &$form_state->getValue($this->options['expose']['operator_id']); } else { $operator = $this->operator; @@ -110,7 +110,7 @@ class Date extends Numeric { // $group['value'] array contains the type of filter (date or offset) // and therefore the number of items the comparission has to be done // against 'one' instead of 'zero'. - foreach ($form_state['values']['options']['group_info']['group_items'] as $id => $group) { + foreach ($form_state->getValue(array('options', 'group_info', 'group_items')) as $id => $group) { if (empty($group['remove'])) { // Check if the title is defined but value wasn't defined. if (!empty($group['title'])) { diff --git a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php index c92184e1a6c..3f5ecb9da22 100644 --- a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php +++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php @@ -253,8 +253,10 @@ abstract class FilterPluginBase extends HandlerBase { * Simple submit handler */ public function submitOptionsForm(&$form, FormStateInterface $form_state) { - unset($form_state['values']['expose_button']); // don't store this. - unset($form_state['values']['group_button']); // don't store this. + // Do not store these values. + $form_state->unsetValue('expose_button'); + $form_state->unsetValue('group_button'); + if (!$this->isAGroup()) { $this->operatorSubmit($form, $form_state); $this->valueSubmit($form, $form_state); @@ -612,15 +614,15 @@ abstract class FilterPluginBase extends HandlerBase { * Validate the options form. */ public function validateExposeForm($form, FormStateInterface $form_state) { - if (empty($form_state['values']['options']['expose']['identifier'])) { + $identifier = $form_state->getValue(array('options', 'expose', 'identifier')); + if (empty($identifier)) { form_error($form['expose']['identifier'], $form_state, t('The identifier is required if the filter is exposed.')); } - - if (!empty($form_state['values']['options']['expose']['identifier']) && $form_state['values']['options']['expose']['identifier'] == 'value') { + elseif ($identifier == 'value') { form_error($form['expose']['identifier'], $form_state, t('This identifier is not allowed.')); } - if (!$this->view->display_handler->isIdentifierUnique($form_state['id'], $form_state['values']['options']['expose']['identifier'])) { + if (!$this->view->display_handler->isIdentifierUnique($form_state['id'], $identifier)) { form_error($form['expose']['identifier'], $form_state, t('This identifier is used by another handler.')); } } @@ -629,24 +631,25 @@ abstract class FilterPluginBase extends HandlerBase { * Validate the build group options form. */ protected function buildGroupValidate($form, FormStateInterface $form_state) { - if (!empty($form_state['values']['options']['group_info'])) { - if (empty($form_state['values']['options']['group_info']['identifier'])) { + if (!$form_state->isValueEmpty(array('options', 'group_info'))) { + $identifier = $form_state->getValue(array('options', 'group_info', 'identifier')); + if (empty($identifier)) { form_error($form['group_info']['identifier'], $form_state, t('The identifier is required if the filter is exposed.')); } - if (!empty($form_state['values']['options']['group_info']['identifier']) && $form_state['values']['options']['group_info']['identifier'] == 'value') { + elseif ($identifier == 'value') { form_error($form['group_info']['identifier'], $form_state, t('This identifier is not allowed.')); } - if (!$this->view->display_handler->isIdentifierUnique($form_state['id'], $form_state['values']['options']['group_info']['identifier'])) { + if (!$this->view->display_handler->isIdentifierUnique($form_state['id'], $identifier)) { form_error($form['group_info']['identifier'], $form_state, t('This identifier is used by another handler.')); } } - if (!empty($form_state['values']['options']['group_info']['group_items'])) { + if ($group_items = $form_state->getValue(array('options', 'group_info', 'group_items'))) { $operators = $this->operators(); - foreach ($form_state['values']['options']['group_info']['group_items'] as $id => $group) { + foreach ($group_items as $id => $group) { if (empty($group['remove'])) { // Check if the title is defined but value wasn't defined. @@ -676,32 +679,33 @@ abstract class FilterPluginBase extends HandlerBase { */ protected function buildGroupSubmit($form, FormStateInterface $form_state) { $groups = array(); - uasort($form_state['values']['options']['group_info']['group_items'], array('Drupal\Component\Utility\SortArray', 'sortByWeightElement')); + $group_items = $form_state->getValue(array('options', 'group_info', 'group_items')); + uasort($group_items, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement')); // Filter out removed items. // Start from 1 to avoid problems with #default_value in the widget. $new_id = 1; $new_default = 'All'; - foreach ($form_state['values']['options']['group_info']['group_items'] as $id => $group) { + foreach ($group_items as $id => $group) { if (empty($group['remove'])) { // Don't store this. unset($group['remove']); unset($group['weight']); $groups[$new_id] = $group; - if ($form_state['values']['options']['group_info']['default_group'] === $id) { + if ($form_state->getValue(array('options', 'group_info', 'default_group')) == $id) { $new_default = $new_id; } } $new_id++; } if ($new_default != 'All') { - $form_state['values']['options']['group_info']['default_group'] = $new_default; + $form_state->setValue(array('options', 'group_info', 'default_group'), $new_default); } - $filter_default_multiple = array_filter($form_state['values']['options']['group_info']['default_group_multiple']); - $form_state['values']['options']['group_info']['default_group_multiple'] = $filter_default_multiple; + $filter_default_multiple = $form_state->getValue(array('options', 'group_info', 'default_group_multiple')); + $form_state->setValue(array('options', 'group_info', 'default_group_multiple'), array_filter($filter_default_multiple)); - $form_state['values']['options']['group_info']['group_items'] = $groups; + $form_state->setValue(array('options', 'group_info', 'group_items'), $groups); } /** @@ -951,7 +955,7 @@ abstract class FilterPluginBase extends HandlerBase { // After the general settings, comes a table with all the existent groups. $default_weight = 0; foreach ($this->options['group_info']['group_items'] as $item_id => $item) { - if (!empty($form_state['values']['options']['group_info']['group_items'][$item_id]['remove'])) { + if (!$form_state->isValueEmpty(array('options', 'group_info', 'group_items', $item_id, 'remove'))) { continue; } // Each rows contains three widgets: diff --git a/core/modules/views/src/Plugin/views/filter/InOperator.php b/core/modules/views/src/Plugin/views/filter/InOperator.php index f99041edb38..a06ebb2e3b2 100644 --- a/core/modules/views/src/Plugin/views/filter/InOperator.php +++ b/core/modules/views/src/Plugin/views/filter/InOperator.php @@ -306,7 +306,7 @@ class InOperator extends FilterPluginBase { // *only* a list of checkboxes that were set, and we can use that // instead. - $form_state['values']['options']['value'] = $form['value']['#value']; + $form_state->setValue(array('options', 'value'), $form['value']['#value']); } public function adminSummary() { diff --git a/core/modules/views/src/Plugin/views/pager/SqlBase.php b/core/modules/views/src/Plugin/views/pager/SqlBase.php index 3b6b8e5f7aa..1fe68bcec94 100644 --- a/core/modules/views/src/Plugin/views/pager/SqlBase.php +++ b/core/modules/views/src/Plugin/views/pager/SqlBase.php @@ -181,7 +181,7 @@ abstract class SqlBase extends PagerPluginBase { public function validateOptionsForm(&$form, FormStateInterface $form_state) { // Only accept integer values. $error = FALSE; - $exposed_options = $form_state['values']['pager_options']['expose']['items_per_page_options']; + $exposed_options = $form_state->getValue(array('pager_options', 'expose', 'items_per_page_options')); if (strpos($exposed_options, '.') !== FALSE) { $error = TRUE; } @@ -201,8 +201,8 @@ abstract class SqlBase extends PagerPluginBase { } // Make sure that the items_per_page is part of the expose settings. - if (!empty($form_state['values']['pager_options']['expose']['items_per_page']) && !empty($form_state['values']['pager_options']['items_per_page'])) { - $items_per_page = $form_state['values']['pager_options']['items_per_page']; + if (!$form_state->isValueEmpty(array('pager_options', 'expose', 'items_per_page')) && !$form_state->isValueEmpty(array('pager_options', 'items_per_page'))) { + $items_per_page = $form_state->getValue(array('pager_options', 'items_per_page')); if (array_search($items_per_page, $options) === FALSE) { form_set_error('pager_options][expose][items_per_page_options', $form_state, t("The <em>Exposed items per page</em> field's options must include the value from the <em>Items per page</em> field (@items_per_page).", array('@items_per_page' => $items_per_page)) @@ -369,8 +369,8 @@ abstract class SqlBase extends PagerPluginBase { } public function exposedFormValidate(&$form, FormStateInterface $form_state) { - if (!empty($form_state['values']['offset']) && trim($form_state['values']['offset'])) { - if (!is_numeric($form_state['values']['offset']) || $form_state['values']['offset'] < 0) { + if (!$form_state->isValueEmpty('offset') && trim($form_state->getValue('offset'))) { + if (!is_numeric($form_state->getValue('offset')) || $form_state->getValue('offset') < 0) { form_set_error('offset', $form_state, t('Offset must be an number greather or equal than 0.')); } } diff --git a/core/modules/views/src/Plugin/views/query/Sql.php b/core/modules/views/src/Plugin/views/query/Sql.php index 1cabb79c657..25b1a230e7c 100644 --- a/core/modules/views/src/Plugin/views/query/Sql.php +++ b/core/modules/views/src/Plugin/views/query/Sql.php @@ -243,7 +243,7 @@ class Sql extends QueryPluginBase { */ public function submitOptionsForm(&$form, FormStateInterface $form_state) { $element = array('#parents' => array('query', 'options', 'query_tags')); - $value = explode(',', NestedArray::getValue($form_state['values'], $element['#parents'])); + $value = explode(',', NestedArray::getValue($form_state->getValues(), $element['#parents'])); $value = array_filter(array_map('trim', $value)); form_set_value($element, $value, $form_state); } diff --git a/core/modules/views/src/Plugin/views/row/Fields.php b/core/modules/views/src/Plugin/views/row/Fields.php index 5851d4991fe..788219a4cd3 100644 --- a/core/modules/views/src/Plugin/views/row/Fields.php +++ b/core/modules/views/src/Plugin/views/row/Fields.php @@ -102,7 +102,8 @@ class Fields extends RowPluginBase { * There is no need for this function to actually store the data. */ public function submitOptionsForm(&$form, FormStateInterface $form_state) { - $form_state['values']['row_options']['inline'] = array_filter($form_state['values']['row_options']['inline']); + $inline = $form_state->getValue(array('row_options', 'inline')); + $form_state->setValue(array('row_options', 'inline'), array_filter($inline)); } } diff --git a/core/modules/views/src/Plugin/views/sort/SortPluginBase.php b/core/modules/views/src/Plugin/views/sort/SortPluginBase.php index cfe4d3fb2d9..5a01ad96008 100644 --- a/core/modules/views/src/Plugin/views/sort/SortPluginBase.php +++ b/core/modules/views/src/Plugin/views/sort/SortPluginBase.php @@ -157,7 +157,9 @@ abstract class SortPluginBase extends HandlerBase { * Simple submit handler */ public function submitOptionsForm(&$form, FormStateInterface $form_state) { - unset($form_state['values']['expose_button']); // don't store this. + // Do not store this values. + $form_state->unsetValue('expose_button'); + $this->sortSubmit($form, $form_state); if (!empty($this->options['exposed'])) { $this->submitExposeForm($form, $form_state); diff --git a/core/modules/views/src/Plugin/views/style/StylePluginBase.php b/core/modules/views/src/Plugin/views/style/StylePluginBase.php index 6bb8cb157ba..0cafc1d66ec 100644 --- a/core/modules/views/src/Plugin/views/style/StylePluginBase.php +++ b/core/modules/views/src/Plugin/views/style/StylePluginBase.php @@ -338,11 +338,12 @@ abstract class StylePluginBase extends PluginBase { public function validateOptionsForm(&$form, FormStateInterface $form_state) { // Don't run validation on style plugins without the grouping setting. - if (isset($form_state['values']['style_options']['grouping'])) { + if ($form_state->hasValue(array('style_options', 'grouping'))) { // Don't save grouping if no field is specified. - foreach ($form_state['values']['style_options']['grouping'] as $index => $grouping) { + $groupings = $form_state->getValue(array('style_options', 'grouping')); + foreach ($groupings as $index => $grouping) { if (empty($grouping['field'])) { - unset($form_state['values']['style_options']['grouping'][$index]); + $form_state->unsetValue(array('style_options', 'grouping', $index)); } } } diff --git a/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php b/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php index 4a6d31e4015..4ea360efd51 100644 --- a/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php +++ b/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php @@ -470,8 +470,8 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface { * this form element was actually submitted). In a simple case (assuming * #tree is TRUE throughout the form), if the select element is located in * $form['wrapper']['select'], so that the submitted form values would - * normally be found in $form_state['values']['wrapper']['select'], you would - * pass array('wrapper', 'select') for this parameter. + * normally be found in $form_state->getValue(array('wrapper', 'select')), + * you would pass array('wrapper', 'select') for this parameter. * @param $default_value * The default value to return if the #select element does not currently have * a proper value set based on the submitted input. @@ -492,10 +492,10 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface { // If there is a user-submitted value for this element that matches one of // the currently available options attached to it, use that. We need to check - // $form_state['input'] rather than $form_state['values'] here because the + // $form_state['input'] rather than $form_state->getValues() here because the // triggering element often has the #limit_validation_errors property set to // prevent unwanted errors elsewhere on the form. This means that the - // $form_state['values'] array won't be complete. We could make it complete + // $form_state->getValues() array won't be complete. We could make it complete // by adding each required part of the form to the #limit_validation_errors // property individually as the form is being built, but this is difficult to // do for a highly dynamic and extensible form. This method is much simpler. @@ -645,9 +645,9 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface { protected function instantiateView($form, FormStateInterface $form_state) { // Build the basic view properties and create the view. $values = array( - 'id' => $form_state['values']['id'], - 'label' => $form_state['values']['label'], - 'description' => $form_state['values']['description'], + 'id' => $form_state->getValue('id'), + 'label' => $form_state->getValue('label'), + 'description' => $form_state->getValue('description'), 'base_table' => $this->base_table, 'langcode' => language_default()->id, ); @@ -685,17 +685,17 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface { $display_options['default']['sorts'] += $this->defaultDisplaySorts($form, $form_state); // Display: Page - if (!empty($form_state['values']['page']['create'])) { + if (!$form_state->isValueEmpty(array('page', 'create'))) { $display_options['page'] = $this->pageDisplayOptions($form, $form_state); // Display: Feed (attached to the page) - if (!empty($form_state['values']['page']['feed'])) { + if (!$form_state->isValueEmpty(array('page', 'feed'))) { $display_options['feed'] = $this->pageFeedDisplayOptions($form, $form_state); } } // Display: Block - if (!empty($form_state['values']['block']['create'])) { + if (!$form_state->isValueEmpty(array('block', 'create'))) { $display_options['block'] = $this->blockDisplayOptions($form, $form_state); } @@ -859,7 +859,7 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface { protected function defaultDisplayFiltersUser(array $form, FormStateInterface $form_state) { $filters = array(); - if (!empty($form_state['values']['show']['type']) && $form_state['values']['show']['type'] != 'all') { + if (($type = $form_state->getValue(array('show', 'type'))) && $type != 'all') { $bundle_key = $this->entityType->getKey('bundle'); // Figure out the table where $bundle_key lives. It may not be the same as // the base table for the view; the taxonomy vocabulary machine_name, for @@ -882,11 +882,11 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface { $handler = $table_data[$bundle_key]['filter']['id']; $handler_definition = Views::pluginManager('filter')->getDefinition($handler); if ($handler == 'in_operator' || is_subclass_of($handler_definition['class'], 'Drupal\\views\\Plugin\\views\\filter\\InOperator')) { - $value = array($form_state['values']['show']['type'] => $form_state['values']['show']['type']); + $value = array($type => $type); } // Otherwise, use just a single value. else { - $value = $form_state['values']['show']['type']; + $value = $type; } $filters[$bundle_key] = array( @@ -946,8 +946,8 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface { // Don't add a sort if there is no form value or the user set the sort to // 'none'. - if (!empty($form_state['values']['show']['sort']) && $form_state['values']['show']['sort'] != 'none') { - list($column, $sort) = explode(':', $form_state['values']['show']['sort']); + if (($sort_type = $form_state->getValue(array('show', 'sort'))) && $sort_type != 'none') { + list($column, $sort) = explode(':', $sort_type); // Column either be a column-name or the table-columnn-ame. $column = explode('-', $column); if (count($column) > 1) { @@ -990,7 +990,7 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface { */ protected function pageDisplayOptions(array $form, FormStateInterface $form_state) { $display_options = array(); - $page = $form_state['values']['page']; + $page = $form_state->getValue('page'); $display_options['title'] = $page['title']; $display_options['path'] = $page['path']; $display_options['style'] = array('type' => $page['style']['style_plugin']); @@ -1036,7 +1036,7 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface { */ protected function blockDisplayOptions(array $form, FormStateInterface $form_state) { $display_options = array(); - $block = $form_state['values']['block']; + $block = $form_state->getValue('block'); $display_options['title'] = $block['title']; $display_options['style'] = array('type' => $block['style']['style_plugin']); $display_options['row'] = array('type' => isset($block['style']['row_plugin']) ? $block['style']['row_plugin'] : 'fields'); @@ -1060,9 +1060,9 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface { $display_options = array(); $display_options['pager']['type'] = 'some'; $display_options['style'] = array('type' => 'rss'); - $display_options['row'] = array('type' => $form_state['values']['page']['feed_properties']['row_plugin']); - $display_options['path'] = $form_state['values']['page']['feed_properties']['path']; - $display_options['title'] = $form_state['values']['page']['title']; + $display_options['row'] = array('type' => $form_state->getValue(array('page', 'feed_properties', 'row_plugin'))); + $display_options['path'] = $form_state->getValue(array('page', 'feed_properties', 'path')); + $display_options['title'] = $form_state->getValue(array('page', 'title')); $display_options['displays'] = array( 'default' => 'default', 'page_1' => 'page_1', @@ -1155,7 +1155,7 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface { protected function retrieveValidatedView(array $form, FormStateInterface $form_state, $unset = TRUE) { // @todo Figure out why all this hashing is done. Wouldn't it be easier to // store a single entry and that's it? - $key = hash('sha256', serialize($form_state['values'])); + $key = hash('sha256', serialize($form_state->getValues())); $view = (isset($this->validated_views[$key]) ? $this->validated_views[$key] : NULL); if ($unset) { unset($this->validated_views[$key]); @@ -1174,7 +1174,7 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface { * The validated view object. */ protected function setValidatedView(array $form, FormStateInterface $form_state, ViewUI $view) { - $key = hash('sha256', serialize($form_state['values'])); + $key = hash('sha256', serialize($form_state->getValues())); $this->validated_views[$key] = $view; } diff --git a/core/modules/views/src/Tests/Wizard/WizardPluginBaseUnitTest.php b/core/modules/views/src/Tests/Wizard/WizardPluginBaseUnitTest.php index 97807b28ca2..0304607029f 100644 --- a/core/modules/views/src/Tests/Wizard/WizardPluginBaseUnitTest.php +++ b/core/modules/views/src/Tests/Wizard/WizardPluginBaseUnitTest.php @@ -65,12 +65,12 @@ class WizardPluginBaseUnitTest extends ViewUnitTestBase { )); language_save($language); - $form_state['values'] = array( + $form_state->set('values', array( '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); diff --git a/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php index d81680e9317..3fda583d764 100644 --- a/core/modules/views/src/ViewExecutable.php +++ b/core/modules/views/src/ViewExecutable.php @@ -127,7 +127,7 @@ class ViewExecutable { // Exposed widget input /** - * All the form data from $form_state['values']. + * All the form data from $form_state->getValues(). * * @var array */ @@ -141,7 +141,7 @@ class ViewExecutable { public $exposed_input = array(); /** - * Exposed widget input directly from the $form_state['values']. + * Exposed widget input directly from the $form_state->getValues(). * * @var array */ diff --git a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display/DisplayTest.php b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display/DisplayTest.php index ca9b746793e..4f748839faf 100644 --- a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display/DisplayTest.php +++ b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display/DisplayTest.php @@ -96,10 +96,10 @@ class DisplayTest extends DisplayPluginBase { */ public function validateOptionsForm(&$form, FormStateInterface $form_state) { parent::validateOptionsForm($form, $form_state); - watchdog('views', $form_state['values']['test_option']); + watchdog('views', $form_state->getValue('test_option')); switch ($form_state['section']) { case 'test_option': - if (!trim($form_state['values']['test_option'])) { + if (!trim($form_state->getValue('test_option'))) { form_error($form['test_option'], $form_state, t('You cannot have an empty option.')); } break; @@ -113,7 +113,7 @@ class DisplayTest extends DisplayPluginBase { parent::submitOptionsForm($form, $form_state); switch ($form_state['section']) { case 'test_option': - $this->setOption('test_option', $form_state['values']['test_option']); + $this->setOption('test_option', $form_state->getValue('test_option')); break; } } diff --git a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display_extender/DisplayExtenderTest.php b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display_extender/DisplayExtenderTest.php index e7a35ea9f58..8c0061d42f1 100644 --- a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display_extender/DisplayExtenderTest.php +++ b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display_extender/DisplayExtenderTest.php @@ -82,7 +82,7 @@ class DisplayExtenderTest extends DisplayExtenderPluginBase { parent::submitOptionsForm($form, $form_state); switch ($form_state['section']) { case 'test_extender_test_option': - $this->displayHandler->setOption('test_extender_test_option', $form_state['values']['test_extender_test_option']); + $this->displayHandler->setOption('test_extender_test_option', $form_state->getValue('test_extender_test_option')); break; } } diff --git a/core/modules/views_ui/admin.inc b/core/modules/views_ui/admin.inc index fd9b1b1787a..5a017e419f0 100644 --- a/core/modules/views_ui/admin.inc +++ b/core/modules/views_ui/admin.inc @@ -69,7 +69,7 @@ function views_ui_add_ajax_trigger(&$wrapping_element, $trigger_key, $refresh_pa // triggering element only. We have to do this in #process since until the // form API has added the #parents property to the triggering element for // us, we don't have any (easy) way to find out where its submitted values - // will eventually appear in $form_state['values']. + // will eventually appear in $form_state->getValues(). '#process' => array_merge(array('views_ui_add_limited_validation'), element_info_property('submit', '#process', array())), // Add an after-build function that inserts a wrapper around the region of // the form that needs to be refreshed by AJAX (so that the AJAX system can diff --git a/core/modules/views_ui/src/Form/AdvancedSettingsForm.php b/core/modules/views_ui/src/Form/AdvancedSettingsForm.php index b84eb29b6be..56254a25071 100644 --- a/core/modules/views_ui/src/Form/AdvancedSettingsForm.php +++ b/core/modules/views_ui/src/Form/AdvancedSettingsForm.php @@ -93,10 +93,10 @@ class AdvancedSettingsForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('views.settings') - ->set('skip_cache', $form_state['values']['skip_cache']) - ->set('sql_signature', $form_state['values']['sql_signature']) - ->set('no_javascript', $form_state['values']['no_javascript']) - ->set('display_extenders', isset($form_state['values']['display_extenders']) ? $form_state['values']['display_extenders'] : array()) + ->set('skip_cache', $form_state->getValue('skip_cache')) + ->set('sql_signature', $form_state->getValue('sql_signature')) + ->set('no_javascript', $form_state->getValue('no_javascript')) + ->set('display_extenders', $form_state->getValue('display_extenders', array())) ->save(); parent::submitForm($form, $form_state); diff --git a/core/modules/views_ui/src/Form/Ajax/ConfigHandler.php b/core/modules/views_ui/src/Form/Ajax/ConfigHandler.php index 066efe7899d..9c100bc6de6 100644 --- a/core/modules/views_ui/src/Form/Ajax/ConfigHandler.php +++ b/core/modules/views_ui/src/Form/Ajax/ConfigHandler.php @@ -233,7 +233,7 @@ class ConfigHandler extends ViewsFormBase { // Add the incoming options to existing options because items using // the extra form may not have everything in the form here. - $options = $form_state['values']['options'] + $form_state['handler']->options; + $options = $form_state->getValue('options') + $form_state['handler']->options; // This unpacks only options that are in the definition, ensuring random // extra stuff on the form is not sent through. diff --git a/core/modules/views_ui/src/Form/Ajax/ConfigHandlerExtra.php b/core/modules/views_ui/src/Form/Ajax/ConfigHandlerExtra.php index 16bc2306365..17b501119f4 100644 --- a/core/modules/views_ui/src/Form/Ajax/ConfigHandlerExtra.php +++ b/core/modules/views_ui/src/Form/Ajax/ConfigHandlerExtra.php @@ -106,7 +106,7 @@ class ConfigHandlerExtra extends ViewsFormBase { $item = $form_state['handler']->options; // Store the data we're given. - foreach ($form_state['values']['options'] as $key => $value) { + foreach ($form_state->getValue('options') as $key => $value) { $item[$key] = $value; } diff --git a/core/modules/views_ui/src/Form/Ajax/EditDetails.php b/core/modules/views_ui/src/Form/Ajax/EditDetails.php index f6684a2d1f6..2a085a0e211 100644 --- a/core/modules/views_ui/src/Form/Ajax/EditDetails.php +++ b/core/modules/views_ui/src/Form/Ajax/EditDetails.php @@ -76,7 +76,7 @@ class EditDetails extends ViewsFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $view = $form_state['view']; - foreach ($form_state['values'] as $key => $value) { + foreach ($form_state->getValues() as $key => $value) { // Only save values onto the view if they're actual view properties // (as opposed to 'op' or 'form_build_id'). if (isset($form['details'][$key])) { diff --git a/core/modules/views_ui/src/Form/Ajax/Rearrange.php b/core/modules/views_ui/src/Form/Ajax/Rearrange.php index 5e3d7090e63..72b4395d6be 100644 --- a/core/modules/views_ui/src/Form/Ajax/Rearrange.php +++ b/core/modules/views_ui/src/Form/Ajax/Rearrange.php @@ -143,7 +143,7 @@ class Rearrange extends ViewsFormBase { $new_fields = $order = array(); // Make an array with the weights - foreach ($form_state['values']['fields'] as $field => $info) { + foreach ($form_state->getValue('fields') as $field => $info) { // add each value that is a field with a weight to our list, but only if // it has had its 'removed' checkbox checked. if (is_array($info) && isset($info['weight']) && empty($info['removed'])) { diff --git a/core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php b/core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php index 54ba06e86a6..eb77664c95f 100644 --- a/core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php +++ b/core/modules/views_ui/src/Form/Ajax/RearrangeFilter.php @@ -226,12 +226,12 @@ class RearrangeFilter extends ViewsFormBase { $old_fields = $display->getOption($types['filter']['plural']); } - $groups = $form_state['values']['filter_groups']; + $groups = $form_state->getValue('filter_groups'); // Whatever button was clicked, re-calculate field information. $new_fields = $order = array(); // Make an array with the weights - foreach ($form_state['values']['filters'] as $field => $info) { + foreach ($form_state->getValue('filters') as $field => $info) { // add each value that is a field with a weight to our list, but only if // it has had its 'removed' checkbox checked. if (is_array($info) && empty($info['removed'])) { diff --git a/core/modules/views_ui/src/Form/BasicSettingsForm.php b/core/modules/views_ui/src/Form/BasicSettingsForm.php index 6b15d791295..621f1a429db 100644 --- a/core/modules/views_ui/src/Form/BasicSettingsForm.php +++ b/core/modules/views_ui/src/Form/BasicSettingsForm.php @@ -129,16 +129,16 @@ class BasicSettingsForm extends ConfigFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('views.settings') - ->set('ui.show.master_display', $form_state['values']['ui_show_master_display']) - ->set('ui.show.advanced_column', $form_state['values']['ui_show_advanced_column']) - ->set('ui.show.display_embed', $form_state['values']['ui_show_display_embed']) - ->set('ui.exposed_filter_any_label', $form_state['values']['ui_exposed_filter_any_label']) - ->set('ui.always_live_preview', $form_state['values']['ui_always_live_preview']) - ->set('ui.show.preview_information', $form_state['values']['ui_show_preview_information']) - ->set('ui.show.sql_query.where', $form_state['values']['ui_show_sql_query_where']) - ->set('ui.show.sql_query.enabled', $form_state['values']['ui_show_sql_query_enabled']) - ->set('ui.show.performance_statistics', $form_state['values']['ui_show_performance_statistics']) - ->set('ui.show.additional_queries', $form_state['values']['ui_show_additional_queries']) + ->set('ui.show.master_display', $form_state->getValue('ui_show_master_display')) + ->set('ui.show.advanced_column', $form_state->getValue('ui_show_advanced_column')) + ->set('ui.show.display_embed', $form_state->getValue('ui_show_display_embed')) + ->set('ui.exposed_filter_any_label', $form_state->getValue('ui_exposed_filter_any_label')) + ->set('ui.always_live_preview', $form_state->getValue('ui_always_live_preview')) + ->set('ui.show.preview_information', $form_state->getValue('ui_show_preview_information')) + ->set('ui.show.sql_query.where', $form_state->getValue('ui_show_sql_query_where')) + ->set('ui.show.sql_query.enabled', $form_state->getValue('ui_show_sql_query_enabled')) + ->set('ui.show.performance_statistics', $form_state->getValue('ui_show_performance_statistics')) + ->set('ui.show.additional_queries', $form_state->getValue('ui_show_additional_queries')) ->save(); parent::submitForm($form, $form_state); diff --git a/core/modules/views_ui/src/ViewAddForm.php b/core/modules/views_ui/src/ViewAddForm.php index dd4cd1b7869..8717ff93a10 100644 --- a/core/modules/views_ui/src/ViewAddForm.php +++ b/core/modules/views_ui/src/ViewAddForm.php @@ -165,7 +165,7 @@ class ViewAddForm extends ViewFormBase { * {@inheritdoc} */ public function validate(array $form, FormStateInterface $form_state) { - $wizard_type = $form_state['values']['show']['wizard_key']; + $wizard_type = $form_state->getValue(array('show', 'wizard_key')); $wizard_instance = $this->wizardManager->createInstance($wizard_type); $form_state['wizard'] = $wizard_instance->getPluginDefinition(); $form_state['wizard_instance'] = $wizard_instance; diff --git a/core/modules/views_ui/src/ViewDuplicateForm.php b/core/modules/views_ui/src/ViewDuplicateForm.php index fb2f2df7543..e817e36263b 100644 --- a/core/modules/views_ui/src/ViewDuplicateForm.php +++ b/core/modules/views_ui/src/ViewDuplicateForm.php @@ -71,7 +71,7 @@ class ViewDuplicateForm extends ViewFormBase { public function submit(array $form, FormStateInterface $form_state) { $original = parent::submit($form, $form_state); $this->entity = $original->createDuplicate(); - $this->entity->set('id', $form_state['values']['id']); + $this->entity->set('id', $form_state->getValue('id')); $this->entity->save(); // Redirect the user to the view admin form. diff --git a/core/modules/views_ui/src/ViewPreviewForm.php b/core/modules/views_ui/src/ViewPreviewForm.php index 02a0225e093..45096751134 100644 --- a/core/modules/views_ui/src/ViewPreviewForm.php +++ b/core/modules/views_ui/src/ViewPreviewForm.php @@ -79,8 +79,8 @@ class ViewPreviewForm extends ViewFormBase { ); $args = array(); - if (!empty($form_state['values']['view_args'])) { - $args = explode('/', $form_state['values']['view_args']); + if (!$form_state->isValueEmpty('view_args')) { + $args = explode('/', $form_state->getValue('view_args')); } if (!empty($form_state['show_preview']) || !empty($form_state['input']['js'])) { diff --git a/core/modules/views_ui/src/ViewUI.php b/core/modules/views_ui/src/ViewUI.php index 9ac7d46d0c8..64f8cae3a27 100644 --- a/core/modules/views_ui/src/ViewUI.php +++ b/core/modules/views_ui/src/ViewUI.php @@ -401,12 +401,13 @@ class ViewUI implements ViewStorageInterface { */ public function getOverrideValues($form, FormStateInterface $form_state) { // Make sure the dropdown exists in the first place. - if (isset($form_state['values']['override']['dropdown'])) { + if ($form_state->hasValue(array('override', 'dropdown'))) { // #default_value is used to determine whether it was the default value or not. // So the available options are: $display, 'default' and 'default_revert', not 'defaults'. $was_defaulted = ($form['override']['dropdown']['#default_value'] === 'defaults'); - $is_defaulted = ($form_state['values']['override']['dropdown'] === 'default'); - $revert = ($form_state['values']['override']['dropdown'] === 'default_revert'); + $dropdown = $form_state->getValue(array('override', 'dropdown')); + $is_defaulted = ($dropdown === 'default'); + $revert = ($dropdown === 'default_revert'); if ($was_defaulted !== $is_defaulted && isset($form['#section'])) { // We're changing which display these values apply to. @@ -499,9 +500,9 @@ class ViewUI implements ViewStorageInterface { $display->setOverride($section); } - if (!empty($form_state['values']['name']) && is_array($form_state['values']['name'])) { + if (!$form_state->isValueEmpty('name') && is_array($form_state->getValue('name'))) { // Loop through each of the items that were checked and add them to the view. - foreach (array_keys(array_filter($form_state['values']['name'])) as $field) { + foreach (array_keys(array_filter($form_state->getValue('name'))) as $field) { list($table, $field) = explode('.', $field, 2); if ($cut = strpos($field, '$')) { diff --git a/core/tests/Drupal/Tests/Core/Display/DisplayVariantTest.php b/core/tests/Drupal/Tests/Core/Display/DisplayVariantTest.php index c13a3828ccd..4f51351279f 100644 --- a/core/tests/Drupal/Tests/Core/Display/DisplayVariantTest.php +++ b/core/tests/Drupal/Tests/Core/Display/DisplayVariantTest.php @@ -144,7 +144,7 @@ class DisplayVariantTest extends UnitTestCase { $form = array(); $label = $this->randomMachineName(); $form_state = new FormState(); - $form_state['values']['label'] = $label; + $form_state->setValue('label', $label); $display_variant->submitConfigurationForm($form, $form_state); $this->assertSame($label, $display_variant->label()); } diff --git a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php index e071ca4dbf9..0f9e15d7b5b 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php @@ -128,7 +128,6 @@ class FormBuilderTest extends FormTestBase { $form_state = new FormState(); try { - $form_state['values'] = array(); $form_state['input']['form_id'] = $form_id; $this->simulateFormSubmission($form_id, $form_arg, $form_state, FALSE); $this->fail('TestFormBuilder::sendResponse() was not triggered.'); @@ -182,7 +181,6 @@ class FormBuilderTest extends FormTestBase { $form_state = new FormState(); try { - $form_state['values'] = array(); $form_state['input']['form_id'] = $form_id; $this->simulateFormSubmission($form_id, $form_arg, $form_state, FALSE); $this->fail('TestFormBuilder::sendResponse() was not triggered.'); diff --git a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php index 41882304cba..4cd45e770f7 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php @@ -175,4 +175,143 @@ class FormStateTest extends UnitTestCase { $this->assertSame($expected, $form_state->getValues()); } + /** + * @covers ::getValue + * + * @dataProvider providerTestGetValue + */ + public function testGetValue($key, $expected, $default = NULL) { + $form_state = new FormState(array('values' => array( + 'foo' => 'one', + 'bar' => array( + 'baz' => 'two', + ), + ))); + $this->assertSame($expected, $form_state->getValue($key, $default)); + } + + public function providerTestGetValue() { + $data = array(); + $data[] = array( + 'foo', 'one', + ); + $data[] = array( + array('bar', 'baz'), 'two', + ); + $data[] = array( + array('foo', 'bar', 'baz'), NULL, + ); + $data[] = array( + 'baz', 'baz', 'baz', + ); + return $data; + } + + /** + * @covers ::setValue + * + * @dataProvider providerTestSetValue + */ + public function testSetValue($key, $value, $expected) { + $form_state = new FormState(array('values' => array('bar' => 'wrong'))); + $form_state->setValue($key, $value); + $this->assertSame($expected, $form_state->getValues()); + } + + public function providerTestSetValue() { + $data = array(); + $data[] = array( + 'foo', 'one', array('bar' => 'wrong', 'foo' => 'one'), + ); + $data[] = array( + array('bar', 'baz'), 'two', array('bar' => array('baz' => 'two')), + ); + $data[] = array( + array('foo', 'bar', 'baz'), NULL, array('bar' => 'wrong', 'foo' => array('bar' => array('baz' => NULL))), + ); + return $data; + } + + /** + * @covers ::hasValue + * + * @dataProvider providerTestHasValue + */ + public function testHasValue($key, $expected) { + $form_state = new FormState(array('values' => array( + 'foo' => 'one', + 'bar' => array( + 'baz' => 'two', + ), + 'true' => TRUE, + 'false' => FALSE, + 'null' => NULL, + ))); + $this->assertSame($expected, $form_state->hasValue($key)); + } + + public function providerTestHasValue() { + $data = array(); + $data[] = array( + 'foo', TRUE, + ); + $data[] = array( + array('bar', 'baz'), TRUE, + ); + $data[] = array( + array('foo', 'bar', 'baz'), FALSE, + ); + $data[] = array( + 'true', TRUE, + ); + $data[] = array( + 'false', TRUE, + ); + $data[] = array( + 'null', FALSE, + ); + return $data; + } + + /** + * @covers ::isValueEmpty + * + * @dataProvider providerTestIsValueEmpty + */ + public function testIsValueEmpty($key, $expected) { + $form_state = new FormState(array('values' => array( + 'foo' => 'one', + 'bar' => array( + 'baz' => 'two', + ), + 'true' => TRUE, + 'false' => FALSE, + 'null' => NULL, + ))); + $this->assertSame($expected, $form_state->isValueEmpty($key)); + } + + public function providerTestIsValueEmpty() { + $data = array(); + $data[] = array( + 'foo', FALSE, + ); + $data[] = array( + array('bar', 'baz'), FALSE, + ); + $data[] = array( + array('foo', 'bar', 'baz'), TRUE, + ); + $data[] = array( + 'true', FALSE, + ); + $data[] = array( + 'false', TRUE, + ); + $data[] = array( + 'null', TRUE, + ); + return $data; + } + } diff --git a/core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php b/core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php index 52b017d4f08..7c9969905a5 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php @@ -107,7 +107,7 @@ class FormValidatorTest extends UnitTestCase { $form_state->expects($this->once()) ->method('setErrorByName') ->with('form_token', 'The form has become outdated. Copy any unsaved work in the form below and then <a href="/test/example?foo=bar">reload this page</a>.'); - $form_state['values']['form_token'] = 'some_random_token'; + $form_state->setValue('form_token', 'some_random_token'); $form_validator->validateForm('test_form_id', $form, $form_state); $this->assertTrue($form_state['validation_complete']); } @@ -137,7 +137,7 @@ class FormValidatorTest extends UnitTestCase { ->getMock(); $form_state->expects($this->never()) ->method('setErrorByName'); - $form_state['values']['form_token'] = 'some_random_token'; + $form_state->setValue('form_token', 'some_random_token'); $form_validator->validateForm('test_form_id', $form, $form_state); $this->assertTrue($form_state['validation_complete']); } @@ -178,14 +178,15 @@ class FormValidatorTest extends UnitTestCase { ->setMethods(NULL) ->getMock(); + $triggering_element['#limit_validation_errors'] = $sections; $form = array(); - $form_state = new FormState(); - $form_state['triggering_element'] = $triggering_element; - $form_state['triggering_element']['#limit_validation_errors'] = $sections; + $form_state = new FormState(array( + 'values' => $values, + 'triggering_element' => $triggering_element, + )); - $form_state['values'] = $values; $form_validator->validateForm('test_form_id', $form, $form_state); - $this->assertSame($expected, $form_state['values']); + $this->assertSame($expected, $form_state->getValues()); } public function providerTestHandleErrorsWithLimitedValidation() { @@ -405,7 +406,6 @@ class FormValidatorTest extends UnitTestCase { $form_state->expects($this->once()) ->method('setError') ->with($this->isType('array'), $expected_message); - $form_state['values'] = array(); $form_validator->validateForm('test_form_id', $form, $form_state); } |