| 1: | <?php |
| 2: | namespace TIC\CoreBundle\Base; |
| 3: | |
| 4: | use Symfony\Component\Form\AbstractType as BaseType; |
| 5: | use Symfony\Component\OptionsResolver\OptionsResolver; |
| 6: | |
| 7: | use Symfony\Contracts\Translation\TranslatorInterface; |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | abstract class TICFormType extends BaseType |
| 14: | { |
| 15: | |
| 16: | use \TIC\CoreBundle\Traits\ContextProperties; |
| 17: | |
| 18: | protected $data_class; |
| 19: | protected $form_alias; |
| 20: | |
| 21: | protected $translator; |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | public function __construct(TranslatorInterface $translator) |
| 27: | { |
| 28: | $this->translator = $translator; |
| 29: | |
| 30: | |
| 31: | $this->setContextProperties('Form|Type'); |
| 32: | |
| 33: | if (null === $this->data_class) |
| 34: | $this->data_class = $this->ctxRoot . "\\Entity\\" . $this->ctxName; |
| 35: | |
| 36: | if (null === $this->form_alias) |
| 37: | $this->form_alias = $this->ctxRoute . "form"; |
| 38: | } |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | public function configureOptions(OptionsResolver $resolver) |
| 44: | { |
| 45: | $defaults = array(); |
| 46: | if ($this->data_class) $defaults['data_class'] = $this->data_class; |
| 47: | $resolver->setDefaults($defaults); |
| 48: | } |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | public function getBlockPrefix(): string |
| 54: | { |
| 55: | if ($this->form_alias) return $this->form_alias; |
| 56: | return parent::getBlockPrefix(); |
| 57: | } |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | protected function trans(string $token, array $parameters = []): string |
| 63: | { |
| 64: | return $this->translator->trans($token, $parameters); |
| 65: | } |
| 66: | |
| 67: | } |
| 68: | |