diff --git a/core/lib/Drupal/Core/Controller/FormController.php b/core/lib/Drupal/Core/Controller/FormController.php index 03a76d4..6a9b9d5 100644 --- a/core/lib/Drupal/Core/Controller/FormController.php +++ b/core/lib/Drupal/Core/Controller/FormController.php @@ -8,7 +8,6 @@ namespace Drupal\Core\Controller; use Drupal\Core\DependencyInjection\DependencySerializationTrait; -use Drupal\Core\EventSubscriber\FormControllerSubscriber; use Drupal\Core\Form\FormBuilderInterface; use Drupal\Core\Form\FormState; use Drupal\Core\Routing\RouteMatchInterface; @@ -77,12 +76,6 @@ public function getContentResult(Request $request, RouteMatchInterface $route_ma unset($args[0], $args[1]); $form_state->addBuildInfo('args', array_values($args)); - // If this form is being submitted back to its original URL, disable all - // redirects. - if ($request->query->get(FormControllerSubscriber::POST_TO_ORIGINAL_URL) === FormControllerSubscriber::DRUPAL_AJAX_POST) { - $form_state->disableRedirect(); - } - return $this->formBuilder->buildForm($form_object, $form_state); } diff --git a/core/lib/Drupal/Core/Field/WidgetBase.php b/core/lib/Drupal/Core/Field/WidgetBase.php index cc13ae4..1289596 100644 --- a/core/lib/Drupal/Core/Field/WidgetBase.php +++ b/core/lib/Drupal/Core/Field/WidgetBase.php @@ -12,6 +12,7 @@ use Drupal\Component\Utility\SortArray; use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; use Symfony\Component\Validator\ConstraintViolationInterface; use Symfony\Component\Validator\ConstraintViolationListInterface; @@ -243,6 +244,9 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f 'callback' => array(get_class($this), 'addMoreAjax'), 'wrapper' => $wrapper_id, 'effect' => 'fade', + // @todo Remove this. + 'url' => Url::fromRoute('system.ajax'), + 'cache_form' => TRUE, ), ); } diff --git a/core/lib/Drupal/Core/Form/FormAjaxException.php b/core/lib/Drupal/Core/Form/FormAjaxException.php index 4a405f6..66d4274 100644 --- a/core/lib/Drupal/Core/Form/FormAjaxException.php +++ b/core/lib/Drupal/Core/Form/FormAjaxException.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Form; /** - * @todo. + * Custom exception to break out of AJAX form processing. */ class FormAjaxException extends \Exception { diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index 7c0eba3..8418faf 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -247,7 +247,7 @@ public function buildForm($form_id, FormStateInterface &$form_state) { // If this form should post to the original URL, disable all form redirects. $request = $this->requestStack->getCurrentRequest(); - if ($post_to_original_url = $request->query->get(FormControllerSubscriber::POST_TO_ORIGINAL_URL) === FormControllerSubscriber::DRUPAL_AJAX_POST) { + if ($post_to_original_url = ($request->query->get(FormControllerSubscriber::POST_TO_ORIGINAL_URL) === FormControllerSubscriber::DRUPAL_AJAX_POST)) { $form_state->disableRedirect(); } diff --git a/core/lib/Drupal/Core/Render/Element/RenderElement.php b/core/lib/Drupal/Core/Render/Element/RenderElement.php index aaf2969..1c788e9 100644 --- a/core/lib/Drupal/Core/Render/Element/RenderElement.php +++ b/core/lib/Drupal/Core/Render/Element/RenderElement.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Render\Element; -use Drupal\Component\Utility\NestedArray; use Drupal\Core\EventSubscriber\FormControllerSubscriber; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginBase; @@ -130,6 +129,10 @@ public static function preRenderGroup($element) { */ public static function processAjaxForm(&$element, FormStateInterface $form_state, &$complete_form) { $element = static::preRenderAjaxForm($element); + // @todo Remove this. + if (!empty($element['#ajax']['cache_form'])) { + $form_state->setCached(); + } return $element; } @@ -151,6 +154,7 @@ public static function processAjaxForm(&$element, FormStateInterface $form_state * - #ajax['parameters'] * - #ajax['effect'] * - #ajax['accepts'] + * - #ajax['cache_form'] * * @return array * The processed element with the necessary JavaScript attached to it. diff --git a/core/modules/file/src/Element/ManagedFile.php b/core/modules/file/src/Element/ManagedFile.php index 40d0c31..9719ea9 100644 --- a/core/modules/file/src/Element/ManagedFile.php +++ b/core/modules/file/src/Element/ManagedFile.php @@ -146,6 +146,8 @@ public static function processManagedFile(&$element, FormStateInterface $form_st $ajax_settings = [ 'url' => Url::fromRoute('file.ajax_upload'), + // @todo Remove this. + 'cache_form' => TRUE, 'options' => [ 'query' => [ 'element_parents' => implode('/', $element['#array_parents']), diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 721fdd9..a206f0e 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -1504,6 +1504,8 @@ protected function drupalGetAjax($path, array $options = array(), array $headers * is done by drupalPostAjaxForm(). This string is literally appended to the * POST data, so it must already be urlencoded and contain a leading "&" * (e.g., "&extra_var1=hello+world&extra_var2=you%26me"). + * + * @return bool|string|null */ protected function drupalPostForm($path, $edit, $submit, array $options = array(), array $headers = array(), $form_html_id = NULL, $extra_post = NULL) { $submit_matches = FALSE; @@ -2622,7 +2624,8 @@ protected function prepareRequestForGenerator($clean_urls = TRUE, $override_serv */ protected function buildUrl($path, array $options = array()) { if ($path instanceof Url) { - return $path->setAbsolute()->toString(); + $absolute_path = clone $path; + return $absolute_path->setAbsolute()->toString(); } // The URL generator service is not necessarily available yet; e.g., in // interactive installer tests. diff --git a/core/modules/views_ui/admin.inc b/core/modules/views_ui/admin.inc index 6c72b03..b5cbda5 100644 --- a/core/modules/views_ui/admin.inc +++ b/core/modules/views_ui/admin.inc @@ -53,7 +53,9 @@ function views_ui_add_ajax_trigger(&$wrapping_element, $trigger_key, $refresh_pa $triggering_element['#ajax']['callback'] = 'views_ui_ajax_update_form'; // Specify the #ajax URL in order to retain form caching. + // @todo Remove this. $triggering_element['#ajax']['url'] = Url::fromRoute('system.ajax'); + $triggering_element['#ajax']['cache_form'] = TRUE; // We do not use \Drupal\Component\Utility\Html::getUniqueId() to get an ID // for the AJAX wrapper, because it remembers IDs across AJAX requests (and