[closing motive] add an hierarchy + admin section for closing motives

This commit is contained in:
2020-03-12 12:19:15 +01:00
parent ceb3b5e955
commit e59f58f461
26 changed files with 712 additions and 41 deletions

View File

@@ -14,8 +14,7 @@ use Symfony\Component\Form\Extension\Core\Type\DateType;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Chill\MainBundle\Form\Type\UserPickerType;
use Symfony\Component\Security\Core\Role\Role;
use Chill\PersonBundle\Form\Type\ClosingMotiveType;
use Chill\PersonBundle\Form\Type\ClosingMotivePickerType;
class AccompanyingPeriodType extends AbstractType
{
@@ -72,7 +71,7 @@ class AccompanyingPeriodType extends AbstractType
) {
$form->add('closingDate', DateType::class, array('required' => true,
'widget' => 'single_text', 'format' => 'dd-MM-yyyy'));
$form->add('closingMotive', ClosingMotiveType::class);
$form->add('closingMotive', ClosingMotivePickerType::class);
}
});

View File

@@ -0,0 +1,67 @@
<?php
/*
*
* Copyright (C) 2014-2020, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\PersonBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Chill\PersonBundle\Form\Type\ClosingMotivePickerType;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
/**
*
*
*/
class ClosingMotiveType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TranslatableStringFormType::class, [
'label' => 'Nom'
])
->add('active', CheckboxType::class, [
'label' => 'Actif ?',
'required' => false
])
->add('ordering', NumberType::class, [
'label' => 'Ordre d\'apparition',
'required' => true,
'scale' => 5
])
->add('parent', ClosingMotivePickerType::class, [
'label' => 'Parent',
'required' => false,
'placeholder' => 'closing_motive.any parent',
'multiple' => false,
'only_leaf' => false
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefault('class', \Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive::class)
;
}
}

View File

@@ -9,13 +9,15 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension;
use Symfony\Component\OptionsResolver\Options;
use Chill\PersonBundle\Repository\ClosingMotiveRepository;
/**
* A type to add a closing motive
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class ClosingMotiveType extends AbstractType
class ClosingMotivePickerType extends AbstractType
{
/**
@@ -24,9 +26,26 @@ class ClosingMotiveType extends AbstractType
*/
protected $translatableStringHelper;
public function __construct(TranslatableStringHelper $translatableStringHelper)
{
/**
*
* @var ChillEntityRenderExtension
*/
protected $entityRenderExtension;
/**
*
* @var ClosingMotiveRepository
*/
protected $repository;
public function __construct(
TranslatableStringHelper $translatableStringHelper,
ChillEntityRenderExtension $chillEntityRenderExtension,
ClosingMotiveRepository $closingMotiveRepository
) {
$this->translatableStringHelper = $translatableStringHelper;
$this->entityRenderExtension = $chillEntityRenderExtension;
$this->repository = $closingMotiveRepository;
}
public function getBlockPrefix()
@@ -46,11 +65,17 @@ class ClosingMotiveType extends AbstractType
'empty_data' => null,
'placeholder' => 'Choose a motive',
'choice_label' => function(ClosingMotive $cm) {
return $this->translatableStringHelper
->localize($cm->getName());
}
return $this->entityRenderExtension->renderString($cm);
},
'only_leaf' => true
)
);
$resolver
->setAllowedTypes('only_leaf', 'bool')
->setNormalizer('choices', function (Options $options) {
return $this->repository->getActiveClosingMotive($options['only_leaf']);
});
}
}