diff --git a/core/core.api.php b/core/core.api.php index a8b13ca..e2ff4dd 100644 --- a/core/core.api.php +++ b/core/core.api.php @@ -2054,12 +2054,6 @@ function hook_validation_constraint_alter(array &$definitions) { * an array. Here are the details of its elements, all of which are optional: * - callback: The callback to invoke to handle the server side of the * Ajax event. More information on callbacks is below in @ref sub_callback. - * - path: The URL path to use for the request. If omitted, defaults to - * 'system/ajax', which invokes the default Drupal Ajax processing (this will - * call the callback supplied in the 'callback' element). If you supply a - * path, you must set up a routing entry to handle the request yourself and - * return output described in @ref sub_callback below. See the - * @link menu Routing topic @endlink for more information on routing. * - wrapper: The HTML 'id' attribute of the area where the content returned by * the callback should be placed. Note that callbacks have a choice of * returning content or JavaScript commands; 'wrapper' is used for content diff --git a/core/lib/Drupal/Core/Form/FormBuilderInterface.php b/core/lib/Drupal/Core/Form/FormBuilderInterface.php index 60ad704..bbfed36 100644 --- a/core/lib/Drupal/Core/Form/FormBuilderInterface.php +++ b/core/lib/Drupal/Core/Form/FormBuilderInterface.php @@ -108,9 +108,7 @@ public function buildForm($form_id, FormStateInterface &$form_state); * form workflow, to be returned for rendering. * * Ajax form submissions are almost always multi-step workflows, so that is - * one common use-case during which form rebuilding occurs. See - * Drupal\system\FormAjaxController::content() for more information about - * creating Ajax-enabled forms. + * one common use-case during which form rebuilding occurs. * * @param string $form_id * The unique string identifying the desired form. If a function with that @@ -130,7 +128,6 @@ public function buildForm($form_id, FormStateInterface &$form_state); * The newly built form. * * @see self::processForm() - * @see \Drupal\system\FormAjaxController::content() */ public function rebuildForm($form_id, FormStateInterface &$form_state, $old_form = NULL); diff --git a/core/lib/Drupal/Core/Theme/AjaxBasePageNegotiator.php b/core/lib/Drupal/Core/Theme/AjaxBasePageNegotiator.php index b15ce93..9d904ee 100644 --- a/core/lib/Drupal/Core/Theme/AjaxBasePageNegotiator.php +++ b/core/lib/Drupal/Core/Theme/AjaxBasePageNegotiator.php @@ -15,12 +15,12 @@ /** * Defines a theme negotiator that deals with the active theme on ajax requests. * - * Many different pages can invoke an Ajax request to system/ajax or another - * generic Ajax path. It is almost always desired for an Ajax response to be - * rendered using the same theme as the base page, because most themes are built - * with the assumption that they control the entire page, so if the CSS for two - * themes are both loaded for a given page, they may conflict with each other. - * For example, Bartik is Drupal's default theme, and Seven is Drupal's default + * Many different pages can invoke an Ajax request to a generic Ajax path. It is + * almost always desired for an Ajax response to be rendered using the same + * theme as the base page, because most themes are built with the assumption + * that they control the entire page, so if the CSS for two themes are both + * loaded for a given page, they may conflict with each other. For example, + * Bartik is Drupal's default theme, and Seven is Drupal's default * administration theme. Depending on whether the "Use the administration theme * when editing or creating content" checkbox is checked, the node edit form may * be displayed in either theme, but the Ajax response to the Field module's diff --git a/core/modules/file/src/Controller/FileWidgetAjaxController.php b/core/modules/file/src/Controller/FileWidgetAjaxController.php index 1c1b7e3..d05a4dd 100644 --- a/core/modules/file/src/Controller/FileWidgetAjaxController.php +++ b/core/modules/file/src/Controller/FileWidgetAjaxController.php @@ -7,13 +7,12 @@ namespace Drupal\file\Controller; -use Drupal\system\Controller\FormAjaxController; use Symfony\Component\HttpFoundation\JsonResponse; /** * Defines a controller to respond to file widget AJAX requests. */ -class FileWidgetAjaxController extends FormAjaxController { +class FileWidgetAjaxController { /** * Returns the progress status for a file upload process. diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index f1399e2..5c13871 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -1593,15 +1593,14 @@ protected function drupalGetAjax($path, array $options = array(), array $headers * case, this value needs to be an array with the following keys: * - path: A path to submit the form values to for Ajax-specific processing, * which is likely different than the $path parameter used for retrieving - * the initial form. Defaults to 'system/ajax'. - * - triggering_element: If the value for the 'path' key is 'system/ajax' or - * another generic Ajax processing path, this needs to be set to the name - * of the element. If the name doesn't identify the element uniquely, then - * this should instead be an array with a single key/value pair, - * corresponding to the element name and value. The callback for the - * generic Ajax processing path uses this to find the #ajax information - * for the element, including which specific callback to use for - * processing the request. + * the initial form. + * - triggering_element: If the value for the 'path' key is a generic Ajax + * processing path, this needs to be set to the name of the element. If + * the name doesn't identify the element uniquely, then this should + * instead be an array with a single key/value pair, corresponding to the + * element name and value. The callback for the generic Ajax processing + * path uses this to find the #ajax information for the element, including + * which specific callback to use for processing the request. * * This can also be set to NULL in order to emulate an Internet Explorer * submission of a form with a single text field, and pressing ENTER in that @@ -1649,7 +1648,7 @@ protected function drupalPostForm($path, $edit, $submit, array $options = array( $submit_matches = $this->handleForm($post, $edit, $upload, $ajax ? NULL : $submit, $form); $action = isset($form['action']) ? $this->getAbsoluteUrl((string) $form['action']) : $this->getUrl(); if ($ajax) { - $action = $this->getAbsoluteUrl(!empty($submit['path']) ? $submit['path'] : 'system/ajax'); + $action = $this->getAbsoluteUrl(!empty($submit['path']) ? $submit['path'] : ''); // Ajax callbacks verify the triggering element if necessary, so while // we may eventually want extra code that verifies it in the // handleForm() function, it's not currently a requirement. @@ -1736,7 +1735,8 @@ protected function drupalPostForm($path, $edit, $submit, array $options = array( * @param $ajax_path * (optional) Override the path set by the Ajax settings of the triggering * element. In the absence of both the triggering element's Ajax path and - * $ajax_path 'system/ajax' will be used. + * $ajax_path '' will be used. + * @todo Using '' is definitely wrong, what should it be? * @param $options * (optional) Options to be forwarded to the url generator. * @param $headers @@ -1808,7 +1808,8 @@ protected function drupalPostAjaxForm($path, $edit, $triggering_element, $ajax_p $extra_post = '&' . $this->serializePostValues($extra_post); // Unless a particular path is specified, use the one specified by the - // Ajax settings, or else 'system/ajax'. + // Ajax settings, or else ''. + // @todo Using '' is definitely wrong, what should it be? if (!isset($ajax_path)) { if (isset($ajax_settings['url'])) { // In order to allow to set for example the wrapper envelope query @@ -1826,7 +1827,8 @@ protected function drupalPostAjaxForm($path, $edit, $triggering_element, $ajax_p ); } else { - $ajax_path = 'system/ajax'; + // @todo Using '' is definitely wrong, what should it be? + $ajax_path = ''; } } $ajax_path = $this->container->get('unrouted_url_assembler')->assemble('base://' . $ajax_path, $options); diff --git a/core/modules/system/src/Controller/FormAjaxController.php b/core/modules/system/src/Controller/FormAjaxController.php deleted file mode 100644 index 084847a..0000000 --- a/core/modules/system/src/Controller/FormAjaxController.php +++ /dev/null @@ -1,186 +0,0 @@ -logger = $logger; - $this->formBuilder = $form_builder; - $this->renderer = $renderer; - $this->ajaxRenderer = $ajax_renderer; - $this->routeMatch = $route_match; - $this->formAjaxResponseBuilder = $form_ajax_response_builder; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('logger.factory')->get('ajax'), - $container->get('form_builder'), - $container->get('renderer'), - $container->get('main_content_renderer.ajax'), - $container->get('current_route_match'), - $container->get('form_ajax_response_builder') - ); - } - - /** - * Processes an Ajax form submission. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The current request object. - * - * @return mixed - * Whatever is returned by the triggering element's #ajax['callback'] - * function. One of: - * - A render array containing the new or updated content to return to the - * browser. This is commonly an element within the rebuilt form. - * - A \Drupal\Core\Ajax\AjaxResponse object containing commands for the - * browser to process. - * - * @throws \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface - */ - public function content(Request $request) { - $ajax_form = $this->getForm($request); - $form = $ajax_form->getForm(); - $form_state = $ajax_form->getFormState(); - $commands = $ajax_form->getCommands(); - - $this->formBuilder->processForm($form['#form_id'], $form, $form_state); - - return $this->formAjaxResponseBuilder->buildResponse($request, $form, $form_state, $commands); - } - - /** - * Gets a form submitted via #ajax during an Ajax callback. - * - * This will load a form from the form cache used during Ajax operations. It - * pulls the form info from the request body. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The current request object. - * - * @return \Drupal\system\FileAjaxForm - * A wrapper object containing the $form, $form_state, $form_id, - * $form_build_id and an initial list of Ajax $commands. - * - * @throws \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface - */ - protected function getForm(Request $request) { - $form_state = new FormState(); - $form_build_id = $request->request->get('form_build_id'); - - // Get the form from the cache. - $form = $this->formBuilder->getCache($form_build_id, $form_state); - if (!$form) { - // If $form cannot be loaded from the cache, the form_build_id must be - // invalid, which means that someone performed a POST request onto - // system/ajax without actually viewing the concerned form in the browser. - // This is likely a hacking attempt as it never happens under normal - // circumstances. - $this->logger->warning('Invalid form POST data.'); - throw new BadRequestHttpException(); - } - - // Since some of the submit handlers are run, redirects need to be disabled. - $form_state->disableRedirect(); - - // When a form is rebuilt after Ajax processing, its #build_id and #action - // should not change. - // @see \Drupal\Core\Form\FormBuilderInterface::rebuildForm() - $form_state->addRebuildInfo('copy', [ - '#build_id' => TRUE, - '#action' => TRUE, - ]); - - // The form needs to be processed; prepare for that by setting a few - // internal variables. - $form_state->setUserInput($request->request->all()); - $form_id = $form['#form_id']; - - return new FileAjaxForm($form, $form_state, $form_id, $form['#build_id'], []); - } - -} diff --git a/core/modules/system/src/Tests/Ajax/AjaxFormPageCacheTest.php b/core/modules/system/src/Tests/Ajax/AjaxFormPageCacheTest.php index 03727b6..136ec69 100644 --- a/core/modules/system/src/Tests/Ajax/AjaxFormPageCacheTest.php +++ b/core/modules/system/src/Tests/Ajax/AjaxFormPageCacheTest.php @@ -35,7 +35,7 @@ protected function getFormBuildId() { } /** - * Create a simple form, then POST to system/ajax to change to it. + * Create a simple form, then POST via AJAX to change to it. */ public function testSimpleAJAXFormValue() { $this->drupalGet('ajax_forms_test_get_form'); diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml index 12e7d9a..a386196 100644 --- a/core/modules/system/system.routing.yml +++ b/core/modules/system/system.routing.yml @@ -1,12 +1,3 @@ -system.ajax: - path: '/system/ajax' - defaults: - _controller: '\Drupal\system\Controller\FormAjaxController::content' - options: - _theme: ajax_base_page - requirements: - _access: 'TRUE' - system.401: path: '/system/401' defaults: diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestSimpleForm.php b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestSimpleForm.php index 225664d..2fcfd1f 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestSimpleForm.php +++ b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestSimpleForm.php @@ -57,7 +57,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ); // This is for testing invalid callbacks that should return a 500 error in - // \Drupal\system\FormAjaxController::content(). + // \Drupal\Core\Form\FormAjaxResponseBuilderInterface::buildResponse(). $invalid_callbacks = array( 'null' => NULL, 'empty' => '',