ruwork / polyfill-form-dti
Symfony Form polyfill adding input=datetime_immutable to date types.
Installs: 49 675
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 5
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.5
- symfony/form: ^2.8 || ^3.0 || ^4.0
Requires (Dev)
- doctrine/orm: ^2.4.8
- symfony/phpunit-bridge: ^2.8 || ^3.0 || ^4.0
This package is auto-updated.
Last update: 2024-12-12 07:42:42 UTC
README
This package is a polyfill for my pull request adding input=datetime_immutable
option to the Symfony date and time form types.
Works with PHP >=5.5
and Symfony >=2.8
.
If you use Symfony Framework have a look at the corresponding ruwork/polyfill-form-dti-bundle.
Installation
composer require ruwork/polyfill-form-dti
Usage
<?php use Ruwork\PolyfillFormDTI\DTIExtension; use Ruwork\PolyfillFormDTI\Guesser\DoctrineOrmDTIGuesser; use Symfony\Component\Form\Extension\Core\Type\DateTimeType; use Symfony\Component\Form\Extension\Core\Type\DateType; use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\Form\Extension\Core\Type\TimeType; use Symfony\Component\Form\Forms; /** @var \Doctrine\Common\Persistence\ManagerRegistry $registry */ $factory = Forms::createFormFactoryBuilder() ->addExtension(new DTIExtension()) // Optionally you can add a Doctrine ORM guesser // to guess input=datetime_immutable for Doctrine 2.6 immutable date types. ->addTypeGuesser(new DoctrineOrmDTIGuesser($registry)) ->getFormFactory(); $form = $factory ->createBuilder(FormType::class, [ 'datetime' => new \DateTimeImmutable('1828-09-09 12:00:00'), 'date' => new \DateTimeImmutable('1860-01-29'), 'time' => new \DateTimeImmutable('23:59'), ]) ->add('datetime', DateTimeType::class, [ 'input' => 'datetime_immutable', ]) ->add('date', DateType::class, [ 'input' => 'datetime_immutable', ]) ->add('time', TimeType::class, [ 'input' => 'datetime_immutable', ]) ->getForm();
Testing
vendor/bin/simple-phpunit