Cause I don't like twig template engine this example only for PHP templating
What you need is to make:
New TestBundleFormExtensionCoreTypeDateRangeType
which extends SymfonyComponentFormAbstractType
Here you should:
a. write your own getParent, getName, buildForm methods
b. getParent return 'field'
c. getName return 'daterange'
d. buildForm has $builder->add('start', ...)->add('end', ...)->setAttribute('widget', 'daterange')
Add it to the DI (config.yml as example)
services:
form.type.daterange:
class: TestBundleFormExtensionCoreTypeDateRangeType
tags:
- { name: form.type, alias: daterange }
Create new widget for it in TestBundle/Resources/views/Form/daterange_widget.html.php
you can take date widget as example. Src/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/date_widget.html.php
Add to config (config.yml as example)
framework:
templating:
form:
resources:
- 'TestBundle:Form'
And for more widget customization as nefo_x said check form customization.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…