enable autoloading for form in person bundle

This commit is contained in:
2021-09-01 17:04:24 +02:00
parent 41d76542b4
commit 2450655452
3 changed files with 15 additions and 82 deletions

View File

@@ -20,6 +20,9 @@
namespace Chill\PersonBundle\Form\Type;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\MaritalStatus;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Chill\MainBundle\Form\Type\DataTransformer\ObjectToIdTransformer;
@@ -35,15 +38,13 @@ use Chill\MainBundle\Form\Type\Select2ChoiceType;
*/
class Select2MaritalStatusType extends AbstractType
{
/** @var RequestStack */
private $requestStack;
private EntityManagerInterface $em;
/** @var ObjectManager */
private $em;
private TranslatableStringHelper $translatableStringHelper;
public function __construct(RequestStack $requestStack,ObjectManager $em)
public function __construct(TranslatableStringHelper $translatableStringHelper, EntityManagerInterface $em)
{
$this->requestStack = $requestStack;
$this->translatableStringHelper = $translatableStringHelper;
$this->em = $em;
}
@@ -63,18 +64,17 @@ class Select2MaritalStatusType extends AbstractType
public function configureOptions(OptionsResolver $resolver)
{
$locale = $this->requestStack->getCurrentRequest()->getLocale();
$maritalStatuses = $this->em->getRepository('Chill\PersonBundle\Entity\MaritalStatus')->findAll();
$choices = array();
foreach ($maritalStatuses as $ms) {
$choices[$ms->getId()] = $ms->getName()[$locale];
$choices[$ms->getId()] = $this->translatableStringHelper->localize($ms->getName());
}
asort($choices, SORT_STRING | SORT_FLAG_CASE);
$resolver->setDefaults(array(
'class' => 'Chill\PersonBundle\Entity\MaritalStatus',
'class' => MaritalStatus::class,
'choices' => array_combine(array_values($choices),array_keys($choices))
));
}