Commit de5fe262 authored by webchick's avatar webchick

Issue #2318087 by tim.plunkett: Replace ['input'] with FormState::getUserInput().

parent 0c8bbf1b
......@@ -269,7 +269,7 @@ function form_type_image_button_value($form, $input, FormStateInterface $form_st
// X and one for the Y coordinates on which the user clicked the
// button. We'll find this element in the #post data, and search
// in the same spot for its name, with '_x'.
$input = $form_state['input'];
$input = $form_state->getUserInput();
foreach (explode('[', $form['#name']) as $element_name) {
// chop off the ] that may exist.
if (substr($element_name, -1) == ']') {
......
......@@ -187,9 +187,11 @@ public function buildForm($form_id, FormStateInterface &$form_state) {
// Ensure the form ID is prepared.
$form_id = $this->getFormId($form_id, $form_state);
if (!isset($form_state['input'])) {
$input = $form_state->getUserInput();
if (!isset($input)) {
$request = $this->requestStack->getCurrentRequest();
$form_state->set('input', $form_state['method'] == 'get' ? $request->query->all() : $request->request->all());
$input = $form_state['method'] == 'get' ? $request->query->all() : $request->request->all();
$form_state->setUserInput($input);
}
if (isset($_SESSION['batch_form_state'])) {
......@@ -205,9 +207,9 @@ public function buildForm($form_id, FormStateInterface &$form_state) {
// the form to proceed. In addition, if there is stored form_state data from
// a previous step, we'll retrieve it so it can be passed on to the form
// processing code.
$check_cache = isset($form_state['input']['form_id']) && $form_state['input']['form_id'] == $form_id && !empty($form_state['input']['form_build_id']);
$check_cache = isset($input['form_id']) && $input['form_id'] == $form_id && !empty($input['form_build_id']);
if ($check_cache) {
$form = $this->getCache($form_state['input']['form_build_id'], $form_state);
$form = $this->getCache($input['form_build_id'], $form_state);
}
// If the previous bit of code didn't result in a populated $form object, we
......@@ -393,11 +395,11 @@ public function submitForm($form_arg, FormStateInterface &$form_state) {
$form_state->addBuildInfo('args', array_values($args));
}
// Populate $form_state['input'] with the submitted values before retrieving
// Populate FormState::$input with the submitted values before retrieving
// 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->getValues());
$form_state->setUserInput($form_state->getValues());
$form_state->set('programmed', TRUE);
......@@ -462,7 +464,7 @@ public function processForm($form_id, &$form, FormStateInterface &$form_state) {
// With GET, these forms are always submitted if requested.
if ($form_state['method'] == 'get' && !empty($form_state['always_process'])) {
$input = $form_state->get('input');
$input = $form_state->getUserInput();
if (!isset($input['form_build_id'])) {
$input['form_build_id'] = $form['#build_id'];
}
......@@ -472,7 +474,7 @@ public function processForm($form_id, &$form, FormStateInterface &$form_state) {
if (!isset($input['form_token']) && isset($form['#token'])) {
$input['form_token'] = $this->csrfToken->get($form['#token']);
}
$form_state->set('input', $input);
$form_state->setUserInput($input);
}
// self::doBuildForm() finishes building the form by calling element
......@@ -737,7 +739,8 @@ public function doBuildForm($form_id, &$element, FormStateInterface &$form_state
// Set a flag if we have a correct form submission. This is always TRUE
// for programmed forms coming from self::submitForm(), or if the form_id
// coming from the POST data is set and matches the current form_id.
if ($form_state['programmed'] || (!empty($form_state['input']) && (isset($form_state['input']['form_id']) && ($form_state['input']['form_id'] == $form_id)))) {
$input = $form_state->getUserInput();
if ($form_state['programmed'] || (!empty($input) && (isset($input['form_id']) && ($input['form_id'] == $form_id)))) {
$form_state->set('process_input', TRUE);
}
else {
......@@ -962,20 +965,20 @@ protected function handleInputElement($form_id, &$element, FormStateInterface &$
// Get the input for the current element. NULL values in the input need
// to be explicitly distinguished from missing input. (see below)
$input_exists = NULL;
$input = NestedArray::getValue($form_state['input'], $element['#parents'], $input_exists);
$input = NestedArray::getValue($form_state->getUserInput(), $element['#parents'], $input_exists);
// For browser-submitted forms, the submitted values do not contain
// values for certain elements (empty multiple select, unchecked
// checkbox). During initial form processing, we add explicit NULL
// values for such elements in $form_state['input']. When rebuilding the
// values for such elements in FormState::$input. When rebuilding the
// form, we can distinguish elements having NULL input from elements
// that were not part of the initially submitted form and can therefore
// use default values for the latter, if required. Programmatically
// submitted forms can submit explicit NULL values when calling
// self::submitForm() so we do not modify $form_state['input'] for them.
// self::submitForm() so we do not modify FormState::$input for them.
if (!$input_exists && !$form_state['rebuild'] && !$form_state['programmed']) {
// Add the necessary parent keys to $form_state['input'] and sets the
// Add the necessary parent keys to FormState::$input and sets the
// element's input value to NULL.
NestedArray::setValue($form_state['input'], $element['#parents'], NULL);
NestedArray::setValue($form_state->getUserInput(), $element['#parents'], NULL);
$input_exists = TRUE;
}
// If we have input for the current element, assign it to the #value
......@@ -1054,8 +1057,9 @@ protected function handleInputElement($form_id, &$element, FormStateInterface &$
* // buttons all named 'op', and only differing in their value.
*/
protected function elementTriggeredScriptedSubmission($element, FormStateInterface &$form_state) {
if (!empty($form_state['input']['_triggering_element_name']) && $element['#name'] == $form_state['input']['_triggering_element_name']) {
if (empty($form_state['input']['_triggering_element_value']) || $form_state['input']['_triggering_element_value'] == $element['#value']) {
$input = $form_state->getUserInput();
if (!empty($input['_triggering_element_name']) && $element['#name'] == $input['_triggering_element_name']) {
if (empty($input['_triggering_element_value']) || $input['_triggering_element_value'] == $element['#value']) {
return TRUE;
}
}
......@@ -1088,7 +1092,8 @@ protected function buttonWasClicked($element, FormStateInterface &$form_state) {
// return value is used to determine which was clicked. This ONLY works as
// long as $form['#name'] puts the value at the top level of the tree of
// \Drupal::request()->request data.
if (isset($form_state['input'][$element['#name']]) && $form_state['input'][$element['#name']] == $element['#value']) {
$input = $form_state->getUserInput();
if (isset($input[$element['#name']]) && $input[$element['#name']] == $element['#value']) {
return TRUE;
}
// When image buttons are clicked, browsers do NOT pass the form element
......
......@@ -564,6 +564,21 @@ public function addBuildInfo($property, $value) {
return $this;
}
/**
* {@inheritdoc}
*/
public function &getUserInput() {
return $this->input;
}
/**
* {@inheritdoc}
*/
public function setUserInput(array $user_input) {
$this->input = $user_input;
return $this;
}
/**
* {@inheritdoc}
*/
......
......@@ -175,6 +175,28 @@ public function has($property);
*/
public function addBuildInfo($property, $value);
/**
* Returns the form values as they were submitted by the user.
*
* These are raw and unvalidated, so should not be used without a thorough
* understanding of security implications. In almost all cases, code should
* use self::getValues() and self::getValue() exclusively.
*
* @return array
* An associative array of values submitted to the form.
*/
public function &getUserInput();
/**
* Sets the form values as though they were submitted by a user.
*
* @param array $user_input
* An associative array of raw and unvalidated values.
*
* @return $this
*/
public function setUserInput(array $user_input);
/**
* Returns the submitted and sanitized form values.
*
......
......@@ -43,22 +43,23 @@ public function buildForm(array $form, FormStateInterface $form_state) {
// Note: The installer even executes this form if there is a valid database
// connection already, since the submit handler of this form is responsible
// for writing all $settings to settings.php (not limited to $databases).
if (!isset($form_state['input']['driver']) && $database = Database::getConnectionInfo()) {
$form_state['input']['driver'] = $database['default']['driver'];
$form_state['input'][$database['default']['driver']] = $database['default'];
$input = &$form_state->getUserInput();
if (!isset($input['driver']) && $database = Database::getConnectionInfo()) {
$input['driver'] = $database['default']['driver'];
$input[$database['default']['driver']] = $database['default'];
}
if (isset($form_state['input']['driver'])) {
$default_driver = $form_state['input']['driver'];
if (isset($input['driver'])) {
$default_driver = $input['driver'];
// In case of database connection info from settings.php, as well as for a
// programmed form submission (non-interactive installer), the table prefix
// information is usually normalized into an array already, but the form
// element only allows to configure one default prefix for all tables.
$prefix = &$form_state['input'][$default_driver]['prefix'];
$prefix = &$input[$default_driver]['prefix'];
if (isset($prefix) && is_array($prefix)) {
$prefix = $prefix['default'];
}
$default_options = $form_state['input'][$default_driver];
$default_options = $input[$default_driver];
}
// If there is no database information yet, suggest the first available driver
// as default value, so that its settings form is made visible via #states
......
......@@ -96,7 +96,8 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
public function submitForm(array &$form, FormStateInterface $form_state) {
// Save elements in the same order as defined in post rather than the form.
// This ensures parents are updated before their children, preventing orphans.
$order = array_flip(array_keys($form_state['input']['table']));
$user_input = $form_state->getUserInput();
$order = array_flip(array_keys($user_input['table']));
$form['table'] = array_merge($order, $form['table']);
foreach (Element::children($form['table']) as $key) {
......
......@@ -84,7 +84,7 @@ public function getConfirmText() {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$edit = $form_state['input'];
$edit = $form_state->getUserInput();
$form['comments'] = array(
'#prefix' => '<ul>',
......
......@@ -38,7 +38,8 @@ public function buildForm(array $form, FormStateInterface $form_state, FilterFor
// The default values are set directly from \Drupal::request()->request,
// provided by the editor plugin opening the dialog.
if (!isset($form_state['image_element'])) {
$form_state['image_element'] = isset($form_state['input']['editor_object']) ? $form_state['input']['editor_object'] : array();
$user_input = $form_state->getUserInput();
$form_state['image_element'] = isset($user_input['editor_object']) ? $user_input['editor_object'] : array();
}
$image_element = $form_state['image_element'];
......
......@@ -36,7 +36,8 @@ public function getFormId() {
public function buildForm(array $form, FormStateInterface $form_state, FilterFormat $filter_format = NULL) {
// The default values are set directly from \Drupal::request()->request,
// provided by the editor plugin opening the dialog.
$input = isset($form_state['input']['editor_object']) ? $form_state['input']['editor_object'] : array();
$user_input = $form_state->getUserInput();
$input = isset($user_input['editor_object']) ? $user_input['editor_object'] : array();
$form['#tree'] = TRUE;
$form['#attached']['library'][] = 'editor/drupal.editor.dialog';
......
......@@ -348,7 +348,8 @@ function field_config_import_steps_alter(&$sync_steps, ConfigImporter $config_im
function field_form_config_admin_import_form_alter(&$form, FormStateInterface $form_state) {
// Only display the message when there is a storage comparer available and the
// form is not submitted.
if (isset($form_state['storage_comparer']) && empty($form_state['input'])) {
$user_input = $form_state->getUserInput();
if (isset($form_state['storage_comparer']) && empty($user_input)) {
$field_storages = \Drupal\field\ConfigImporterFieldPurger::getFieldStoragesToPurge(
$form_state['storage_comparer']->getSourceStorage()->read('core.extension'),
$form_state['storage_comparer']->getChangelist('delete')
......
......@@ -1404,15 +1404,15 @@ function file_managed_file_submit($form, FormStateInterface $form_state) {
$element['#files'][$fid]->delete();
}
}
// Update both $form_state->getValues() and $form_state['input'] to reflect
// Update both $form_state->getValues() and FormState::$input to reflect
// that the file has been removed, so that the form is rebuilt correctly.
// $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()
// FormState::$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);
NestedArray::setValue($form_state['input'], $element['fids']['#parents'], implode(' ', $fids));
NestedArray::setValue($form_state->getUserInput(), $element['fids']['#parents'], implode(' ', $fids));
}
// Set the form to rebuild so that $form is correctly updated in response to
......
......@@ -487,12 +487,12 @@ protected static function getDescriptionFromElement($element) {
*/
public static function submit($form, FormStateInterface $form_state) {
// During the form rebuild, formElement() will create field item widget
// elements using re-indexed deltas, so clear out $form_state['input'] to
// elements using re-indexed deltas, so clear out FormState::$input to
// avoid a mismatch between old and new deltas. The rebuilt elements will
// have #default_value set appropriately for the current state of the field,
// so nothing is lost in doing this.
$parents = array_slice($form_state['triggering_element']['#parents'], 0, -2);
NestedArray::setValue($form_state['input'], $parents, NULL);
NestedArray::setValue($form_state->getUserInput(), $parents, NULL);
$button = $form_state['triggering_element'];
......
......@@ -54,6 +54,7 @@ public static function create(ContainerInterface $container) {
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$user_input = $form_state->getUserInput();
$form['#title'] = $this->t('Edit style %name', array('%name' => $this->entity->label()));
$form['#tree'] = TRUE;
$form['#attached']['css'][drupal_get_path('module', 'image') . '/css/image.admin.css'] = array();
......@@ -93,7 +94,7 @@ public function form(array $form, FormStateInterface $form_state) {
foreach ($this->entity->getEffects() as $effect) {
$key = $effect->getUuid();
$form['effects'][$key]['#attributes']['class'][] = 'draggable';
$form['effects'][$key]['#weight'] = isset($form_state['input']['effects']) ? $form_state['input']['effects'][$key]['weight'] : NULL;
$form['effects'][$key]['#weight'] = isset($user_input['effects']) ? $user_input['effects'][$key]['weight'] : NULL;
$form['effects'][$key]['effect'] = array(
'#tree' => FALSE,
'data' => array(
......@@ -149,7 +150,7 @@ public function form(array $form, FormStateInterface $form_state) {
}
$form['effects']['new'] = array(
'#tree' => FALSE,
'#weight' => isset($form_state['input']['weight']) ? $form_state['input']['weight'] : NULL,
'#weight' => isset($user_input['weight']) ? $user_input['weight'] : NULL,
'#attributes' => array('class' => array('draggable')),
);
$form['effects']['new']['effect'] = array(
......
......@@ -235,7 +235,7 @@ public static function validateRequiredFields($element, FormStateInterface $form
// If the image is not there, we do not check for empty values.
$parents = $element['#parents'];
$field = array_pop($parents);
$image_field = NestedArray::getValue($form_state['input'], $parents);
$image_field = NestedArray::getValue($form_state->getUserInput(), $parents);
// We check for the array key, so that it can be NULL (like if the user
// submits the form without using the "upload" button).
if (!array_key_exists($field, $image_field)) {
......
......@@ -357,7 +357,7 @@ protected function submitOverviewForm(array $complete_form, FormStateInterface $
// equally separated yet. Therefore, we use a $form_state key to point to
// the parents of the form section.
$parents = $form_state['menu_overview_form_parents'];
$input = NestedArray::getValue($form_state['input'], $parents);
$input = NestedArray::getValue($form_state->getUserInput(), $parents);
$form = &NestedArray::getValue($complete_form, $parents);
// When dealing with saving menu items, the order in which these items are
......
......@@ -38,7 +38,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
// Do not needlessly re-execute a full test discovery if the user input
// already contains an explicit list of test classes to run.
if (!empty($form_state['input']['tests'])) {
$user_input = $form_state->getUserInput();
if (!empty($user_input['tests'])) {
return $form;
}
......@@ -197,8 +198,9 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// 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 ($form_state->isValueEmpty('tests') && !empty($form_state['input']['tests'])) {
$form_state->setValue('tests', $form_state['input']['tests']);
$user_input = $form_state->getUserInput();
if ($form_state->isValueEmpty('tests') && !empty($user_input['tests'])) {
$form_state->setValue('tests', $user_input['tests']);
}
$tests_list = array();
......
......@@ -126,7 +126,7 @@ protected function getForm(Request $request) {
// The form needs to be processed; prepare for that by setting a few internal
// variables.
$form_state['input'] = $request->request->all();
$form_state->setUserInput($request->request->all());
$form_id = $form['#form_id'];
return array($form, $form_state, $form_id, $form_build_id);
......
......@@ -105,7 +105,7 @@ function testBatchFormMultipleBatches() {
// Check that result messages are present and in the correct order.
$this->assertBatchMessages($this->_resultMessages('chained'), 'Batches defined in separate submit handlers performed successfully.');
// The stack contains execution order of batch callbacks and submit
// hanlders and logging of corresponding $form_state[{values'].
// handlers and logging of corresponding $form_state->getValues().
$this->assertEqual(batch_test_stack(), $this->_resultStack('chained', $value), 'Execution order was correct, and $form_state is correctly persisted.');
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
}
......@@ -123,7 +123,7 @@ function testBatchFormProgrammatic() {
// Check that result messages are present and in the correct order.
$this->assertBatchMessages($this->_resultMessages('chained'), 'Batches defined in separate submit handlers performed successfully.');
// The stack contains execution order of batch callbacks and submit
// hanlders and logging of corresponding $form_state[{values'].
// handlers and logging of corresponding $form_state->getValues().
$this->assertEqual(batch_test_stack(), $this->_resultStack('chained', $value), 'Execution order was correct, and $form_state is correctly persisted.');
$this->assertText('Got out of a programmatic batched form.', 'Page execution continues normally.');
}
......
......@@ -215,8 +215,8 @@ private function formSubmitHelper($form, $edit) {
// bypass it by setting the token to FALSE.
$form['#token'] = FALSE;
$form_state['input'] = $edit;
$form_state['input']['form_id'] = $form_id;
$edit['form_id'] = $form_id;
$form_state->setUserInput($edit);
$form_state['build_info']['callback_object'] = new StubForm($form_id, $form);
\Drupal::formBuilder()->prepareForm($form_id, $form, $form_state);
......
......@@ -108,8 +108,9 @@ function testRequiredFields() {
$element = $data['element']['#title'];
$form[$element] = $data['element'];
$form[$element]['#required'] = $required;
$form_state['input'][$element] = $empty;
$form_state['input']['form_id'] = $form_id;
$user_input[$element] = $empty;
$user_input['form_id'] = $form_id;
$form_state->setUserInput($user_input);
$form_state['build_info']['callback_object'] = new StubForm($form_id, $form);
$form_state['method'] = 'post';
// The form token CSRF protection should not interfere with this test,
......
......@@ -44,11 +44,12 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#required' => TRUE,
);
$form['actions'] = array('#type' => 'actions');
$user_input = $form_state->getUserInput();
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => 'Save',
'#limit_validation_errors' => array(
array($form_state['input']['section']),
array($user_input['section']),
),
// Required for #limit_validation_errors.
'#submit' => array(array($this, 'submitForm')),
......
......@@ -1038,7 +1038,8 @@ function system_user_timezone(&$form, FormStateInterface $form_state) {
'#options' => system_time_zones($account->id() != $user->id()),
'#description' => t('Select the desired local time and time zone. Dates and times throughout this site will be displayed using this time zone.'),
);
if (!$account->getTimezone() && $account->id() == $user->id() && empty($form_state['input']['timezone'])) {
$user_input = $form_state->getUserInput();
if (!$account->getTimezone() && $account->id() == $user->id() && empty($user_input['timezone'])) {
$form['timezone']['#description'] = t('Your time zone setting will be automatically detected if possible. Confirm the selection and click save.');
$form['timezone']['#attached']['library'][] = 'core/drupal.timezone';
$form['timezone']['timezone']['#attributes'] = array('class' => array('timezone-detect'));
......
......@@ -76,9 +76,10 @@ public function buildForm(array $form, FormStateInterface $form_state) {
// #limit_validation_errors property.)
'#submit' => array(array($this, 'submitForm')),
);
if (!empty($form_state['input']['field_to_validate']) && $form_state['input']['field_to_validate'] != 'all') {
$user_input = $form_state->getUserInput();
if (!empty($user_input['field_to_validate']) && $user_input['field_to_validate'] != 'all') {
$form['submit_limit_validation']['#limit_validation_errors'] = array(
array($form_state['input']['field_to_validate']),
array($user_input['field_to_validate']),
);
}
......
......@@ -33,11 +33,12 @@ public function getFormId() {
*/
public function buildForm(array $form, FormStateInterface $form_state) {
if ($form_state['rebuild']) {
$form_state['input'] = array();
$form_state->setUserInput(array());
}
// Initialize
if (empty($form_state['storage'])) {
if (empty($form_state['input'])) {
$user_input = $form_state->getUserInput();
if (empty($user_input)) {
$_SESSION['constructions'] = 0;
}
// Put the initial thing into the storage
......
......@@ -171,16 +171,17 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular
// If this form was already submitted once, it's probably hit a validation
// error. Ensure the form is rebuilt in the same order as the user
// submitted.
if (!empty($form_state['input'])) {
$user_input = $form_state->getUserInput();
if (!empty($user_input)) {
// Get the POST order.
$order = array_flip(array_keys($form_state['input']['terms']));
$order = array_flip(array_keys($user_input['terms']));
// Update our form with the new order.
$current_page = array_merge($order, $current_page);
foreach ($current_page as $key => $term) {
// Verify this is a term for the current page and set at the current
// depth.
if (is_array($form_state['input']['terms'][$key]) && is_numeric($form_state['input']['terms'][$key]['term']['tid'])) {
$current_page[$key]->depth = $form_state['input']['terms'][$key]['term']['depth'];
if (is_array($user_input['terms'][$key]) && is_numeric($user_input['terms'][$key]['term']['tid'])) {
$current_page[$key]->depth = $user_input['terms'][$key]['term']['depth'];
}
else {
unset($current_page[$key]);
......
......@@ -200,8 +200,10 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
'#default_value' => $default_value,
);
if (!empty($form_state['exposed']) && isset($identifier) && !isset($form_state['input'][$identifier])) {
$form_state['input'][$identifier] = $default_value;
$user_input = $form_state->getUserInput();
if (!empty($form_state['exposed']) && isset($identifier) && !isset($user_input[$identifier])) {
$user_input[$identifier] = $default_value;
$form_state->setUserInput($user_input);
}
}
......
......@@ -46,8 +46,10 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
'#autocomplete_route_name' => 'user.autocomplete_anonymous',
);
if (!empty($form_state['exposed']) && !isset($form_state['input'][$this->options['expose']['identifier']])) {
$form_state['input'][$this->options['expose']['identifier']] = $default_value;
$user_input = $form_state->getUserInput();
if (!empty($form_state['exposed']) && !isset($user_input[$this->options['expose']['identifier']])) {
$user_input[$this->options['expose']['identifier']] = $default_value;
$form_state->setUserInput($user_input);
}
}
......
......@@ -68,7 +68,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$view = $form_state['view'];
$display = &$form_state['display'];
$form_state['input'] = $view->getExposedInput();
$form_state->setUserInput($view->getExposedInput());
// Let form plugins know this is for exposed widgets.
$form_state['exposed'] = TRUE;
......
......@@ -224,17 +224,19 @@ public function exposedFormAlter(&$form, FormStateInterface $form_state) {
'ASC' => $this->options['sort_asc_label'],
'DESC' => $this->options['sort_desc_label'],
);
if (isset($form_state['input']['sort_by']) && isset($this->view->sort[$form_state['input']['sort_by']])) {
$default_sort_order = $this->view->sort[$form_state['input']['sort_by']]->options['order'];
$user_input = $form_state->getUserInput();
if (isset($user_input['sort_by']) && isset($this->view->sort[$user_input['sort_by']])) {
$default_sort_order = $this->view->sort[$user_input['sort_by']]->options['order'];
}
else {
$first_sort = reset($this->view->sort);
$default_sort_order = $first_sort->options['order'];
}
if (!isset($form_state['input']['sort_by'])) {
if (!isset($user_input['sort_by'])) {
$keys = array_keys($exposed_sorts);
$form_state['input']['sort_by'] = array_shift($keys);
$user_input['sort_by'] = array_shift($keys);
$form_state->setUserInput($user_input);
}
if ($this->options['expose_sort_order']) {
......
......@@ -153,8 +153,10 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
);
if (!empty($this->options['exposed'])) {
$identifier = $this->options['expose']['identifier'];
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
$form_state['input'][$identifier] = $this->value;
$user_input = $form_state->getUserInput();
if (!empty($form_state['exposed']) && !isset($user_input[$identifier])) {
$user_input[$identifier] = $this->value;
$form_state->setUserInput($user_input);
}
// If we're configuring an exposed filter, add an - Any - option.
if (empty($form_state['exposed']) || empty($this->options['expose']['required'])) {
......
......@@ -44,8 +44,10 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
if (!empty($form_state['exposed'])) {
$identifier = $this->options['expose']['identifier'];
if (!isset($form_state['input'][$identifier])) {
$form_state['input'][$identifier] = $this->value;
$user_input = $form_state->getUserInput();
if (!isset($user_input[$identifier])) {
$user_input[$identifier] = $this->value;
$form_state->setUserInput($user_input);
}
}
}
......
......@@ -775,8 +775,10 @@ public function groupForm(&$form, FormStateInterface $form_state) {
$form[$value]['#multiple'] = TRUE;
}
unset($form[$value]['#default_value']);
if (empty($form_state['input'])) {
$form_state['input'][$value] = $this->group_info;
$user_input = $form_state->getUserInput();
if (empty($user_input)) {
$user_input[$value] = $this->group_info;
$form_state->setUserInput($user_input);
}
}
......
......@@ -227,8 +227,10 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
'#multiple' => TRUE,
'#size' => count($options) > 8 ? 8 : count($options),
);
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
$form_state['input'][$identifier] = $default_value;
$user_input = $form_state->getUserInput();
if (!empty($form_state['exposed']) && !isset($user_input[$identifier])) {
$user_input[$identifier] = $default_value;
$form_state->setUserInput($user_input);
}
if ($which == 'all') {
......
......@@ -164,6 +164,7 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
}
}
$user_input = $form_state->getUserInput();
if ($which == 'all') {
$form['value']['value'] = array(
'#type' => 'textfield',
......@@ -177,8 +178,9 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
$source => array('value' => $operator),
);
}
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier]['value'])) {
$form_state['input'][$identifier]['value'] = $this->value['value'];
if (!empty($form_state['exposed']) && !isset($user_input[$identifier]['value'])) {
$user_input[$identifier]['value'] = $this->value['value'];
$form_state->setUserInput($user_input);
}
}
elseif ($which == 'value') {
......@@ -190,8 +192,9 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
'#size' => 30,
'#default_value' => $this->value['value'],
);
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
$form_state['input'][$identifier] = $this->value['value'];
if (!empty($form_state['exposed']) && !isset($user_input[$identifier])) {
$user_input[$identifier] = $this->value['value'];
$form_state->setUserInput($user_input);
}
}
......@@ -219,11 +222,11 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
$form['value']['min'] += $states;
$form['value']['max'] += $states;
}
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier]['min'])) {
$form_state['input'][$identifier]['min'] = $this->value['min'];
if (!empty($form_state['exposed']) && !isset($user_input[$identifier]['min'])) {
$user_input[$identifier]['min'] = $this->value['min'];
}
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier]['max'])) {
$form_state['input'][$identifier]['max'] = $this->value['max'];
if (!empty($form_state['exposed']) && !isset($user_input[$identifier]['max'])) {
$user_input[$identifier]['max'] = $this->value['max'];
}
if (!isset($form['value'])) {
......
......@@ -212,8 +212,10 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
'#size' => 30,