mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 19:43:49 +00:00
ActivityType add new fields
This commit is contained in:
@@ -2,7 +2,12 @@
|
||||
|
||||
namespace Chill\ActivityBundle\Form;
|
||||
|
||||
use Chill\ActivityBundle\Entity\ActivityTypeCategory;
|
||||
use Chill\ActivityBundle\Form\Type\ActivityFieldPresence;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
@@ -10,6 +15,13 @@ use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
|
||||
class ActivityTypeType extends AbstractType
|
||||
{
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper)
|
||||
{
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
@@ -18,13 +30,36 @@ class ActivityTypeType extends AbstractType
|
||||
{
|
||||
$builder
|
||||
->add('name', TranslatableStringFormType::class)
|
||||
->add('active', ChoiceType::class, array(
|
||||
'choices' => array(
|
||||
->add('active', ChoiceType::class, [
|
||||
'choices' => [
|
||||
'Yes' => true,
|
||||
'No' => false
|
||||
),
|
||||
],
|
||||
'expanded' => true
|
||||
));
|
||||
])
|
||||
->add('category', EntityType::class, [
|
||||
'class' => ActivityTypeCategory::class,
|
||||
'choice_label' => function (ActivityTypeCategory $activityTypeCategory) {
|
||||
return $this->translatableStringHelper->localize($activityTypeCategory->getName());
|
||||
},
|
||||
])
|
||||
;
|
||||
|
||||
$fields = [
|
||||
'person', 'user', 'date', 'place', 'persons',
|
||||
'thirdparty', 'durationTime', 'attendee',
|
||||
'reasons', 'comment', 'sentReceived', 'document',
|
||||
'emergency', 'accompanyingPeriod', 'socialData'
|
||||
];
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$builder
|
||||
->add($field.'Visible', ActivityFieldPresence::class)
|
||||
->add($field.'Label', TextType::class, [
|
||||
'required' => false,
|
||||
'empty_data' => '',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\ActivityBundle\Form\Type;
|
||||
|
||||
use Chill\ActivityBundle\Entity\ActivityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class ActivityFieldPresence extends AbstractType
|
||||
{
|
||||
public function getParent()
|
||||
{
|
||||
return ChoiceType::class;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(
|
||||
array(
|
||||
'choices' => [
|
||||
'Invisible' => ActivityType::FIELD_INVISIBLE,
|
||||
'Optional' => ActivityType::FIELD_OPTIONAL,
|
||||
'Required' => ActivityType::FIELD_REQUIRED,
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user