Symfony: встроенная подчиненная форма и созданный At / updatedAt: конфликт проверки - PullRequest
1 голос
/ 21 февраля 2020

У меня есть форма объекта, которая встраивает collectionType и подчиненные формы. Для того, чтобы требуемая опция работала, мне пришлось включить Auto_mapping

        class ClassePriceType extends AbstractType
    {
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            $builder
            ->add('priceform', PriceformType::class, [
                'data_class' => ClassePrice::class,
                'block_prefix' => 'mainprice_block'

            ]);
        }

        public function configureOptions(OptionsResolver $resolver)
        {
            $resolver->setDefaults([
                'data_class' => ClassePrice::class,
                'attr' => array(
                    'class' => 'fullwidth'
                )
            ]);
        }
    }

class PriceformType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
        ->add('pricecover', ChoiceType::class, [
            'label' => 'Price type',
            'placeholder' => 'Select a price option',
            'choices' => [ 'Global' => '1' ,'Step' => '2'],
            'required' => true
        ])
        ->add('rangesubform', RangesubformType::class, [
            'data_class' => ClassePrice::class,
            'block_prefix' => 'range_block'

        ])
        ->add('pricesubform', PricesubformType::class, [
            'data_class' => ClassePrice::class,
            'block_prefix' => 'price_block'
        ]);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'inherit_data' => true
        ]);
    }
}

class RangesubformType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
        ->add('rangetype', EntityType::class, [
            'class' => Ptur::class,
            'label' => 'Step type',
            'choice_translation_domain'=> true,
            'required' => true
        ])
        ->add('rangeformat', EntityType::class, [
                'class' => Format::class,
                'label' => 'Format',
                'required' => true
        ])
        ->add('rangemin', IntegerType::class, [
            'label' => 'Range min',
            'required' => true
        ]);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'inherit_data' => true,
            'attr' => array(
                'class' => 'form-horizontal'
            )
        ]);
    }
}

framework:
    validation:
        email_validation_mode: html5

        # Enables validator auto-mapping support.
        # For instance, basic validation constraints will be inferred from Doctrine's metadata.
        auto_mapping:
            App\Entity\: []
        enabled: 
            true   

. В своих энтеитах я также использую автоматическую генерацию createAt / updatedAt, созданную

use Gedmo\Timestampable\Traits\TimestampableEntity;
use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
use Gedmo\Mapping\Annotation as Gedmo;

Проблема в том, что с активацией auto_mapping я получил ошибку валидатора при создании ввода новой сущности.

Ответы [ 2 ]

0 голосов
/ 24 февраля 2020

Убедитесь, что ваш объект действителен внутри класса:

public function __construct()
{
    $this->createdAt = new DateTime();
    $this->updatedAt = new DateTime();
}
0 голосов
/ 24 февраля 2020

Установите время в вашей сущности так:

    /**
 * @var datetime $created_at
 *
 * @Orm\Column(type="datetime")
 */
protected $created_at;

/**
 * @var datetime $updated_at
 *
 * @Orm\Column(type="datetime", nullable = true)
 */
protected $updated_at;

/**
 * @orm\PrePersist
 */
public function onPrePersist()
{
    $this->created_at = new \DateTime("now");
}

/**
 * @Orm\PreUpdate
 */
public function onPreUpdate()
{
    $this->updated_at = new \DateTime("now");
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...