mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fix: Use TranslatableStringHelperInterface
.
This commit is contained in:
parent
cc9ce4167f
commit
b722106616
@ -1,42 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\AMLI\BudgetBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\AMLI\BudgetBundle\Config\ConfigRepository;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\AMLI\BudgetBundle\Entity\Charge;
|
||||
|
||||
class ChargeType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var ConfigRepository
|
||||
*/
|
||||
protected $configRepository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
protected ConfigRepository $configRepository;
|
||||
|
||||
protected TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
public function __construct(
|
||||
ConfigRepository $configRepository,
|
||||
TranslatableStringHelper $translatableStringHelper
|
||||
ConfigRepository $configRepository,
|
||||
TranslatableStringHelperInterface $translatableStringHelper
|
||||
) {
|
||||
$this->configRepository = $configRepository;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
@ -45,24 +37,23 @@ class ChargeType extends AbstractType
|
||||
'placeholder' => 'Choose a charge type'
|
||||
])
|
||||
->add('amount', MoneyType::class)
|
||||
->add('comment', TextAreaType::class, [
|
||||
->add('comment', TextareaType::class, [
|
||||
'required' => false
|
||||
])
|
||||
;
|
||||
|
||||
]);
|
||||
|
||||
if ($options['show_start_date']) {
|
||||
$builder->add('startDate', ChillDateType::class, [
|
||||
'label' => 'Start of validity period'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
if ($options['show_end_date']) {
|
||||
$builder->add('endDate', ChillDateType::class, [
|
||||
'required' => false,
|
||||
'label' => 'End of validity period'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
if ($options['show_help']) {
|
||||
$builder->add('help', ChoiceType::class, [
|
||||
'choices' => [
|
||||
@ -77,48 +68,39 @@ class ChargeType extends AbstractType
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function getTypes()
|
||||
{
|
||||
$charges = $this->configRepository
|
||||
->getChargesLabels();
|
||||
|
||||
|
||||
// rewrite labels to filter in language
|
||||
foreach ($charges as $key => $labels) {
|
||||
$charges[$key] = $this->translatableStringHelper->localize($labels);
|
||||
}
|
||||
|
||||
|
||||
\asort($charges);
|
||||
|
||||
|
||||
return \array_flip($charges);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Chill\AMLI\BudgetBundle\Entity\Charge',
|
||||
'data_class' => Charge::class,
|
||||
'show_start_date' => true,
|
||||
'show_end_date' => true,
|
||||
'show_help' => true
|
||||
));
|
||||
|
||||
|
||||
$resolver
|
||||
->setAllowedTypes('show_start_date', 'boolean')
|
||||
->setAllowedTypes('show_end_date', 'boolean')
|
||||
->setAllowedTypes('show_help', 'boolean')
|
||||
;
|
||||
->setAllowedTypes('show_help', 'boolean');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'chill_amli_budgetbundle_charge';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\AMLI\BudgetBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
@ -10,32 +13,22 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\AMLI\BudgetBundle\Config\ConfigRepository;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
|
||||
class ResourceType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var ConfigRepository
|
||||
*/
|
||||
protected $configRepository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
protected ConfigRepository $configRepository;
|
||||
|
||||
protected TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
public function __construct(
|
||||
ConfigRepository $configRepository,
|
||||
TranslatableStringHelper $translatableStringHelper
|
||||
ConfigRepository $configRepository,
|
||||
TranslatableStringHelperInterface $translatableStringHelper
|
||||
) {
|
||||
$this->configRepository = $configRepository;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
@ -45,17 +38,16 @@ class ResourceType extends AbstractType
|
||||
'label' => 'Resource element type'
|
||||
])
|
||||
->add('amount', MoneyType::class)
|
||||
->add('comment', TextAreaType::class, [
|
||||
->add('comment', TextareaType::class, [
|
||||
'required' => false
|
||||
])
|
||||
;
|
||||
|
||||
]);
|
||||
|
||||
if ($options['show_start_date']) {
|
||||
$builder->add('startDate', ChillDateType::class, [
|
||||
'label' => 'Start of validity period'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
if ($options['show_end_date']) {
|
||||
$builder->add('endDate', ChillDateType::class, [
|
||||
'required' => false,
|
||||
@ -63,25 +55,7 @@ class ResourceType extends AbstractType
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function getTypes()
|
||||
{
|
||||
$resources = $this->configRepository
|
||||
->getResourcesLabels();
|
||||
|
||||
// rewrite labels to filter in language
|
||||
foreach ($resources as $key => $labels) {
|
||||
$resources[$key] = $this->translatableStringHelper->localize($labels);
|
||||
}
|
||||
|
||||
asort($resources);
|
||||
|
||||
return \array_flip($resources);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
@ -89,20 +63,29 @@ class ResourceType extends AbstractType
|
||||
'show_start_date' => true,
|
||||
'show_end_date' => true
|
||||
));
|
||||
|
||||
|
||||
$resolver
|
||||
->setAllowedTypes('show_start_date', 'boolean')
|
||||
->setAllowedTypes('show_end_date', 'boolean')
|
||||
;
|
||||
->setAllowedTypes('show_end_date', 'boolean');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'chill_amli_budgetbundle_resource';
|
||||
}
|
||||
|
||||
private function getTypes()
|
||||
{
|
||||
$resources = $this->configRepository
|
||||
->getResourcesLabels();
|
||||
|
||||
// rewrite labels to filter in language
|
||||
foreach ($resources as $key => $labels) {
|
||||
$resources[$key] = $this->translatableStringHelper->localize($labels);
|
||||
}
|
||||
|
||||
asort($resources);
|
||||
|
||||
return \array_flip($resources);
|
||||
}
|
||||
}
|
||||
|
@ -1,83 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2014-2021, 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/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Form\SocialWork;
|
||||
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
|
||||
/**
|
||||
* Class SocialIssueType
|
||||
*
|
||||
* @package Chill\PersonBundle\Form
|
||||
*/
|
||||
class SocialIssueType extends AbstractType
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
protected TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper) {
|
||||
public function __construct(
|
||||
TranslatableStringHelperInterface $translatableStringHelper
|
||||
) {
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('title', TranslatableStringFormType::class, [
|
||||
'label' => 'Nom'
|
||||
])
|
||||
|
||||
->add('parent', EntityType::class, [
|
||||
'class' => SocialIssue::class,
|
||||
'required' => false,
|
||||
'choice_label' => function (SocialIssue $issue) {
|
||||
return $this->translatableStringHelper->localize($issue->getTitle());
|
||||
}
|
||||
'choice_label' => static fn (SocialIssue $issue): ?string => $this->translatableStringHelper->localize($issue->getTitle())
|
||||
])
|
||||
|
||||
->add('desactivationDate', DateType::class, [
|
||||
'attr' => ['class' => 'datepicker'],
|
||||
'widget'=> 'single_text',
|
||||
'format' => 'dd-MM-yyyy',
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OptionsResolver $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefault('class', SocialIssue::class)
|
||||
;
|
||||
$resolver->setDefault('class', SocialIssue::class);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user