D
D
Daria Motorina2022-02-08 22:32:14
css
Daria Motorina, 2022-02-08 22:32:14

How to override the properties of an existing field in an inherited form in a Form Component?

Symfony 6.0.
I can not find an example in the documentation or on SO - how can I override the properties of one field in an inherited form in symphony? Using form events does not seem to be a very suitable tool, making two forms in parallel from the base one is inefficient.
Example:

<?php

class ArticleFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('title', TextType::class, ['help' => 'Choose something catchy'])
            ->add('content', null, ['rows' => 15]);
    }
}

class CustomArticleFormType extends ArticleFormType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('content', null, ['rows' => 25]);

        parent::buildForm($builder, $options);
    }
}


Please share links to a solution to a similar question, I don’t understand how to find it - the examples in the documentation talk about either FormExtension or form events, but they are needed for other tasks.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Serj-One, 2016-02-02
@Grizzy

<div class="example"></div>

.example {
  width: 300px;
  height: 50px;
  background: yellow;
  cursor: pointer;
  position: relative;

  margin: 50px auto;
}
.example:before {
  content: '';
  display: block;
  width: 0;
  height: 5px;
  background: red;
  position: absolute;
  left: 0;
  bottom: 0;
  transition: .5s;
}
.example:hover:before {
  width: 100%;
}

codepen.io/anon/pen/vLarpB

M
make_dev, 2016-02-04
@make_dev

Here are the ready made solutions. You can customize for your purposes.
Here is 1 option.
Effect No. 10, on a blue background
Here is the 2nd option.
Effect #3 Surinami

A
Anton Shamanov, 2022-02-21
@SilenceOfWinter

I'm not a symphony expert, but this won't work - you must first call parent::buildForm(); and then replace $builder->add(content', $builder->get('content')->getType(), $builder->get('content')->getOptions()),
and from banal LSP'shnogo - you can always inherit the class and expand the visibility of its properties.
+ one of the symphony developers said that this is an outdated way and you need to pass a builder, not a string, but it's better to talk to them yourself, I don't always understand them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question