问题
I use symfony 3.4 and easycorp/easyadmin-bundle 1.17
Config form easyadmin :
form:
fields:
- { type: 'group', label: 'Basic Information', icon: 'envelope-o', css_class: 'col-sm-8' }
- { property: 'title' }
- { property: 'status' }
- { type: 'group', label: 'Legal Information', icon: 'briefcase', css_class: 'col-sm-4' }
- { property: 'pdfFile', type: 'file' }
In AdminController :
/**
* @param $entity
* @param $view
* @return \Symfony\Component\Form\FormBuilder
*/
protected function createQuotationEntityFormBuilder($entity, $view)
{
$formBuilder = parent::createEntityFormBuilder($entity, $view);
$formBuilder->add('customer', EntityType::class, array(
'class' => 'AppBundle:Person',
'label' => false,
'by_reference' => false,
'query_builder' => function(EntityRepository $er) {
$user = $this->get('security.token_storage')->getToken()->getUser();
$query = $er->createQueryBuilder('person')
->leftJoin('person.userCreated', 'user')
->andWhere('person.type = :type')
->setParameter('type', 2) // à changer c'est en dur!
;
if (in_array("ROLE_ADMIN", $user->getRoles())) {
$query->andWhere('user.company = :company');
$query->setParameter('company', $user->getCompany());
} else {
$query->andWhere('user.id = :user');
$query->setParameter('user', $user->getId());
}
return $query;
},
'multiple' => false,
'expanded' => false,
'attr' => ['data-widget' => 'select2'],
'placeholder' => 'label.form.empty_value'
)
);
return $formBuilder;
}
In my form builder I want to add a field "customer" but it appears at the end, the rendering of the form is not good (cf. image), someone would have an idea so that I can insert the field "customer" after the field "status"
Thanks in advance
回答1:
Render it manually:
{{ form_start(form) }}
{{ form_row(form.title) }}
{{ form_row(form.status) }}
{{ form_row(form.client) }}
...
{{ form_end(form) }}
PS: the group option that you've added in the easyadmin config file will be ignored.
来源:https://stackoverflow.com/questions/52313338/symfony-easyadmin-custom-form-builder