diff --git a/DependencyInjection/SherlockodeSonataModularExtension.php b/DependencyInjection/SherlockodeSonataModularExtension.php index e0d0802..6476dc2 100644 --- a/DependencyInjection/SherlockodeSonataModularExtension.php +++ b/DependencyInjection/SherlockodeSonataModularExtension.php @@ -81,6 +81,17 @@ public function prepend(ContainerBuilder $container) ]; $container->prependExtensionConfig('sonata_admin', $config); + + $bundles = $container->getParameter('kernel.bundles'); + if (isset($bundles['SonataAdminBundle'])) { + $config = [ + 'templates' => [ + 'form' => ['@SherlockodeSonataModular/Form/form_admin_fields.html.twig'], + ], + ]; + + $container->prependExtensionConfig('sonata_doctrine_orm_admin', $config); + } } } } diff --git a/Resources/views/CRUD/Association/edit_one_to_many.html.twig b/Resources/views/CRUD/Association/edit_one_to_many.html.twig new file mode 100755 index 0000000..3083120 --- /dev/null +++ b/Resources/views/CRUD/Association/edit_one_to_many.html.twig @@ -0,0 +1,97 @@ +{# + +This file is part of the Sonata package. + +(c) Thomas Rabaix + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. + +#} +{% if not sonata_admin.field_description.hasassociationadmin %} + {% for element in value %} + {{ element|render_relation_element(sonata_admin.field_description) }} + {% endfor %} +{% else %} + +
+ + {% if sonata_admin.edit == 'inline' %} + {% if sonata_admin.inline == 'table' %} + {% if form.children|length > 0 %} + {% include '@SonataAdmin/CRUD/Association/edit_one_to_many_inline_table.html.twig' %} + {% endif %} + {% elseif form.children|length > 0 %} + {% set associationAdmin = sonata_admin.field_description.associationadmin %} + {% include '@SonataAdmin/CRUD/Association/edit_one_to_many_inline_tabs.html.twig' %} + + {% endif %} + {% else %} + {{ form_widget(form) }} + {% endif %} + + + + {% set display_create_button = sonata_admin.field_description.associationadmin.hasroute('create') + and sonata_admin.field_description.associationadmin.isGranted('CREATE') + and btn_add + and ( + sonata_admin.field_description.options.limit is not defined or + form.children|length < sonata_admin.field_description.options.limit + ) %} + + {% if sonata_admin.edit == 'inline' %} + + {% if display_create_button %} + + + + {{ btn_add|trans({}, btn_catalogue) }} + + + {% endif %} + + {# add code for the sortable options #} + {% if sonata_admin.field_description.options.sortable is defined %} + {% if sonata_admin.inline == 'table' %} + {% include '@SonataAdmin/CRUD/Association/edit_one_to_many_sortable_script_table.html.twig' %} + {% else %} + {% include '@SonataAdmin/CRUD/Association/edit_one_to_many_sortable_script_tabs.html.twig' %} + {% endif %} + {% endif %} + + {# include association code #} + {% include '@SonataAdmin/CRUD/Association/edit_one_script.html.twig' %} + + {% else %} + + {% if display_create_button %} + + + {{ btn_add|trans({}, btn_catalogue) }} + + {% endif %} + + + {% include '@SonataAdmin/CRUD/Association/edit_modal.html.twig' %} + + {% include '@SonataAdmin/CRUD/Association/edit_many_script.html.twig' %} + {% endif %} +
+{% endif %} diff --git a/Resources/views/Form/form_admin_fields.html.twig b/Resources/views/Form/form_admin_fields.html.twig new file mode 100755 index 0000000..34771d2 --- /dev/null +++ b/Resources/views/Form/form_admin_fields.html.twig @@ -0,0 +1,5 @@ +{% extends '@SonataDoctrineORMAdmin/Form/form_admin_fields.html.twig' %} + +{% block sonata_admin_orm_one_to_many_widget %} + {% include '@SherlockodeSonataModular/CRUD/Association/edit_one_to_many.html.twig' %} +{% endblock %}