How to change the shape field in Subscriber



  • I do. FormTypewhere there is a field. When the field is created, the field must be mandatory, editing is not mandatory. Subscriber this one. type

    Field in FormType

     ->add("logo", FileType::class, [
                    "label"    => "Health Plans logo",
                    "mapped"   => true,
                    "required" => true
                ])
    

    postSetData I take the form. $form->get('config')->get('logo') - That's it. FormType Total FormType I can see. So I'm taking the field.

    How do I set up the field? mapped Object received value false ?



    1. Disclosure: required It's just that HTML puts it in. required and a couple of plugs. This option has nothing to do with validation. http://symfony.com/doc/current/reference/forms/types/form.html#required
    2. To solve your problem in her current state, you can use the transmitted option. datae.g.

      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          /** @var MyEntity $data */
          $data = $options['data'];
          // ...
          ->add(
              "logo", 
              FileType::class, 
              [
                  "label"    => "Health Plans logo",
                  "mapped"   => true,
                  // данных нет или у них отсутствует id (т.е. ещё не создана)
                  "required" => $data === null || empty($data->getId())
              ]
          )
      



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2