protected function processSubmit(FormInterface $form, Request $request): void
    {
        // Restored request should only render the form, not immediately submit it.
        if ($request->hasFlag(Request::RESTORED)) {
            return;
        }

        $form->handleRequest($request);
        if (!$form->isSubmitted()) {
            throw new BadRequestException('The form was not submitted.');
        }

        $data = $form->getData();
        if ($form->isValid()) {
            $this->onSuccess($data, $this);
        } else {
            $this->onError($data, $this);
        }
        $this->onSubmit($data, $this);
    }