diff --git a/core/lib/Drupal/Core/Ajax/AjaxForm.php b/core/lib/Drupal/Core/Ajax/AjaxForm.php new file mode 100644 index 0000000..b40538c --- /dev/null +++ b/core/lib/Drupal/Core/Ajax/AjaxForm.php @@ -0,0 +1,97 @@ +form = $form; + $this->formState = $form_state; + $this->formId = $form_id; + $this->formBuildId = $form_build_id; + $this->commands = $commands; + } + + /** + * @return \Drupal\Core\Ajax\CommandInterface[] + */ + public function getCommands() { + return $this->commands; + } + + /** + * @return array + */ + public function getForm() { + return $this->form; + } + + /** + * @return string + */ + public function getFormBuildId() { + return $this->formBuildId; + } + + /** + * @return string + */ + public function getFormId() { + return $this->formId; + } + + /** + * @return \Drupal\Core\Form\FormStateInterface + */ + public function getFormState() { + return $this->formState; + } + +} diff --git a/core/modules/file/src/Controller/FileWidgetAjaxController.php b/core/modules/file/src/Controller/FileWidgetAjaxController.php index 1d225cd..5d017c5 100644 --- a/core/modules/file/src/Controller/FileWidgetAjaxController.php +++ b/core/modules/file/src/Controller/FileWidgetAjaxController.php @@ -8,6 +8,7 @@ namespace Drupal\file\Controller; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Ajax\AjaxForm; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\ReplaceCommand; use Drupal\system\Controller\FormAjaxController; @@ -43,7 +44,11 @@ public function upload(Request $request) { } try { - list($form, $form_state, $form_id, $form_build_id, $commands) = $this->getForm($request); + /** @var $ajaxForm \Drupal\Core\Ajax\AjaxForm */ + $ajaxForm = $this->getForm($request); + $form = $ajaxForm->getForm(); + $form_state = $ajaxForm->getFormState(); + $commands = $ajaxForm->getCommands(); } catch (HttpExceptionInterface $e) { // Invalid form_build_id. diff --git a/core/modules/system/src/Controller/FormAjaxController.php b/core/modules/system/src/Controller/FormAjaxController.php index b8b9069..08a1f40 100644 --- a/core/modules/system/src/Controller/FormAjaxController.php +++ b/core/modules/system/src/Controller/FormAjaxController.php @@ -8,6 +8,7 @@ namespace Drupal\system\Controller; use Drupal\Core\Ajax\AjaxResponse; +use Drupal\Core\Ajax\AjaxForm; use Drupal\Core\Ajax\UpdateBuildIdCommand; use Drupal\Core\Form\FormState; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; @@ -65,7 +66,12 @@ public static function create(ContainerInterface $container) { * @throws \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface */ public function content(Request $request) { - list($form, $form_state, $form_id, $form_build_id, $commands) = $this->getForm($request); + /** @var $ajaxForm \Drupal\Core\Ajax\AjaxForm */ + $ajaxForm = $this->getForm($request); + $form = $ajaxForm->getForm(); + $form_state = $ajaxForm->getFormState(); + $commands = $ajaxForm->getCommands(); + drupal_process_form($form['#form_id'], $form, $form_state); // We need to return the part of the form (or some other content) that needs @@ -153,7 +159,7 @@ protected function getForm(Request $request) { $form_state->setUserInput($request->request->all()); $form_id = $form['#form_id']; - return [$form, $form_state, $form_id, $form_build_id, $commands]; + return new AjaxForm($form, $form_state, $form_id, $form_build_id, $commands); } }