-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* allow option configuration * add upgrade notes * allow form assembling without request and view resolver * add messages to submission event, allow to disable flash bag * fix action and flash message getter * omit form name in headless build * add is_headless_form option * add form dialog builder * add docs
- Loading branch information
Showing
23 changed files
with
776 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Headless Mode | ||
|
||
## AreaBrick | ||
You need to create your own editable, depending on your integration. You may want to use the `FormDialogBuilder` to simplify the area configuration section. | ||
|
||
## Form Building | ||
This is an example, how you may want to build FormBuilder forms in headless mode: | ||
|
||
```php | ||
$optionBuilder = new FormOptionsResolver(); | ||
$optionBuilder->setFormId($formId); | ||
$optionBuilder->setFormTemplate($formTemplate); | ||
$optionBuilder->setFormPreset($formPreset); | ||
$optionBuilder->setOutputWorkflow($formOutputWorkflow); | ||
|
||
$form = $this->formAssembler->assembleHeadlessForm($optionBuilder); | ||
|
||
$form->submit($request->request->all()); | ||
|
||
if (!$form->isValid()) { | ||
|
||
// process validation errors here | ||
|
||
return; | ||
} | ||
|
||
$response = null; | ||
$submissionEvent = new SubmissionEvent($request, $formRuntimeData, $form, null, false); | ||
$this->eventDispatcher->dispatch($submissionEvent, FormBuilderEvents::FORM_SUBMIT_SUCCESS); | ||
|
||
$finishResponse = $this->formSubmissionFinisher->finishWithSuccess($request, $submissionEvent); | ||
|
||
if ($finishResponse instanceof RedirectResponse) { | ||
return [ | ||
'success' => true, | ||
'redirect' => $finishResponse->getTargetUrl() | ||
]; | ||
} | ||
|
||
if ($finishResponse instanceof JsonResponse) { | ||
$response = json_decode($finishResponse->getContent(), true, 512, JSON_THROW_ON_ERROR); | ||
} | ||
|
||
if ($response === null) { | ||
throw new \InvalidArgumentException('empty success response'); | ||
} | ||
|
||
if ($response['success'] === false) { | ||
|
||
if (!array_key_exists('validation_errors', $response)) { | ||
return $response; | ||
} | ||
|
||
$validationErrors = $response['validation_errors'] | ||
// process validation errors here | ||
|
||
return null; | ||
} | ||
|
||
return $response; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.