<?php declare(strict_types=1);
namespace Swag\ExamplePlugin\Core\Content\Flow\Dispatching\Action;
use Shopware\Core\Content\Flow\Dispatching\Action\FlowAction;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\Uuid\Uuid;
use Swag\ExamplePlugin\Core\Framework\Event\TagAware;
use Shopware\Core\Framework\Event\FlowEvent;
class CreateTagAction extends FlowAction
private EntityRepositoryInterface $tagRepository;
public function __construct(EntityRepositoryInterface $tagRepository)
// you would need this repository to create a tag
$this->tagRepository = $tagRepository;
public static function getName(): string
return 'action.create.tag';
public static function getSubscribedEvents(): array
self::getName() => 'handle',
public function requirements(): array
return [TagAware::class];
public function handle(FlowEvent $event): void
// config is the config data when created a flow sequence
$config = $event->getConfig();
// make sure your tags data is exist
if (!\array_key_exists('tags', $config)) {
$baseEvent = $event->getEvent();
// just a step to make sure you're dispatching correct action
if (!$baseEvent instanceof TagAware || empty($tags)) {
foreach ($tags as $tag) {
'id' => Uuid::randomHex(),
$this->tagRepository->create($tagData, $baseEvent->getContext());