[AdminBundle] Add LiveComponent for PromotionCoupon

This commit is contained in:
Wojdylak 2024-10-25 12:18:26 +02:00
parent aae7407fa7
commit e2bd9e2748
No known key found for this signature in database
GPG key ID: 7509E560A6821ABE
8 changed files with 138 additions and 9 deletions

View file

@ -0,0 +1,30 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Bundle\AdminBundle\Form\Type;
use Sylius\Bundle\PromotionBundle\Form\Type\PromotionCouponGeneratorInstructionType as BasePromotionCouponGeneratorInstructionType;
use Symfony\Component\Form\AbstractType;
final class PromotionCouponGeneratorInstructionType extends AbstractType
{
public function getBlockPrefix(): string
{
return 'sylius_admin_promotion_coupon_generator_instruction';
}
public function getParent(): string
{
return BasePromotionCouponGeneratorInstructionType::class;
}
}

View file

@ -2,7 +2,11 @@ sylius_twig_hooks:
hooks:
'sylius_admin.promotion_coupon.create.content':
form:
template: '@SyliusAdmin/shared/crud/common/content/form.html.twig'
component: 'sylius_admin:promotion_coupon:form'
props:
resource: '@=_context.resource'
form: '@=_context.form'
template: '@SyliusAdmin/shared/crud/common/content/form.html.twig'
configuration:
render_rest: false
priority: 0

View file

@ -19,7 +19,12 @@ sylius_twig_hooks:
template: '@SyliusAdmin/shared/crud/common/content/header.html.twig'
priority: 100
form:
template: '@SyliusAdmin/promotion_coupon/generate/form.html.twig'
component: 'sylius_admin:promotion_coupon:generator_instruction_form'
props:
form: '@=_context.form'
template: '@SyliusAdmin/promotion_coupon/generate/form.html.twig'
configuration:
render_rest: false
priority: 0
'sylius_admin.promotion_coupon.generate.content.header':

View file

@ -2,7 +2,11 @@ sylius_twig_hooks:
hooks:
'sylius_admin.promotion_coupon.update.content':
form:
template: '@SyliusAdmin/shared/crud/common/content/form.html.twig'
component: 'sylius_admin:promotion_coupon:form'
props:
resource: '@=_context.resource'
form: '@=_context.form'
template: '@SyliusAdmin/shared/crud/common/content/form.html.twig'
configuration:
render_rest: false
priority: 0

View file

@ -236,6 +236,10 @@
<tag name="form.type" />
</service>
<service id="sylius_admin.form.type.promotion_coupon_generator_instruction" class="Sylius\Bundle\AdminBundle\Form\Type\PromotionCouponGeneratorInstructionType" >
<tag name="form.type" />
</service>
<service id="sylius_admin.form.type.shipping_category" class="Sylius\Bundle\AdminBundle\Form\Type\ShippingCategoryType" >
<tag name="form.type" />
</service>

View file

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Sylius package.
(c) Sylius Sp. z o.o.
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<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="sylius_admin.twig.component.promotion_coupon.form"
class="Sylius\Bundle\UiBundle\Twig\Component\ResourceFormComponent"
>
<argument type="service" id="sylius.repository.promotion_coupon" />
<argument type="service" id="form.factory" />
<argument>%sylius.model.promotion_coupon.class%</argument>
<argument>Sylius\Bundle\AdminBundle\Form\Type\PromotionCouponType</argument>
<tag name="sylius.live_component.admin" key="sylius_admin:promotion_coupon:form" />
</service>
<service
id="sylius_admin.twig.component.promotion_coupon.generator_instruction_form"
class="Sylius\Bundle\AdminBundle\Twig\Component\PromotionCoupon\GeneratorInstructionFormComponent"
>
<argument type="service" id="form.factory" />
<argument>\Sylius\Bundle\AdminBundle\Form\Type\PromotionCouponGeneratorInstructionType</argument>
<tag name="sylius.live_component.admin" key="sylius_admin:promotion_coupon:generator_instruction_form" />
</service>
</services>
</container>

View file

@ -0,0 +1,42 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Bundle\AdminBundle\Twig\Component\PromotionCoupon;
use Sylius\Bundle\UiBundle\Twig\Component\TemplatePropTrait;
use Sylius\TwigHooks\LiveComponent\HookableLiveComponentTrait;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\ComponentWithFormTrait;
use Symfony\UX\LiveComponent\DefaultActionTrait;
#[AsLiveComponent]
class GeneratorInstructionFormComponent
{
use ComponentWithFormTrait;
use DefaultActionTrait;
use HookableLiveComponentTrait;
use TemplatePropTrait;
public function __construct(
private readonly FormFactoryInterface $formFactory,
private readonly string $formClass,
) {
}
protected function instantiateForm(): FormInterface
{
return $this->formFactory->create($this->formClass);
}
}

View file

@ -1,14 +1,12 @@
{% set form = hookable_metadata.context.form %}
{% form_theme form '@SyliusAdmin/shared/form_theme.html.twig' %}
{% form_theme form '@SyliusAdmin/shared/form_theme.html.twig' %}
<div class="container-xl">
{{ form_start(form, {'attr': {'class': 'ui loadable form', 'novalidate': 'novalidate', 'id': form.vars.id}}) }}
<div class="container-xl" {{ attributes }} >
{{ form_start(form, {'attr': {'novalidate': 'novalidate', 'id': form.vars.id}}) }}
<div class="row">
{{ form_errors(form) }}
{{ form_widget(form._token) }}
{% hook 'form' with { form } %}
</div>
{{ form_end(form, {render_rest: hookable.configuration.render_rest|default(false)}) }}
{{ form_end(form, {render_rest: hookable.configuration.render_rest|default(true)}) }}
</div>