Hi,
i am new with the easyadminbundle and symfony and went dark looking for something (which at first were errors linked to the entity generator code) but now this time, yes, i feel like i am loosing it (i mean my hair)
So basically, i want to make an invoice statement: an invoice has multiple products lines
when i create/show the invoice, i want to be able to enter a new productline but where all fields would be in a single row, next row would be a new productline. something like an "excel format"
my easyadmin file for the invoice part looks like this:
Invoice:
class: AppBundle\Entity\Invoice
list:
fields:
- invoiceDate
- company
- invoicetype
- vatstatus
- internalreference
- financialstatus
form:
fields:
- {type: 'group', css_class: 'col-sm-6', label: 'Informations Generales' }
- { property: 'company', label: 'de/pour', type: 'easyadmin_autocomplete' }
- { property: 'invoicedate', type: 'date' }
- { property: 'internalreference', type: 'text'}
- { property: 'invoicetype', label: 'Type de facture', type: 'easyadmin_autocomplete' }
- { type: 'group', css_class: 'col-sm-3', label: 'Information de paiement' }
- { property: 'vatstatus', type_options: { query_builder: 'AppBundle\Repository\StateRepository::VATStatus'}}
- { property: paymentmethod, type: choice, type_options: { choices: {'Cash' : 'Cash','Transfer' : 'Transfer','Paypal' : 'Paypal', 'MercadoPago' : 'MercadoPago','Otros' : 'Otros'} }}
- { property: 'financialstatus', type_options: { query_builder: 'AppBundle\Repository\StateRepository::OrderStatus'}}
- { property: 'isvisible', label: 'declar茅'}
- { type: 'group', css_class: 'new-row' }
- { type: 'group', css_class: 'col-sm-3', label: 'Statut de l envoi' }
- { property: 'deliverydate', label: 'date livraison', type: 'date' }
- { property: 'deliverystatus', type_options: { query_builder: 'AppBundle\Repository\StateRepository::DeliveryStatus'}}
- { type: 'group', css_class: 'new-row' }
- { type: 'group', css_class: 'col-sm-9', label: 'Detail de la commance' }
- { property: 'invoiceproducts', label: 'Produits', type: 'collection', type_options: {entry_type: 'AppBundle\Form\InvoiceProductType', by_reference: false} }
and my InvoiceProductType form:
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
class InvoiceProductType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('product',
EntityType::class ,
array('class' => 'AppBundle\Entity\Product',
'attr' => array('class' => 'col-sm-2')))
->add('quantity', NumberType::class ,array('attr' => array('class' => 'col-sm-1')))
->add('unit', EntityType::class ,
array('class' => 'AppBundle\Entity\Unit',
'attr' => array('class' => 'col-sm-1')))
->add('price', NumberType::class ,array('attr' => array('class' => 'col-sm-1')))
->add('vattype', EntityType::class ,
array('class' => 'AppBundle\Entity\VatTable',
'attr' => array('class' => 'col-sm-2')))
;
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\InvoiceProduct',
array('attr' => array('class' => 'col-sm-6'))
));
}
}
i haven t found which template to modify... i guess i should use something like at https://github.com/javiereguiluz/EasyAdminBundle/issues/1243, or override the blocks {% block form_row -%}
So i check... and found that the form_widget block contains a call to its parent which i guess means i have to look at the code of the same block in the form_div_layout.html.twig... file i don t find...
Any clue ?
@bertinl0609 sadly I understand that you have problems with this because EasyAdmin relies on Symfony's Form component to solve it. Forms are arguably the most difficult part of Symfony.
To customize the form appearance, you have to read this article of the official Symfony Docs that explain how to create a form theme. Then you have to tell EasyAdmin that you want to use your own theme for the forms as explained in this section of our docs.
The bad news is that it will take you some time to do this because of the complexity of Symfony's Forms. The good news is that the solution (creating a form them) is something related to Symfony, not EasyAdmin, so you can reuse it in the rest of the Symfony application and with other bundles.
I'm closing this issue as "fixed" for now. If you don't agree, please reopen. Thanks!
Sorry, i may have expressed myself uncorrectly...
The theme is nice, it is just for some parts where i want to override the way it is shown and make the edit part much more like an official bill.
From what i understand, when an edit form of an entity with children entities is shown (like my case) they use the same piece of code to render the form
The upper part of the image is the entity itself, the rendering underneath is the children entity collection

