diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php index 4218174eb..2c53af0fe 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php @@ -77,6 +77,7 @@ class Configuration implements ConfigurationInterface ->append($this->addFieldNode('nationality')) ->append($this->addFieldNode('country_of_birth')) ->append($this->addFieldNode('marital_status')) + ->append($this->addFieldNode('civility')) ->append($this->addFieldNode('spoken_languages')) ->append($this->addFieldNode('address')) ->append($this->addFieldNode('accompanying_period')) diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 9aaad8c04..0ae5d2a79 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -34,6 +34,7 @@ use Chill\PersonBundle\Entity\MaritalStatus; use Chill\PersonBundle\Entity\Household\HouseholdMember; use Chill\MainBundle\Entity\HasCenterInterface; use Chill\MainBundle\Entity\Address; +use Chill\MainBundle\Entity\Civility; use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Chill\PersonBundle\Entity\Person\PersonCurrentAddress; use DateTime; @@ -212,6 +213,15 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI */ private $maritalStatus; + /** + * The marital status of the person + * @var Civility + * + * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Civility") + * @ORM\JoinColumn(nullable=true) + */ + private $civility; + /** * The date of the last marital status change of the person * @var \DateTime @@ -962,6 +972,28 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this->maritalStatus; } + /** + * Set civility + * + * @param Civility $civility + * @return Person + */ + public function setCivility(Civility $civility = null) + { + $this->civility = $civility; + return $this; + } + + /** + * Get civility + * + * @return Civility + */ + public function getCivility() + { + return $this->civility; + } + /** * Set contactInfo * diff --git a/src/Bundle/ChillPersonBundle/Form/PersonType.php b/src/Bundle/ChillPersonBundle/Form/PersonType.php index abe4750f2..521d9a9d9 100644 --- a/src/Bundle/ChillPersonBundle/Form/PersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/PersonType.php @@ -22,6 +22,7 @@ namespace Chill\PersonBundle\Form; use Chill\CustomFieldsBundle\Form\Type\CustomFieldType; +use Chill\MainBundle\Entity\Civility; use Chill\MainBundle\Form\Type\ChillCollectionType; use Chill\MainBundle\Form\Type\ChillTextareaType; use Chill\MainBundle\Form\Type\Select2CountryType; @@ -35,6 +36,10 @@ use Chill\PersonBundle\Form\Type\Select2MaritalStatusType; use Symfony\Component\Form\AbstractType; use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\CommentType; +use Chill\MainBundle\Templating\TranslatableStringHelper; +use Doctrine\ORM\QueryBuilder; +use Doctrine\ORM\EntityRepository; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\CallbackTransformer; use Symfony\Component\Form\Extension\Core\Type\EmailType; use Symfony\Component\Form\Extension\Core\Type\TelType; @@ -63,16 +68,20 @@ class PersonType extends AbstractType */ protected $configAltNamesHelper; + protected TranslatableStringHelper $translatableStringHelper; + /** * * @param string[] $personFieldsConfiguration configuration of visibility of some fields */ public function __construct( array $personFieldsConfiguration, - ConfigPersonAltNamesHelper $configAltNamesHelper + ConfigPersonAltNamesHelper $configAltNamesHelper, + TranslatableStringHelper $translatableStringHelper ) { $this->config = $personFieldsConfiguration; $this->configAltNamesHelper = $configAltNamesHelper; + $this->translatableStringHelper = $translatableStringHelper; } /** @@ -190,6 +199,23 @@ class PersonType extends AbstractType )); } + if ($this->config['civility'] === 'visible'){ + $builder + ->add('civility', EntityType::class, [ + 'label' => 'Civility', + 'class' => Civility::class, + 'choice_label' => function (Civility $civility): string { + return $this->translatableStringHelper->localize($civility->getName()); + }, + 'query_builder' => function (EntityRepository $er): QueryBuilder { + return $er->createQueryBuilder('c') + ->where('c.active = true'); + }, + 'placeholder' => 'choose civility', + 'required' => false + ]); + } + if ($this->config['marital_status'] === 'visible'){ $builder ->add('maritalStatus', Select2MaritalStatusType::class, array( diff --git a/src/Bundle/ChillPersonBundle/Resources/test/Fixtures/App/app/config/config_test_with_hidden_fields.yml b/src/Bundle/ChillPersonBundle/Resources/test/Fixtures/App/app/config/config_test_with_hidden_fields.yml index e11599661..0b12be8d0 100644 --- a/src/Bundle/ChillPersonBundle/Resources/test/Fixtures/App/app/config/config_test_with_hidden_fields.yml +++ b/src/Bundle/ChillPersonBundle/Resources/test/Fixtures/App/app/config/config_test_with_hidden_fields.yml @@ -15,4 +15,5 @@ chill_person: phonenumber: hidden country_of_birth: hidden marital_status: hidden - spoken_languages: hidden \ No newline at end of file + spoken_languages: hidden + civility: hidden \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig index 80c1e76f9..d394a75a8 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig @@ -37,6 +37,9 @@