From fb6599988c68562dffe548329ae6426d4eb4e9b1 Mon Sep 17 00:00:00 2001 From: janpalen Date: Wed, 16 Oct 2024 13:50:35 +0200 Subject: [PATCH] OP-550 - Admin panel tabs create --- src/Form/Type/ProductBundleItemType.php | 21 ++---- src/Form/Type/ProductBundleType.php | 21 +----- src/Resources/config/services/form.xml | 1 - src/Resources/config/services/twig.xml | 6 +- .../product/{ => admin}/create.yaml | 4 +- .../twig_hooks/product/admin/update.yaml | 57 ++++++++++++++++ .../config/twig_hooks/twig_hooks.yaml | 2 +- .../Admin/Form/productBundleItem.html.twig | 68 ------------------- .../product/form/sections/bundle.html.twig | 8 +-- .../bundle/productBundleItem.html.twig | 39 +++++++++++ .../form/side_navigation/bundle.html.twig | 24 ++++--- src/Validator/Sequentially.php | 2 +- 12 files changed, 125 insertions(+), 128 deletions(-) rename src/Resources/config/twig_hooks/product/{ => admin}/create.yaml (94%) create mode 100644 src/Resources/config/twig_hooks/product/admin/update.yaml delete mode 100644 src/Resources/views/Admin/Form/productBundleItem.html.twig create mode 100644 src/Resources/views/Admin/product/form/sections/bundle/productBundleItem.html.twig diff --git a/src/Form/Type/ProductBundleItemType.php b/src/Form/Type/ProductBundleItemType.php index e66bac06..9931130b 100644 --- a/src/Form/Type/ProductBundleItemType.php +++ b/src/Form/Type/ProductBundleItemType.php @@ -11,31 +11,23 @@ namespace BitBag\SyliusProductBundlePlugin\Form\Type; +use Sylius\Bundle\AdminBundle\Form\Type\ProductVariantAutocompleteType; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; -use Sylius\Bundle\ResourceBundle\Form\Type\ResourceAutocompleteChoiceType; use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField; -use Symfony\UX\Autocomplete\Form\BaseEntityAutocompleteType; -#[AsEntityAutocompleteField( - alias: 'sylius_admin_product_bundle_item', - route: 'sylius_admin_entity_autocomplete', -)] final class ProductBundleItemType extends AbstractResourceType { - public function buildForm(FormBuilderInterface $builder, array $options): void + public function buildForm(FormBuilderInterface $builder, array $options = []): void { + $builder ->add('quantity', IntegerType::class, [ 'label' => false, 'required' => false, ]) - ->add('productVariant', ResourceAutocompleteChoiceType::class, [ + ->add('productVariant', ProductVariantAutocompleteType::class, [ 'label' => false, - 'choice_name' => 'descriptor', - 'choice_value' => 'code', - 'resource' => 'sylius.product_variant', ]) ; } @@ -44,9 +36,4 @@ public function getBlockPrefix(): string { return 'bitbag_sylius_product_bundle_plugin_product_bundle_item'; } - - public function getParent(): string - { - return BaseEntityAutocompleteType::class; - } } diff --git a/src/Form/Type/ProductBundleType.php b/src/Form/Type/ProductBundleType.php index a703774b..49e6cde1 100644 --- a/src/Form/Type/ProductBundleType.php +++ b/src/Form/Type/ProductBundleType.php @@ -14,7 +14,6 @@ use Sylius\Bundle\AdminBundle\Form\Type\AddButtonType; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; -use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\UX\LiveComponent\Form\Type\LiveCollectionType; @@ -26,32 +25,14 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('isPackedProduct', CheckboxType::class, [ 'label' => 'bitbag_sylius_product_bundle.ui.is_packed_product', ]) -// ->add('rules', LiveCollectionType::class, [ -// 'entry_type' => AutomaticBlacklistingRuleType::class, -// 'allow_add' => true, -// 'allow_delete' => true, -// 'by_reference' => false, -// 'button_add_type' => AddButtonType::class, -// 'button_add_options' => [ -// 'label' => 'sylius.ui.add_rule', -// 'types' => $this->rules, -// ], -// 'button_delete_options' => [ -// 'label' => false, -// ], -// ]) ->add('productBundleItems', LiveCollectionType::class, [ 'entry_type' => ProductBundleItemType::class, -// 'entry_options' => ['label' => false], + 'entry_options' => ['label' => false], 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false, 'label' => false, 'button_add_type' => AddButtonType::class, -// 'button_add_options' => [ -// 'label' => 'sylius.ui.add_rule', -//// 'types' => $this->rules, -// ], ]) ; } diff --git a/src/Resources/config/services/form.xml b/src/Resources/config/services/form.xml index 79d3db6f..fdc2ef66 100644 --- a/src/Resources/config/services/form.xml +++ b/src/Resources/config/services/form.xml @@ -22,7 +22,6 @@ %bitbag_sylius_product_bundle.model.product_bundle_item.class% %bitbag_sylius_product_bundle.form.type.product_bundle_item.validation_groups% - diff --git a/src/Resources/config/services/twig.xml b/src/Resources/config/services/twig.xml index e67c3568..410dd46f 100644 --- a/src/Resources/config/services/twig.xml +++ b/src/Resources/config/services/twig.xml @@ -1,6 +1,10 @@ - + diff --git a/src/Resources/config/twig_hooks/product/create.yaml b/src/Resources/config/twig_hooks/product/admin/create.yaml similarity index 94% rename from src/Resources/config/twig_hooks/product/create.yaml rename to src/Resources/config/twig_hooks/product/admin/create.yaml index a61adb7e..26cc176f 100644 --- a/src/Resources/config/twig_hooks/product/create.yaml +++ b/src/Resources/config/twig_hooks/product/admin/create.yaml @@ -53,5 +53,5 @@ twig_hooks: template: '@BitBagSyliusProductBundlePlugin/Admin/product/form/sections/bundle.html.twig' 'sylius_admin.product.create.content.form.sections.bundle': - item: - template: '@BitBagSyliusProductBundlePlugin/Admin/Form/productBundleItem.html.twig' + product_bundle: + template: '@BitBagSyliusProductBundlePlugin/Admin/product/form/sections/bundle/productBundleItem.html.twig' diff --git a/src/Resources/config/twig_hooks/product/admin/update.yaml b/src/Resources/config/twig_hooks/product/admin/update.yaml new file mode 100644 index 00000000..5f61c68f --- /dev/null +++ b/src/Resources/config/twig_hooks/product/admin/update.yaml @@ -0,0 +1,57 @@ +twig_hooks: + hooks: + 'sylius_admin.product.update.content.form.side_navigation': + general: + template: '@SyliusAdmin/product/form/side_navigation/general.html.twig' + configuration: + active: true + channel_pricing: + template: '@SyliusAdmin/product/form/side_navigation/channel_pricing.html.twig' + taxes: + template: '@SyliusAdmin/product/form/side_navigation/taxes.html.twig' + shipping: + template: '@SyliusAdmin/product/form/side_navigation/shipping.html.twig' + inventory: + template: '@SyliusAdmin/product/form/side_navigation/inventory.html.twig' + translations: + template: '@SyliusAdmin/product/form/side_navigation/translations.html.twig' + taxonomy: + template: '@SyliusAdmin/product/form/side_navigation/taxonomy.html.twig' + attributes: + template: '@SyliusAdmin/product/form/side_navigation/attributes.html.twig' + associations: + template: '@SyliusAdmin/product/form/side_navigation/associations.html.twig' + media: + template: '@SyliusAdmin/product/form/side_navigation/media.html.twig' + bundle: + template: '@BitBagSyliusProductBundlePlugin/Admin/product/form/side_navigation/bundle.html.twig' + + 'sylius_admin.product.update.content.form.sections': + general: + template: '@SyliusAdmin/product/form/sections/general.html.twig' + configuration: + active: true + channel_pricing: + template: '@SyliusAdmin/product/form/sections/channel_pricing.html.twig' + taxes: + template: '@SyliusAdmin/product/form/sections/taxes.html.twig' + shipping: + template: '@SyliusAdmin/product/form/sections/shipping.html.twig' + inventory: + template: '@SyliusAdmin/product/form/sections/inventory.html.twig' + translations: + template: '@SyliusAdmin/product/form/sections/translations.html.twig' + taxonomy: + template: '@SyliusAdmin/product/form/sections/taxonomy.html.twig' + attributes: + template: '@SyliusAdmin/product/form/sections/attributes.html.twig' + associations: + template: '@SyliusAdmin/product/form/sections/associations.html.twig' + media: + template: '@SyliusAdmin/product/form/sections/media.html.twig' + bundle: + template: '@BitBagSyliusProductBundlePlugin/Admin/product/form/sections/bundle.html.twig' + + 'sylius_admin.product.update.content.form.sections.bundle': + product_bundle: + template: '@BitBagSyliusProductBundlePlugin/Admin/product/form/sections/bundle/productBundleItem.html.twig' diff --git a/src/Resources/config/twig_hooks/twig_hooks.yaml b/src/Resources/config/twig_hooks/twig_hooks.yaml index 9ac41c4b..ffd03256 100644 --- a/src/Resources/config/twig_hooks/twig_hooks.yaml +++ b/src/Resources/config/twig_hooks/twig_hooks.yaml @@ -1,2 +1,2 @@ imports: - - { resource: "@BitBagSyliusProductBundlePlugin/Resources/config/twig_hooks/product/create.yaml" } + - { resource: "@BitBagSyliusProductBundlePlugin/Resources/config/twig_hooks/product/**/*.yaml" } diff --git a/src/Resources/views/Admin/Form/productBundleItem.html.twig b/src/Resources/views/Admin/Form/productBundleItem.html.twig deleted file mode 100644 index 8ae2fff2..00000000 --- a/src/Resources/views/Admin/Form/productBundleItem.html.twig +++ /dev/null @@ -1,68 +0,0 @@ -{#{% extends '@SyliusUi/Form/theme.html.twig' %}#} - -{#{% block collection_widget -%}#} -{# {% from '@SyliusResource/Macros/notification.html.twig' import error %}#} -{# {% import _self as self %}#} -{# {% set attr = attr|merge({'class': attr.class|default ~ ' controls collection-widget'}) %}#} - -{# {% apply spaceless %}#} -{#
#} -{# {{ error(form.vars.errors) }}#} - -{# {% if prototypes|default is iterable %}#} -{# {% for key, subPrototype in prototypes %}#} -{# #} -{# {% endfor %}#} -{# {% endif %}#} - -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# {% for child in form %}#} -{# {{ self.collection_item(child, allow_delete, button_delete_label, loop.index0) }}#} -{# {% endfor %}#} -{# #} -{#
{{ 'bitbag_sylius_product_bundle.ui.product_variant'|trans }}{{ 'bitbag_sylius_product_bundle.ui.quantity'|trans }}{{ 'bitbag_sylius_product_bundle.ui.delete'|trans }}
#} - -{# {% if prototype is defined and allow_add %}#} -{# #} -{# #} -{# {{ button_add_label|trans }}#} -{# #} -{# {% endif %}#} -{#
#} -{# {% endapply %}#} -{#{%- endblock collection_widget %}#} - -{#{% macro collection_item(form, allow_delete, button_delete_label, index) %}#} -{# {% apply spaceless %}#} -{# #} -{# #} -{#
{{ form_row(form.productVariant, {'remote_url': path('bitbag_product_bundle_admin_ajax_product_variants_by_phrase'), 'remote_criteria_type': 'contains', 'remote_criteria_name': 'phrase', 'load_edit_url': path('bitbag_product_bundle_admin_ajax_product_variants_by_codes')}) }}
#} -{# #} -{# #} -{# {{ form_row(form.quantity) }}#} -{# #} - -{# {% if allow_delete %}#} -{# #} -{# #} -{# #} -{# {{ button_delete_label|trans }}#} -{# #} -{# #} -{# {% endif %}#} -{# #} -{# {% endapply %}#} -{#{% endmacro %}#} diff --git a/src/Resources/views/Admin/product/form/sections/bundle.html.twig b/src/Resources/views/Admin/product/form/sections/bundle.html.twig index a488704d..d9845e50 100644 --- a/src/Resources/views/Admin/product/form/sections/bundle.html.twig +++ b/src/Resources/views/Admin/product/form/sections/bundle.html.twig @@ -1,8 +1,7 @@ -{#{% form_theme form '@BitBagSyliusProductBundlePlugin/Admin/Form/productBundleItem.html.twig' %}#} {% set form = hookable_metadata.context.form %} {% set product = hookable_metadata.context.resource %} -
+

