Install the Bundle
composer require dbp/relay-formalize-bundle
Ensure your config/bundles.php includes:
return [
// ...
DigitalBlueprint\Relay\FormalizeBundle\FormalizeBundle::class => ['all' => true],
];
Configure the Bundle Publish the default config:
php bin/console dbp:relay-formalize:install
Update config/packages/dbp_relay_formalize.yaml with your database and authorization settings.
First Use Case: Basic Form
Define a form schema in YAML (e.g., config/forms/event_registration.yaml):
name: event_registration
title: "Event Registration"
fields:
- { name: "name", type: "text", label: "Your Name" }
- { name: "email", type: "email", label: "Email" }
Register the form in a controller:
use DigitalBlueprint\Relay\FormalizeBundle\Form\FormManager;
public function showForm(FormManager $formManager)
{
$form = $formManager->getForm('event_registration');
return $this->render('form/show.html.twig', ['form' => $form]);
}
Form Definition & Validation
config/forms/).required, email, regex) or extend with custom rules via ValidationExtension.fields:
- { name: "age", type: "integer", validators: ["min:18"] }
Submission Lifecycle
allow_drafts: true) and use the SubmissionManager to save drafts:
$submission = $submissionManager->createDraft('event_registration', $user);
$submission->setData(['name' => 'John']);
$submissionManager->saveDraft($submission);
submission.created) via Symfony’s event dispatcher:
$eventDispatcher->addListener(SubmissionEvents::SUBMISSION_CREATED, function (SubmissionEvent $event) {
// Send confirmation email
});
Authorization
DbpRelayAuthorizationBundle to restrict form access:
# config/packages/dbp_relay_authorization.yaml
access_control:
- { path: ^/form/event_registration, roles: ROLE_USER }
AuthorizationChecker in controllers:
if (!$authorizationChecker->isGranted('ROLE_ADMIN')) {
throw $this->createAccessDeniedException();
}
File Uploads
fields:
- { name: "document", type: "file", upload_dir: "uploads/event_registrations" }
Submission entity:
$filePath = $submission->getFilePath('document');
Exports
Exporter service:
$exporter = $this->container->get('dbp_relay_formalize.exporter');
$pdf = $exporter->exportToPdf($submissions, 'event_registration');
Relay API Server to expose forms/submissions as REST endpoints. Configure routes in config/routes.yaml:
dbp_relay_formalize:
resource: "@DbpRelayFormalizeBundle/Resources/config/routes.yaml"
FormManager and SubmissionManager in PHPUnit:
$formManager = $this->createMock(FormManager::class);
$formManager->method('getForm')->willReturn($form);
$this->container->set(FormManager::class, $formManager);
Schema Caching
php bin/console cache:clear
config/packages/dbp_relay_formalize.yaml:
cache:
enabled: false
File Uploads
upload_dir in the schema is writable by the web server (e.g., chmod -R 775 uploads/).upload_max_filesize and post_max_size in php.ini.Authorization Conflicts
FormalizeBundle and AuthorizationBundle, ensure roles are consistent across bundles. Debug with:
$this->container->get('debug.authorization_checker')->isGranted('ROLE_ADMIN');
Submission Events
SubmissionEvent::getSubmission() to access data in listeners./_profiler) for validation messages.config/packages/dev/dbp_relay_formalize.yaml:
database:
logging: true
npm run build) if styles/scripts fail to load.Custom Validators
services.yaml:
services:
App\Validator\Constraints\CustomValidator:
tags: [validator.constraint_validator]
fields:
- { name: "custom_field", type: "text", validators: ["@App\Validator\Constraints\CustomValidator"] }
Submission Exporters
Exporter service by overriding the exportToPdf/exportToExcel methods in a custom service:
class CustomExporter extends Exporter
{
public function exportToPdf(array $submissions, string $formName): string
{
// Custom logic
return parent::exportToPdf($submissions, $formName);
}
}
services.yaml and set it as the default exporter in config.Dynamic Forms
FormBuilder service to create forms programmatically:
$form = $formBuilder->buildForm('dynamic_form', [
'fields' => [
['name' => 'dynamic_field', 'type' => 'text', 'label' => 'Dynamic Label']
]
]);
Multi-Stage Workflows
Submission entity and using Symfony’s StateMachine component:
$submission->getStateMachine()->apply('submit');
$eventDispatcher->addListener(SubmissionEvents::SUBMISSION_STATE_CHANGED, function (StateEvent $event) {
// Handle state change (e.g., send approval email)
});
submissions table by default. Customize the table name in config:
database:
submission_table: custom_submissions
FileStorageInterface and configuring in services.yaml:
services:
dbp_relay_formalize.file_storage:
class: App\Service\S3FileStorage
How can I help you explore Laravel packages today?