Skip to content

Commit

Permalink
Merge pull request #39 from sherlockode/fix/one-to-many-view
Browse files Browse the repository at this point in the history
Fix one to many view
  • Loading branch information
Vowow authored Jan 15, 2019
2 parents 483995a + 171f93c commit cfedced
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
11 changes: 11 additions & 0 deletions DependencyInjection/SherlockodeSonataModularExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
97 changes: 97 additions & 0 deletions Resources/views/CRUD/Association/edit_one_to_many.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
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 %}

<div id="field_container_{{ id }}" class="field-container">
<span id="field_widget_{{ id }}" >
{% 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 %}

</span>

{% 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 %}
<span id="field_actions_{{ id }}" >
<a
href="{{ sonata_admin.field_description.associationadmin.generateUrl(
'create',
sonata_admin.field_description.getOption('link_parameters', {})
) }}"
onclick="return start_field_retrieve_{{ id }}(this);"
class="btn btn-primary btn-sm sonata-ba-action"
title="{{ btn_add|trans({}, btn_catalogue) }}"
>
<i class="fa fa-plus-circle"></i>
{{ btn_add|trans({}, btn_catalogue) }}
</a>
</span>
{% 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 %}
<span id="field_actions_{{ id }}" >
{% if display_create_button %}
<a
href="{{ sonata_admin.field_description.associationadmin.generateUrl(
'create',
sonata_admin.field_description.getOption('link_parameters', {})
) }}"
onclick="return start_field_dialog_form_add_{{ id }}(this);"
class="btn btn-primary btn-sm sonata-ba-action"
title="{{ btn_add|trans({}, btn_catalogue) }}"
>
<i class="fa fa-plus-circle"></i>
{{ btn_add|trans({}, btn_catalogue) }}
</a>
{% endif %}
</span>

{% include '@SonataAdmin/CRUD/Association/edit_modal.html.twig' %}

{% include '@SonataAdmin/CRUD/Association/edit_many_script.html.twig' %}
{% endif %}
</div>
{% endif %}
5 changes: 5 additions & 0 deletions Resources/views/Form/form_admin_fields.html.twig
Original file line number Diff line number Diff line change
@@ -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 %}

0 comments on commit cfedced

Please sign in to comment.