@@ -10,12 +9,7 @@

- {{ dump(form) }} - {{ form_row(form.productBundle.isPackedProduct) }} - {{ form_row(form.productBundle.productBundleItems) }} -{# {{ sonata_block_render_event('sylius.admin.product.' ~ action ~ '.tab_bundle', {'form': form }) }}#} {% hook 'bundle' with { product } %}
-
diff --git a/src/Resources/views/Admin/product/form/sections/bundle/productBundleItem.html.twig b/src/Resources/views/Admin/product/form/sections/bundle/productBundleItem.html.twig new file mode 100644 index 00000000..77fe9cc8 --- /dev/null +++ b/src/Resources/views/Admin/product/form/sections/bundle/productBundleItem.html.twig @@ -0,0 +1,39 @@ +{% from '@SyliusResource/Macros/notification.html.twig' import error %} + +{% set form = hookable_metadata.context.form %} +{% set product_bundle_items = hookable_metadata.context.form.productBundle.productBundleItems %} + +
+ + {{ error(form.vars.errors) }} + +
+ + + + + + + + + + {% for product_bundle_form in product_bundle_items %} + + + + + + {% endfor %} + +
{{ 'bitbag_sylius_product_bundle.ui.product_variant'|trans }}{{ 'bitbag_sylius_product_bundle.ui.quantity'|trans }}{{ 'bitbag_sylius_product_bundle.ui.delete'|trans }}
+ {{ form_row(product_bundle_form.children.productVariant) }} + + {{ form_row(product_bundle_form.children.quantity) }} + + {{ form_widget(product_bundle_form.vars.button_delete, { label: 'sylius.ui.delete'|trans, attr: { class: 'btn btn-outline-danger w-100','data-test-image-delete': '' }}) }} +
+
+ {{ form_widget(product_bundle_items.vars.button_add) }} +
+
+
diff --git a/src/Resources/views/Admin/product/form/side_navigation/bundle.html.twig b/src/Resources/views/Admin/product/form/side_navigation/bundle.html.twig index 65795eb9..18d5d964 100644 --- a/src/Resources/views/Admin/product/form/side_navigation/bundle.html.twig +++ b/src/Resources/views/Admin/product/form/side_navigation/bundle.html.twig @@ -1,10 +1,14 @@ - +{% set product = hookable_metadata.context.resource %} + +{% if product.productBundle is not null %} + +{% endif %} diff --git a/src/Validator/Sequentially.php b/src/Validator/Sequentially.php index 6412897d..1714f794 100644 --- a/src/Validator/Sequentially.php +++ b/src/Validator/Sequentially.php @@ -38,7 +38,7 @@ protected function getCompositeOption(): string /** * @return array|string */ - public function getTargets() + public function getTargets(): string|array { return [self::CLASS_CONSTRAINT, self::PROPERTY_CONSTRAINT]; }