From 08c3e85f7ed9b221c35b7c13896a0eb6ff2d6c5b Mon Sep 17 00:00:00 2001 From: Wojdylak Date: Fri, 10 May 2024 14:23:48 +0200 Subject: [PATCH] [Admin][Taxon] Implements media management --- .../AdminBundle/Form/Type/TaxonType.php | 47 ++ .../config/app/twig_hooks/taxon/create.yaml | 37 +- .../config/app/twig_hooks/taxon/update.yaml | 39 +- .../Resources/config/routing/taxon.yml | 9 +- .../config/services/twig/component.xml | 16 +- .../Twig/Component/Taxon/FormComponent.php | 46 ++ .../Twig/Component/Taxon/TreeComponent.php | 4 +- .../taxon/component/taxon_tree.html.twig | 68 --- .../templates/taxon/create/form.html.twig | 10 - .../templates/taxon/form/sections.html.twig | 3 - .../form/sections/details/code.html.twig | 1 - .../taxon/form/sections/media.html.twig | 29 -- .../templates/taxon/form/tree.html.twig | 400 ------------------ .../{taxon_tree.html.twig => tree.html.twig} | 11 +- .../templates/taxon/sections.html.twig | 12 + .../templates/taxon/sections/form.html.twig | 16 + .../form}/details.html.twig | 0 .../sections/form/details/code.html.twig | 1 + .../form}/details/enabled.html.twig | 0 .../form}/details/parent.html.twig | 0 .../taxon/sections/form/media.html.twig | 46 ++ .../form}/translations.html.twig | 13 +- .../templates/taxon/sections/tree.html.twig | 16 + .../templates/taxon/update/form.html.twig | 10 - 24 files changed, 263 insertions(+), 571 deletions(-) create mode 100644 src/Sylius/Bundle/AdminBundle/Form/Type/TaxonType.php create mode 100644 src/Sylius/Bundle/AdminBundle/Twig/Component/Taxon/FormComponent.php delete mode 100644 src/Sylius/Bundle/AdminBundle/templates/taxon/component/taxon_tree.html.twig delete mode 100644 src/Sylius/Bundle/AdminBundle/templates/taxon/create/form.html.twig delete mode 100644 src/Sylius/Bundle/AdminBundle/templates/taxon/form/sections.html.twig delete mode 100644 src/Sylius/Bundle/AdminBundle/templates/taxon/form/sections/details/code.html.twig delete mode 100644 src/Sylius/Bundle/AdminBundle/templates/taxon/form/sections/media.html.twig delete mode 100644 src/Sylius/Bundle/AdminBundle/templates/taxon/form/tree.html.twig rename src/Sylius/Bundle/AdminBundle/templates/taxon/helper/{taxon_tree.html.twig => tree.html.twig} (92%) create mode 100644 src/Sylius/Bundle/AdminBundle/templates/taxon/sections.html.twig create mode 100644 src/Sylius/Bundle/AdminBundle/templates/taxon/sections/form.html.twig rename src/Sylius/Bundle/AdminBundle/templates/taxon/{form/sections => sections/form}/details.html.twig (100%) create mode 100644 src/Sylius/Bundle/AdminBundle/templates/taxon/sections/form/details/code.html.twig rename src/Sylius/Bundle/AdminBundle/templates/taxon/{form/sections => sections/form}/details/enabled.html.twig (100%) rename src/Sylius/Bundle/AdminBundle/templates/taxon/{form/sections => sections/form}/details/parent.html.twig (100%) create mode 100644 src/Sylius/Bundle/AdminBundle/templates/taxon/sections/form/media.html.twig rename src/Sylius/Bundle/AdminBundle/templates/taxon/{form/sections => sections/form}/translations.html.twig (65%) create mode 100644 src/Sylius/Bundle/AdminBundle/templates/taxon/sections/tree.html.twig delete mode 100644 src/Sylius/Bundle/AdminBundle/templates/taxon/update/form.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Form/Type/TaxonType.php b/src/Sylius/Bundle/AdminBundle/Form/Type/TaxonType.php new file mode 100644 index 00000000000..d4cbafb1c27 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Form/Type/TaxonType.php @@ -0,0 +1,47 @@ + $options */ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $builder + ->add('images', LiveCollectionType::class, [ + 'entry_type' => TaxonImageType::class, + 'allow_add' => true, + 'allow_delete' => true, + 'by_reference' => false, + 'button_add_options' => [ + 'label' => 'sylius.ui.add_image', + ], + 'button_delete_options' => [ + 'label' => 'sylius.ui.delete', + ], + ]) + ; + } + + public function getParent(): string + { + return BaseTaxonType::class; + } +} diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/taxon/create.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/taxon/create.yaml index 78e73feb927..b0280c4c9b7 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/taxon/create.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/taxon/create.yaml @@ -2,28 +2,33 @@ twig_hooks: hooks: 'sylius_admin.taxon.create.content': form: - template: '@SyliusAdmin/taxon/create/form.html.twig' - configuration: - render_rest: false - - 'sylius_admin.taxon.create.content.form': + enabled: false + sections: + template: '@SyliusAdmin/taxon/sections.html.twig' + + 'sylius_admin.taxon.create.content.sections#left': tree: component: 'sylius_admin:taxon:tree' - sections: - template: '@SyliusAdmin/taxon/form/sections.html.twig' - 'sylius_admin.taxon.create.content.form.sections': + 'sylius_admin.taxon.create.content.sections#right': + form: + component: 'sylius_admin:taxon:form' + props: + form: '@=_context.form' + resource: '@=_context.resource' + + 'sylius_admin.taxon.create.content.sections.form': details: - template: '@SyliusAdmin/taxon/form/sections/details.html.twig' + template: '@SyliusAdmin/taxon/sections/form/details.html.twig' translations: - template: '@SyliusAdmin/taxon/form/sections/translations.html.twig' + template: '@SyliusAdmin/taxon/sections/form/translations.html.twig' media: - template: '@SyliusAdmin/taxon/form/sections/media.html.twig' - - 'sylius_admin.taxon.create.content.form.sections.details': + template: '@SyliusAdmin/taxon/sections/form/media.html.twig' + + 'sylius_admin.taxon.create.content.sections.form.details': code: - template: '@SyliusAdmin/taxon/form/sections/details/code.html.twig' + template: '@SyliusAdmin/taxon/sections/form/details/code.html.twig' parent: - template: '@SyliusAdmin/taxon/form/sections/details/parent.html.twig' + template: '@SyliusAdmin/taxon/sections/form/details/parent.html.twig' enabled: - template: '@SyliusAdmin/taxon/form/sections/details/enabled.html.twig' + template: '@SyliusAdmin/taxon/sections/form/details/enabled.html.twig' diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/taxon/update.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/taxon/update.yaml index 58d48c5aa9c..50de425af72 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/taxon/update.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/taxon/update.yaml @@ -2,28 +2,35 @@ twig_hooks: hooks: 'sylius_admin.taxon.update.content': form: - template: '@SyliusAdmin/taxon/update/form.html.twig' - configuration: - render_rest: false - - 'sylius_admin.taxon.update.content.form': + enabled: false + sections: + template: '@SyliusAdmin/taxon/sections.html.twig' + + 'sylius_admin.taxon.update.content.sections#left': tree: component: 'sylius_admin:taxon:tree' - sections: - template: '@SyliusAdmin/taxon/form/sections.html.twig' - 'sylius_admin.taxon.update.content.form.sections': + 'sylius_admin.taxon.update.content.sections#right': + form: + component: 'sylius_admin:taxon:form' + props: + form: '@=_context.form' + resource: '@=_context.resource' + configuration: + method: 'PUT' + + 'sylius_admin.taxon.update.content.sections.form': details: - template: '@SyliusAdmin/taxon/form/sections/details.html.twig' + template: '@SyliusAdmin/taxon/sections/form/details.html.twig' translations: - template: '@SyliusAdmin/taxon/form/sections/translations.html.twig' + template: '@SyliusAdmin/taxon/sections/form/translations.html.twig' media: - template: '@SyliusAdmin/taxon/form/sections/media.html.twig' - - 'sylius_admin.taxon.update.content.form.sections.details': + template: '@SyliusAdmin/taxon/sections/form/media.html.twig' + + 'sylius_admin.taxon.update.content.sections.form.details': code: - template: '@SyliusAdmin/taxon/form/sections/details/code.html.twig' + template: '@SyliusAdmin/taxon/sections/form/details/code.html.twig' parent: - template: '@SyliusAdmin/taxon/form/sections/details/parent.html.twig' + template: '@SyliusAdmin/taxon/sections/form/details/parent.html.twig' enabled: - template: '@SyliusAdmin/taxon/form/sections/details/enabled.html.twig' + template: '@SyliusAdmin/taxon/sections/form/details/enabled.html.twig' diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/taxon.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/taxon.yml index 0881c0f908b..f35b1b0874b 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/taxon.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/taxon.yml @@ -6,11 +6,8 @@ sylius_admin_taxon: except: ['show', 'index'] redirect: update permission: true - vars: - all: - subheader: sylius.ui.manage_categorization_of_your_products - templates: - form: "@SyliusAdmin/Taxon/_form.html.twig" + form: + type: Sylius\Bundle\AdminBundle\Form\Type\TaxonType type: sylius.resource sylius_admin_taxon_index: @@ -31,6 +28,8 @@ sylius_admin_taxon_create_for_parent: permission: true template: '@SyliusAdmin/shared/crud/create.html.twig' redirect: sylius_admin_taxon_update + form: + type: Sylius\Bundle\AdminBundle\Form\Type\TaxonType factory: method: createForParent arguments: ['expr:notFoundOnNull(service("sylius.repository.taxon").find($id))'] diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/services/twig/component.xml b/src/Sylius/Bundle/AdminBundle/Resources/config/services/twig/component.xml index f5178441aa2..0b1c5c2cbfa 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/services/twig/component.xml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/services/twig/component.xml @@ -274,6 +274,20 @@ /> + + + Sylius\Bundle\AdminBundle\Form\Type\TaxonType + + + + diff --git a/src/Sylius/Bundle/AdminBundle/Twig/Component/Taxon/FormComponent.php b/src/Sylius/Bundle/AdminBundle/Twig/Component/Taxon/FormComponent.php new file mode 100644 index 00000000000..9d2d1f87d7c --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Twig/Component/Taxon/FormComponent.php @@ -0,0 +1,46 @@ +formFactory->create($this->formClass, $this->resource); + } +} diff --git a/src/Sylius/Bundle/AdminBundle/Twig/Component/Taxon/TreeComponent.php b/src/Sylius/Bundle/AdminBundle/Twig/Component/Taxon/TreeComponent.php index 0c6f56d5a28..41860b0d4f7 100644 --- a/src/Sylius/Bundle/AdminBundle/Twig/Component/Taxon/TreeComponent.php +++ b/src/Sylius/Bundle/AdminBundle/Twig/Component/Taxon/TreeComponent.php @@ -33,8 +33,8 @@ class TreeComponent * @param TaxonRepositoryInterface $taxonRepository */ public function __construct( - private TaxonRepositoryInterface $taxonRepository, - private ObjectManager $taxonManager, + private readonly TaxonRepositoryInterface $taxonRepository, + private readonly ObjectManager $taxonManager, ) { } diff --git a/src/Sylius/Bundle/AdminBundle/templates/taxon/component/taxon_tree.html.twig b/src/Sylius/Bundle/AdminBundle/templates/taxon/component/taxon_tree.html.twig deleted file mode 100644 index 1afac51a3d6..00000000000 --- a/src/Sylius/Bundle/AdminBundle/templates/taxon/component/taxon_tree.html.twig +++ /dev/null @@ -1,68 +0,0 @@ -{% import '@SyliusAdmin/taxon/helper/taxon_tree.html.twig' as taxonTree %} - -
-
-
-
- -
- -
- {{ taxonTree.render(rootNodes) }} -
-
-
-
- -{#{% macro render(taxons) %}#} -{# {% import '@SyliusUi/Macro/buttons.html.twig' as buttons %}#} -{# {% import _self as tree %}#} - -{# #} -{#{% endmacro %}#} diff --git a/src/Sylius/Bundle/AdminBundle/templates/taxon/create/form.html.twig b/src/Sylius/Bundle/AdminBundle/templates/taxon/create/form.html.twig deleted file mode 100644 index 84c9c9955bb..00000000000 --- a/src/Sylius/Bundle/AdminBundle/templates/taxon/create/form.html.twig +++ /dev/null @@ -1,10 +0,0 @@ -{% extends '@SyliusAdmin/shared/crud/create/content/form.html.twig' %} - -{% block form_content %} -
- {{ form_errors(form) }} - {{ form_widget(form._token) }} - - {{ parent() }} -
-{% endblock %} diff --git a/src/Sylius/Bundle/AdminBundle/templates/taxon/form/sections.html.twig b/src/Sylius/Bundle/AdminBundle/templates/taxon/form/sections.html.twig deleted file mode 100644 index c76fe7d14d8..00000000000 --- a/src/Sylius/Bundle/AdminBundle/templates/taxon/form/sections.html.twig +++ /dev/null @@ -1,3 +0,0 @@ -
- {% hook 'sections' %} -
diff --git a/src/Sylius/Bundle/AdminBundle/templates/taxon/form/sections/details/code.html.twig b/src/Sylius/Bundle/AdminBundle/templates/taxon/form/sections/details/code.html.twig deleted file mode 100644 index b39aacad1d9..00000000000 --- a/src/Sylius/Bundle/AdminBundle/templates/taxon/form/sections/details/code.html.twig +++ /dev/null @@ -1 +0,0 @@ -{{ form_row(hookable_metadata.context.form.code) }} diff --git a/src/Sylius/Bundle/AdminBundle/templates/taxon/form/sections/media.html.twig b/src/Sylius/Bundle/AdminBundle/templates/taxon/form/sections/media.html.twig deleted file mode 100644 index 8a07ae443d3..00000000000 --- a/src/Sylius/Bundle/AdminBundle/templates/taxon/form/sections/media.html.twig +++ /dev/null @@ -1,29 +0,0 @@ -
-
-

- {{ 'sylius.ui.media'|trans }} {{ 'sylius.ui.work_in_progress'|trans }} -

-
-
-
-
- -
-
-
- - -
-
- - -
-
-
-
- -
diff --git a/src/Sylius/Bundle/AdminBundle/templates/taxon/form/tree.html.twig b/src/Sylius/Bundle/AdminBundle/templates/taxon/form/tree.html.twig deleted file mode 100644 index db9683d6072..00000000000 --- a/src/Sylius/Bundle/AdminBundle/templates/taxon/form/tree.html.twig +++ /dev/null @@ -1,400 +0,0 @@ -
-
-
-
- -
- -
-
-
diff --git a/src/Sylius/Bundle/AdminBundle/templates/taxon/helper/taxon_tree.html.twig b/src/Sylius/Bundle/AdminBundle/templates/taxon/helper/tree.html.twig similarity index 92% rename from src/Sylius/Bundle/AdminBundle/templates/taxon/helper/taxon_tree.html.twig rename to src/Sylius/Bundle/AdminBundle/templates/taxon/helper/tree.html.twig index 52c3a78892a..bd931c05195 100644 --- a/src/Sylius/Bundle/AdminBundle/templates/taxon/helper/taxon_tree.html.twig +++ b/src/Sylius/Bundle/AdminBundle/templates/taxon/helper/tree.html.twig @@ -27,7 +27,8 @@ role="button" class="dropdown-item" data-action="live#action" - data-live-action-param="prevent|delete(taxonId={{ taxonId }})" + data-live-action-param="prevent|delete" + data-live-taxon-id-param="{{ taxonId }}" > {{ 'sylius.ui.delete'|trans }} @@ -37,7 +38,8 @@ role="button" class="dropdown-item" data-action="live#action" - data-live-action-param="prevent|moveUp(taxonId={{ taxonId }})" + data-live-action-param="prevent|moveUp" + data-live-taxon-id-param="{{ taxonId }}" > {{ 'sylius.ui.move_up'|trans }} @@ -47,7 +49,8 @@ role="button" class="dropdown-item" data-action="live#action" - data-live-action-param="prevent|moveDown(taxonId={{ taxonId }})" + data-live-action-param="prevent|moveDown" + data-live-taxon-id-param="{{ taxonId }}" > {{ 'sylius.ui.move_down'|trans }} @@ -99,7 +102,7 @@ {% endmacro %} {% macro render(taxons, nested = false) %} - {% import '@SyliusAdmin/taxon/helper/taxon_tree.html.twig' as _self %} + {% import '@SyliusAdmin/taxon/helper/tree.html.twig' as _self %}