fixes for new quick-entry week form (#2887)
This commit is contained in:
@@ -15,6 +15,7 @@ use App\Form\Type\WeekPickerType;
|
||||
use App\Model\QuickEntryWeek;
|
||||
use App\Validator\Constraints\QuickEntryModel;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
@@ -36,6 +37,29 @@ class QuickEntryForm extends AbstractType
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->addModelTransformer(new CallbackTransformer(
|
||||
function ($value) {
|
||||
// page is loaded, nothing to do
|
||||
return $value;
|
||||
},
|
||||
function (?QuickEntryWeek $value) {
|
||||
if ($value === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($value->getRows() as $row) {
|
||||
$project = $row->getProject();
|
||||
$activity = $row->getActivity();
|
||||
foreach ($row->getTimesheets() as $timesheet) {
|
||||
$timesheet->setProject($project);
|
||||
$timesheet->setActivity($activity);
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
));
|
||||
|
||||
$startDate = new \DateTime();
|
||||
if ($builder->getData() !== null) {
|
||||
/** @var QuickEntryWeek $data */
|
||||
|
||||
@@ -82,9 +82,23 @@ class QuickEntryWeekType extends AbstractType
|
||||
|
||||
$event->getForm()->add('activity', ActivityType::class, $activityOptions);
|
||||
};
|
||||
|
||||
$builder->addEventListener(FormEvents::PRE_SET_DATA, $activityFunction);
|
||||
|
||||
$activityPreSubmitFunction = function (FormEvent $event) use ($activityOptions) {
|
||||
$data = $event->getData();
|
||||
|
||||
if (isset($data['project']) && !empty($data['project'])) {
|
||||
$activityOptions['projects'] = [$data['project']];
|
||||
}
|
||||
|
||||
if (isset($data['activity']) && !empty($data['activity'])) {
|
||||
$activityOptions['activities'] = [$data['activity']];
|
||||
}
|
||||
|
||||
$event->getForm()->add('activity', ActivityType::class, $activityOptions);
|
||||
};
|
||||
$builder->addEventListener(FormEvents::PRE_SUBMIT, $activityPreSubmitFunction);
|
||||
|
||||
$builder->add('timesheets', CollectionType::class, [
|
||||
'entry_type' => QuickEntryTimesheetType::class,
|
||||
'label' => false,
|
||||
|
||||
Reference in New Issue
Block a user