<?php
namespace App\Form\Flow;
// src/MyCompany/MyBundle/Form/CreateVehicleFlow.php
use Craue\FormFlowBundle\Form\FormFlow;
use Craue\FormFlowBundle\Form\FormFlowInterface;
use Craue\FormFlowBundle\Event\GetStepsEvent;
use Craue\FormFlowBundle\Event\PostBindFlowEvent;
use Craue\FormFlowBundle\Event\PostBindRequestEvent;
use Craue\FormFlowBundle\Event\PostBindSavedDataEvent;
use Craue\FormFlowBundle\Event\PostValidateEvent;
use Craue\FormFlowBundle\Event\PreBindEvent;
use Craue\FormFlowBundle\Form\FormFlowEvents;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use App\Form\ManualInspectionForm;
class ManualInspectionFlow extends FormFlow implements EventSubscriberInterface {
public static function getSubscribedEvents(): array {
return [
FormFlowEvents::PRE_BIND => 'onPreBind',
FormFlowEvents::GET_STEPS => 'onGetSteps',
FormFlowEvents::POST_BIND_SAVED_DATA => 'onPostBindSavedData',
FormFlowEvents::POST_BIND_FLOW => 'onPostBindFlow',
FormFlowEvents::POST_BIND_REQUEST => 'onPostBindRequest',
FormFlowEvents::POST_VALIDATE => 'onPostValidate',
];
}
public function onPreBind(PreBindEvent $event) {
// ...
}
public function onGetSteps(GetStepsEvent $event) {
// ...
}
public function onPostBindSavedData(PostBindSavedDataEvent $event) {
// ...
}
public function onPostBindFlow(PostBindFlowEvent $event) {
// ...
}
public function onPostBindRequest(PostBindRequestEvent $event) {
// ...
}
public function onPostValidate(PostValidateEvent $event) {
if($this->determineCurrentStepNumber() && $this->determineCurrentStepNumber() == 3) {
$manualInspection = $event->getFormData();
for($i = 1; $i < 16; $i++) {
$methodName = 'getQ'.$i;
$options = parent::getFormOptions(1);
if($manualInspection->{$methodName}() == false) {
$manualInspection->setHasAnswersWithNo(true);
break;
}
}
}
}
protected function loadStepsConfig(): array {
return [
[
'label' => 'Zugänge',
'form_type' => ManualInspectionForm::class,
],
// Step 2: Fahrt separate Messspunkte
[
'label' => 'Anlage',
'form_type' => ManualInspectionForm::class,
],
// Step 3: Fahrt ein Messspunkt
[
'label' => 'Dokumentation',
'form_type' => ManualInspectionForm::class,
],
// Step 4: Tür 1 separate Messspunkte
[
'label' => 'Sonstiges und Bestätigung',
'form_type' => ManualInspectionForm::class,
],
];
}
}