Merge remote-tracking branch 'origin/stable'

This commit is contained in:
Julien Fastré 2019-06-17 12:54:43 +02:00
commit 8c17277e9a
3 changed files with 69 additions and 8 deletions

View File

@ -50,7 +50,13 @@ Version 1.5.7
- add css layout for boxes ;
- collect supplementary query parameters in SearchController ;
Branch amli_impersonate
=======================
Version 1.5.8
=============
- allow to remove interval units from DateInterval
Branch master
=============
- add optionnal impersonate feature (if firewall option switch_user is true) ;

View File

@ -23,9 +23,38 @@ use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Chill\MainBundle\Form\Type\DataTransformer\DateIntervalTransformer;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
/**
* Show a dateInterval type
*
* Options:
*
* - `unit_choices`: an array of available units choices.
*
* The oiriginal `unit_choices` are :
* ```
* [
* 'Days' => 'D',
* 'Weeks' => 'W',
* 'Months' => 'M',
* 'Years' => 'Y'
* ]
* ```
*
* You can remove one or more entries:
*
* ```
* $builder
* ->add('duration', DateIntervalType::class, array(
* 'unit_choices' => [
* 'Years' => 'Y',
* 'Months' => 'M',
* ]
* ));
* ```
*
*/
class DateIntervalType extends AbstractType
@ -42,16 +71,39 @@ class DateIntervalType extends AbstractType
]
])
->add('unit', ChoiceType::class, [
'choices' => [
'Days' => 'D',
'Weeks' => 'W',
'Months' => 'M',
'Years' => 'Y'
],
'choices' => $options['unit_choices'],
'choices_as_values' => true
])
;
$builder->addModelTransformer(new DateIntervalTransformer());
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefined('unit_choices')
->setDefault('unit_choices', [
'Days' => 'D',
'Weeks' => 'W',
'Months' => 'M',
'Years' => 'Y'
])
->setAllowedValues('unit_choices', function($values) {
if (FALSE === is_array($values)) {
throw new InvalidOptionsException("The value `unit_choice` should be an array");
}
$diff = \array_diff(\array_values($values), ['D', 'W', 'M', 'Y']);
if (count($diff) == 0) {
return true;
} else {
throw new InvalidOptionsException(sprintf("The values of the "
. "units should be 'D', 'W', 'M', 'Y', those are invalid: %s",
\implode(', ', $diff)));
}
})
;
}
}

View File

@ -39,6 +39,9 @@ Edit: Modifier
Update: Mettre à jour
Back to the list: Retour à la liste
#interval
Years: Années
#elements used in software
centers: centres
Centers: Centres