only in patch2: unchanged: --- a/core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php +++ b/core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php @@ -7,6 +7,8 @@ namespace Drupal\Core\Form\EventSubscriber; +use Drupal\Core\Ajax\AjaxResponse; +use Drupal\Core\Ajax\ReplaceCommand; use Drupal\Core\EventSubscriber\MainContentViewSubscriber; use Drupal\Core\Form\FormAjaxException; use Drupal\Core\Form\FormAjaxResponseBuilderInterface; @@ -14,6 +16,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\KernelEvents; /** @@ -64,9 +67,22 @@ public function onView(GetResponseForControllerResultEvent $event) { * The event to process. */ public function onException(GetResponseForExceptionEvent $event) { + $exception = $event->getException(); + + // @todo Comment. + if ($exception instanceof BadRequestHttpException) { + drupal_set_message($exception->getMessage(), 'error'); + $response = new AjaxResponse(); + $status_messages = array('#type' => 'status_messages'); + $response->addCommand(new ReplaceCommand(NULL, \Drupal::service('renderer')->renderRoot($status_messages))); + $response->headers->set('X-Status-Code', 200); + $event->setResponse($response); + return; + } + // Extract the form AJAX exception (it may have been passed to another // exception before reaching here). - if ($exception = $this->getFormAjaxException($event->getException())) { + if ($exception = $this->getFormAjaxException($exception)) { $request = $event->getRequest(); $form = $exception->getForm(); $form_state = $exception->getFormState(); only in patch2: unchanged: --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -22,6 +22,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; /** * Provides form building and processing. @@ -264,6 +265,11 @@ public function buildForm($form_id, FormStateInterface &$form_state) { // can use it to know or update information about the state of the form. $response = $this->processForm($form_id, $form, $form_state); + // @todo Comment. + if ($ajax_form_request && !isset($form_state->getUserInput()['form_id'])) { + throw new BadRequestHttpException(t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', array('@size' => format_size(file_upload_max_size())))); + } + // After processing the form, if this is an AJAX form request, interrupt // form rendering and return by throwing an exception that contains the // processed form and form state. This exception will be caught by