How to pass data to formMapper method in configureFormFields method using Symfony

I want to pass a form method configureFormFields()to a Twig file, and I use this data in a twig file using formMapper. I use the default Sonata Admin and Overwrite template without a special presentation template. Below is my code:

Controller Code:

protected function configureFormFields(FormMapper $formMapper)
{
    $container = $this->getConfigurationPool()->getContainer();
    $entityManager = $container->get('doctrine.orm.entity_manager');
    $subject = $this->getSubject();            
    $formMapper->add('fieldValue',NumberType::class,array('label'=>'Other Country','required'=>true))->add('id','hidden',array('data' =>'1'));
}

View Twig File Code:

 <div class="col-lg-12 col-ms-12 col-sm-12">               
     <div class="col-lg-12 col-ms-12 col-sm-12">               
         <h3>For Others Country</h3>            
     </div>    
    <div class="col-lg-12 col-ms-12 col-sm-12">
        <div class="form-group {% if form_errors(form.fieldValue) %}has-error{% endif %}">
            {{ form_label(form.fieldValue, 'Other Country'|trans, {'label_attr': {'class': 'control-label'}}) }}<span class="asterik"></span>
            {{ form_widget(form.fieldValue, {'attr': {'class': 'form-control phonecode_field','data-placeholder':'Other Country'|trans}}) }}
            <span class="help-block {% if form_errors(form.fieldValue) %}has-error{% endif %}">{{ form_errors(form.fieldValue) }}</span>
        </div>
    </div>
</div>

In the above code, I set the value of the text field fieldValue and the Pass value from the controller, so how could this be done?

+4
source share

Source: https://habr.com/ru/post/1688583/


All Articles