src/Eccube/Form/Type/Master/PrefType.php line 40

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Form\Type\Master;
  13. use Eccube\Form\Type\MasterType;
  14. use Symfony\Component\Form\AbstractType;
  15. use Symfony\Component\OptionsResolver\OptionsResolver;
  16. use Symfony\Contracts\Translation\TranslatorInterface;
  17. /**
  18.  * Class PrefType
  19.  */
  20. class PrefType extends AbstractType
  21. {
  22.     private $translator;
  23.     public function __construct(TranslatorInterface $translator)
  24.     {
  25.         $this->translator $translator;
  26.     }
  27.     /**
  28.      * {@inheritdoc}
  29.      */
  30.     public function configureOptions(OptionsResolver $resolver)
  31.     {
  32.         $resolver->setDefaults([
  33.             'class' => 'Eccube\Entity\Master\Pref',
  34.             'placeholder' => 'common.select__pref',
  35.             'choice_label' => function ($pref) {
  36.                 // 翻訳キーを使用
  37.                 return $this->translator->trans('pref.' $pref->getId(), [], 'messages');
  38.             },
  39.         ]);
  40.     }
  41.     /**
  42.      * {@inheritdoc}
  43.      */
  44.     public function getBlockPrefix()
  45.     {
  46.         return 'pref';
  47.     }
  48.     /**
  49.      * {@inheritdoc}
  50.      */
  51.     public function getParent()
  52.     {
  53.         return MasterType::class;
  54.     }
  55. }