I don t want to generate a full new theme, just generate a small template for such cases
I would then specify
{ property: 'invoiceproducts', label: 'Produits', type: 'collection', type_options: {entry_type: 'AppBundle\Form\InvoiceProductType', by_reference: false}, template: '@App/easy_admin/tablelikerendering.html.twig' }
in this file i suppose i would put something like the easyadmin_widget but modify it.
I ll try and post by
@bertinl0609 you don't need to create an entire form theme to redesign just the collection widget. Your form them will be a very small Twig template with just the needed fragment to override that.
Hi, it took me a while...
i am explaining what i do in case someone else looks for the same:
1 Create a twig template in App/resources/easy_admin called tabular.html.twig
`
{% block collection_widget %}
{% spaceless %}
{% if form.vars.allow_delete is defined and form.vars.allow_delete %}
{% set allow_delete = true %}
{% else %}
{% set allow_delete = false %}
{% endif %}
<div {{ block('widget_container_attributes') }} class="protoype">
{{ form_errors(form) }}
<table class="subtable table">
<thead>
<tr class="headers" >
{% if form.children|length > 0 %}
{% if form.children[0]|length > 0 %}
{% set header = form.children[0] %}
{{ block('collection_header') }}
{% endif %}
{% endif %}
</tr>
</thead>
<tbody class="container_rows">
{% for rows in form %}
{% spaceless %}
{% if rows.children|length > 0 %}
{% set body = rows %}
{{ block('collection_body') }}
{% endif %}
{% endspaceless %}
{% endfor %}
</tbody>
</table>
{% if prototype is defined %}
{% if form.vars.attr['data-add_label'] is defined %}
{% set add_label = form.vars.attr['data-add_label'] ~ ' ' %}
{% else %}
{% set add_label = 'Ajouter ' %}
{% endif %}
<a href="#/" class="add_button btn btn-default btn-sm pull-right">{{ add_label }}<i class="fa fa-plus"></i></a>
{% endif %}
<br>
</div>
</div>
{% endspaceless %}
{% endblock collection_widget %}
{% block collection_header %}
{% for field in header %}
{% block collection_body %}
{% spaceless %}
{% set fieldNum = 1 %}
3 search the name of your subform (my case: invoiceproducts) and add the line
{% form_theme form.invoiceproducts 'easy_admin/tabular.html.twig' %} in that edit template...
My edit file looks like:
`{% form_theme form with easyadmin_config('design.form_theme') %}
{% set _entity_config = easyadmin_entity(app.request.query.get('entity')) %}
{% set _entity_id = attribute(entity, _entity_config.primary_key_field_name) %}
{% set _trans_parameters = { '%entity_name%': _entity_config.name|trans, '%entity_label%': _entity_config.label|trans, '%entity_id%': _entity_id } %}
{% extends _entity_config.templates.layout %}
{% block body_id 'easyadmin-edit-' ~ _entity_config.name ~ '-' ~ _entity_id %}
{% block body_class 'edit edit-' ~ _entity_config.name|lower %}
{% block content_title %}
{% spaceless %}
{% set _default_title = 'edit.page_title'|trans(_trans_parameters, 'EasyAdminBundle') %}
{{ _entity_config.edit.title is defined ? _entity_config.edit.title|trans(_trans_parameters) : _default_title }}
{% endspaceless %}
{% endblock %}
{% form_theme form.invoiceproducts 'easy_admin/tabular.html.twig' %}
{% block main %}
{% block entity_form %}
{{ form(form) }}
{% endblock entity_form %}
{% block delete_form %}
{{ include('@EasyAdmin/default/includes/_delete_form.html.twig', {
view: 'edit',
referer: app.request.query.get('referer', ''),
delete_form: delete_form,
_trans_parameters: _trans_parameters,
_entity_config: _entity_config,
}, with_context = false) }}
{% endblock delete_form %}
{% endblock %}
{% block body_javascript %}
{{ parent() }}
<script type="text/javascript">
$(function() {
$('.edit-form').areYouSure({ 'message': '{{ 'form.are_you_sure'|trans({}, 'EasyAdminBundle')|e('js') }}' });
$('.form-actions').easyAdminSticky();
$('a.action-delete').on('click', function(e) {
e.preventDefault();
$('#modal-delete').modal({ backdrop: true, keyboard: true })
.off('click', '#modal-delete-button')
.on('click', '#modal-delete-button', function () {
$('#delete-form').trigger('submit');
});
});
// Select2 widget is only enabled for the <select> elements which explicitly ask for it
$('#main').find('form select[data-widget="select2"]').select2({
theme: 'bootstrap'
});
});
</script>
{% endblock %}
`
@bertinl0609
```
your code
```
(between ``` , ```)
or
your code
or
```twig
{# your code #}
```
Most helpful comment
@bertinl0609
(between
```,```)or
or