Skip to content

Commit

Permalink
OP-550 - Admin panel tabs create
Browse files Browse the repository at this point in the history
  • Loading branch information
JanPalen committed Oct 16, 2024
1 parent 87c52cd commit fb65999
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 128 deletions.
21 changes: 4 additions & 17 deletions src/Form/Type/ProductBundleItemType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
])
;
}
Expand All @@ -44,9 +36,4 @@ public function getBlockPrefix(): string
{
return 'bitbag_sylius_product_bundle_plugin_product_bundle_item';
}

public function getParent(): string
{
return BaseEntityAutocompleteType::class;
}
}
21 changes: 1 addition & 20 deletions src/Form/Type/ProductBundleType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
// ],
])
;
}
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/services/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<argument>%bitbag_sylius_product_bundle.model.product_bundle_item.class%</argument>
<argument>%bitbag_sylius_product_bundle.form.type.product_bundle_item.validation_groups%</argument>
<tag name="form.type" />
<tag name="ux.entity_autocomplete_field" />
</service>

<service id="bitbag_sylius_product_bundle.form.extension.type.product" class="BitBag\SyliusProductBundlePlugin\Form\Extension\ProductTypeExtension">
Expand Down
6 changes: 5 additions & 1 deletion src/Resources/config/services/twig.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<container
xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"
>
<services>
<service id="bitbag_sylius_product_bundle.twig.extension.smash_promotion" class="BitBag\SyliusProductBundlePlugin\Twig\Extension\ProductBundleOrderItemExtension" public="false">
<argument type="service" id="bitbag_sylius_product_bundle.repository.product_bundle_order_item" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
57 changes: 57 additions & 0 deletions src/Resources/config/twig_hooks/product/admin/update.yaml
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion src/Resources/config/twig_hooks/twig_hooks.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
imports:
- { resource: "@BitBagSyliusProductBundlePlugin/Resources/config/twig_hooks/product/create.yaml" }
- { resource: "@BitBagSyliusProductBundlePlugin/Resources/config/twig_hooks/product/**/*.yaml" }
68 changes: 0 additions & 68 deletions src/Resources/views/Admin/Form/productBundleItem.html.twig

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
{#{% form_theme form '@BitBagSyliusProductBundlePlugin/Admin/Form/productBundleItem.html.twig' %}#}
{% set form = hookable_metadata.context.form %}
{% set product = hookable_metadata.context.resource %}

<div class="tab pane " id="product-bundle" role="tabpanel" tabindex="0">
<div class="tab pane {% if hookable_metadata.configuration.active|default(false) %}show active{% endif %}" id="product-bundle" role="tabpanel" tabindex="0">
<div class="card mb-3">
<div class="card-header">
<h2 id="productBundle" class="card-title">
{{ 'bitbag_sylius_product_bundle.ui.bundle'|trans }}
</h2>
</div>
<div class="card-body">
{{ 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 } %}
</div>
</div>

</div>
Original file line number Diff line number Diff line change
@@ -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 %}

<div class="row">

{{ error(form.vars.errors) }}

<div class="col-12 mb-4">
<table class="table table-bordered">
<thead>
<tr>
<th class="col-6">{{ 'bitbag_sylius_product_bundle.ui.product_variant'|trans }}</th>
<th class="col-4">{{ 'bitbag_sylius_product_bundle.ui.quantity'|trans }}</th>
<th class="col-2">{{ 'bitbag_sylius_product_bundle.ui.delete'|trans }}</th>
</tr>
</thead>
<tbody>
{% for product_bundle_form in product_bundle_items %}
<tr>
<td>
{{ form_row(product_bundle_form.children.productVariant) }}
</td>
<td>
{{ form_row(product_bundle_form.children.quantity) }}
</td>
<td>
{{ 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': '' }}) }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="d-grid gap-2">
{{ form_widget(product_bundle_items.vars.button_add) }}
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<button
type="button"
class="list-group-item list-group-item-action {% if hookable_metadata.configuration.active|default(false) %}active{% endif %}"
data-bs-toggle="tab"
data-bs-target="#product-bundle"
role="tab"
{{ sylius_test_html_attribute('side-navigation-tab', 'bundle') }}
>
{{ 'bitbag_sylius_product_bundle.ui.bundle'|trans }}
</button>
{% set product = hookable_metadata.context.resource %}

{% if product.productBundle is not null %}
<button
type="button"
class="list-group-item list-group-item-action {% if hookable_metadata.configuration.active|default(false) %}active{% endif %}"
data-bs-toggle="tab"
data-bs-target="#product-bundle"
role="tab"
{{ sylius_test_html_attribute('side-navigation-tab', 'bundle') }}
>
{{ 'bitbag_sylius_product_bundle.ui.bundle'|trans }}
</button>
{% endif %}
2 changes: 1 addition & 1 deletion src/Validator/Sequentially.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function getCompositeOption(): string
/**
* @return array<string>|string
*/
public function getTargets()
public function getTargets(): string|array
{
return [self::CLASS_CONSTRAINT, self::PROPERTY_CONSTRAINT];
}
Expand Down

0 comments on commit fb65999

Please sign in to comment.