Skip to content

Commit

Permalink
State machine transitions from Grid
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed May 15, 2024
1 parent 466d531 commit 3a876cb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 9 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/GiftCard/Entity/GiftCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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')]
Expand Down
13 changes: 13 additions & 0 deletions src/GiftCard/Grid/AdminGiftCardGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'))
);
;
}
Expand Down

0 comments on commit 3a876cb

Please sign in to comment.