diff --git a/composer.json b/composer.json index 3556b91..2a23351 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ ], "require": { "php": "^8.1", + "sylius/grid-bundle": "1.13.0-ALPHA.1", "sylius/paypal-plugin": "^1.6", "sylius/resource-bundle": "1.11-BETA.2", "sylius/sylius": "~1.13.0", diff --git a/composer.lock b/composer.lock index a0e9842..3093074 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c0c4b6a2436c480c5ac18a20860763eb", + "content-hash": "6d178e6f51ea7bd11716bdb858b0575b", "packages": [ { "name": "alcohol/iso4217", @@ -7012,16 +7012,16 @@ }, { "name": "sylius/grid-bundle", - "version": "v1.12.1", + "version": "v1.13.0-ALPHA.1", "source": { "type": "git", "url": "https://github.com/Sylius/SyliusGridBundle.git", - "reference": "0ea47b97aba61162d4f4545c2dcc86963c99c8d7" + "reference": "e67e8d61c7ee47e38310d161da6baa0455ae0bd8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Sylius/SyliusGridBundle/zipball/0ea47b97aba61162d4f4545c2dcc86963c99c8d7", - "reference": "0ea47b97aba61162d4f4545c2dcc86963c99c8d7", + "url": "https://api.github.com/repos/Sylius/SyliusGridBundle/zipball/e67e8d61c7ee47e38310d161da6baa0455ae0bd8", + "reference": "e67e8d61c7ee47e38310d161da6baa0455ae0bd8", "shasum": "" }, "require": { @@ -7068,7 +7068,7 @@ "phpunit/phpunit": "^9.5", "rector/rector": "^0.13", "sylius-labs/coding-standard": "^4.0", - "sylius/resource-bundle": "^1.10", + "sylius/resource-bundle": "dev-poc-new-resource-metadata", "symfony/console": "^5.4 || ^6.0", "symfony/dotenv": "^5.4 || ^6.0", "symfony/maker-bundle": "^1.36", @@ -7124,9 +7124,9 @@ ], "support": { "issues": "https://github.com/Sylius/SyliusGridBundle/issues", - "source": "https://github.com/Sylius/SyliusGridBundle/tree/v1.12.1" + "source": "https://github.com/Sylius/SyliusGridBundle/tree/v1.13.0-ALPHA.1" }, - "time": "2024-01-05T14:42:50+00:00" + "time": "2024-01-30T12:41:30+00:00" }, { "name": "sylius/mailer-bundle", @@ -18653,6 +18653,7 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { + "sylius/grid-bundle": 15, "sylius/resource-bundle": 10 }, "prefer-stable": true, diff --git a/src/GiftCard/Entity/GiftCard.php b/src/GiftCard/Entity/GiftCard.php index 5b71ce1..90f3951 100644 --- a/src/GiftCard/Entity/GiftCard.php +++ b/src/GiftCard/Entity/GiftCard.php @@ -6,6 +6,7 @@ use App\GiftCard\Form\Type\GiftCardAdminType; use Doctrine\ORM\Mapping as ORM; +use Sylius\Resource\Metadata\ApplyStateMachineTransition; use Sylius\Resource\Metadata\AsResource; use Sylius\Resource\Metadata\Create; use Sylius\Resource\Metadata\Delete; @@ -20,10 +21,14 @@ #[Create(routePrefix: '/admin', formType: GiftCardAdminType::class)] #[Update(routePrefix: '/admin', formType: GiftCardAdminType::class)] #[Delete(routePrefix: '/admin')] +#[ApplyStateMachineTransition(routePrefix: '/admin', stateMachineTransition: self::TRANSITION_DEACTIVATE, stateMachineGraph: 'default')] +#[ApplyStateMachineTransition(routePrefix: '/admin', stateMachineTransition: self::TRANSITION_ACTIVATE, stateMachineGraph: 'default')] class GiftCard implements ResourceInterface { public const STATE_ACTIVE = 'active'; public const STATE_INACTIVE = 'inactive'; + public const TRANSITION_ACTIVATE = 'activate'; + public const TRANSITION_DEACTIVATE = 'deactivate'; #[ORM\Id] #[ORM\GeneratedValue(strategy: 'AUTO')] diff --git a/src/GiftCard/Grid/AdminGiftCardGrid.php b/src/GiftCard/Grid/AdminGiftCardGrid.php index 8ca9b1a..01309b9 100644 --- a/src/GiftCard/Grid/AdminGiftCardGrid.php +++ b/src/GiftCard/Grid/AdminGiftCardGrid.php @@ -6,6 +6,7 @@ use App\GiftCard\Entity\GiftCard; use Sylius\Bundle\GridBundle\Builder\Action\Action; +use Sylius\Bundle\GridBundle\Builder\Action\ApplyTransitionAction; use Sylius\Bundle\GridBundle\Builder\Action\CreateAction; use Sylius\Bundle\GridBundle\Builder\Action\DeleteAction; use Sylius\Bundle\GridBundle\Builder\Action\UpdateAction; @@ -36,6 +37,18 @@ public function buildGrid(GridBuilderInterface $gridBuilder): void ->addActionGroup(ItemActionGroup::create() ->addAction(UpdateAction::create()) ->addAction(DeleteAction::create()) + ->addAction(ApplyTransitionAction::create( + GiftCard::TRANSITION_DEACTIVATE, + 'app_admin_gift_card_deactivate', + ['id' => 'resource.id'], + ['graph' => 'default', 'class' => 'black'] + )->setLabel('Deactivate')->setIcon('ban')) + ->addAction(ApplyTransitionAction::create( + GiftCard::TRANSITION_ACTIVATE, + 'app_admin_gift_card_activate', + ['id' => 'resource.id'], + ['graph' => 'default', 'class' => 'green'] + )->setLabel('Activate')->setIcon('star')) ); ; }