src/PN/Bundle/ProductBundle/Form/OccasionType.php
/**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
@param FormBuilderInterface $builder
@param array $options
@param FormBuilderInterface $builder @param array $options
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $postTypeModel = new PostTypeModel();
        $postTypeModel->add("description", "Description", ["required" => false]);
        $builder
            ->add('title')
            ->add('seo', SeoType::class)
            ->add('post', PostType::class, [
                "attributes" => $postTypeModel,
            ])
            ->add('startDate', TextType::class, [
                "label" => "Start Date",
                "required" => true,
                'attr' => ['data-date-format' => 'dd/mm/yyyy', "class" => "datepicker-future"],
            ])
            ->add('endDate', TextType::class, [
                "label" => "End Date",
                "required" => true,
                'attr' => ['data-date-format' => 'dd/mm/yyyy', "class" => "datepicker-future"],
                "constraints" => [
                    new GreaterThanOrEqual(["propertyPath" => "parent.all[startDate].data"]),
                ],
            ])
            ->add('active', CheckboxType::class, [
                "required" => false,
                "label" => "Active",
            ])
            ->add('translations', TranslationsType::class, [
                'entry_type' => OccasionTranslationType::class,
                "label" => false,
                'entry_language_options' => [
                    'en' => [
                        'required' => true,
                    ],
                ],
            ]);
        $builder->get('startDate')
            ->addModelTransformer(new CallbackTransformer(
                    function ($date) {
                        if ($date == null) {
                            return null;
                        }
                        return $date->format('d/m/Y');
                    }, function ($date) {
                    if ($date) {
                        return Date::convertDateFormatToDateTime($date, Date::DATE_FORMAT3);
                    }
                    return null;
                })
            );
        $builder->get('endDate')
            ->addModelTransformer(new CallbackTransformer(
                    function ($date) {
                        if ($date == null) {
                            return null;
                        }
                        return $date->format('d/m/Y');
                    }, function ($date) {
                    if ($date) {
                        return Date::convertDateFormatToDateTime($date, Date::DATE_FORMAT3);
                    }
                    return null;
                })
            );
    }
public function buildForm ( FormBuilderInterface $ builder , array $ options ) { $ postTypeModel = new PostTypeModel ( ) ; $ postTypeModel -> add ( " description " , " Description " , [ " required " => false ] ) ; $ builder -> add ( 'title' ) -> add ( 'seo' , SeoType :: class ) -> add ( 'post' , PostType :: class , [ " attributes " => $ postTypeModel , ] ) -> add ( 'startDate' , TextType :: class , [ " label " => " Start Date " , " required " => true , 'attr' => [ 'data-date-format' => 'dd/mm/yyyy' , " class " => " datepicker-future " ] , ] ) -> add ( 'endDate' , TextType :: class , [ " label " => " End Date " , " required " => true , 'attr' => [ 'data-date-format' => 'dd/mm/yyyy' , " class " => " datepicker-future " ] , " constraints " => [ new GreaterThanOrEqual ( [ " propertyPath " => " parent.all[startDate].data " ] ) , ] , ] ) -> add ( 'active' , CheckboxType :: class , [ " required " => false , " label " => " Active " , ] ) -> add ( 'translations' , TranslationsType :: class , [ 'entry_type' => OccasionTranslationType :: class , " label " => false , 'entry_language_options' => [ 'en' => [ 'required' => true , ] , ] , ] ) ; $ builder -> get ( 'startDate' ) -> addModelTransformer ( new CallbackTransformer ( function ( $ date ) { if ( $ date == null ) { return null ; } return $ date -> format ( 'd/m/Y' ) ; } , function ( $ date ) { if ( $ date ) { return Date :: convertDateFormatToDateTime ( $ date , Date :: DATE_FORMAT3 ) ; } return null ; } ) ) ; $ builder -> get ( 'endDate' ) -> addModelTransformer ( new CallbackTransformer ( function ( $ date ) { if ( $ date == null ) { return null ; } return $ date -> format ( 'd/m/Y' ) ; } , function ( $ date ) { if ( $ date ) { return Date :: convertDateFormatToDateTime ( $ date , Date :: DATE_FORMAT3 ) ; } return null ; } ) ) ; }
@param FormBuilderInterface $builder
 @param array $options
@param FormBuilderInterface $builder @param array $options
// transform the DateTime to a string // transform the string back to DateTime // transform the DateTime to a string // transform the string back to DateTime