一键导入
add-operation
Add one or more operations (Index, Show, Create, Update, Delete, BulkDelete, ApplyStateMachineTransition) to an existing Sylius Resource
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Add one or more operations (Index, Show, Create, Update, Delete, BulkDelete, ApplyStateMachineTransition) to an existing Sylius Resource
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Implement the fix described in a GitHub issue and open a Pull Request that closes it
Apply the latest review feedback to a Pull Request and push it to the PR branch
Add an admin autocomplete form type for a Sylius Resource (translatable or not), optionally injected into another form via an extension
Add an admin FormType for an existing Sylius Resource
Add a Sylius admin grid for an existing Sylius Resource
Add a multiple images collection (OneToMany) to an existing Sylius Resource
| name | add-operation |
| description | Add one or more operations (Index, Show, Create, Update, Delete, BulkDelete, ApplyStateMachineTransition) to an existing Sylius Resource |
| argument-hint | [ModelName] [Operation...] |
| allowed-tools | AskUserQuestion, Bash, Read, Edit, Write, Glob, Grep |
Ask the user for the ModelName and the list of operations they want if not provided. Several operations can be added in one run.
Supported operations:
| Operation | Route | Method | Notes |
|---|---|---|---|
Index | /{plural} | GET | requires a grid (run /sylius-stack:add-grid first) |
Show | /{plural}/{id} | GET | also scaffolds a minimal Twig Hook template |
Create | /{plural}/new | GET, POST | needs formType on the resource |
Update | /{plural}/{id}/edit | GET, PUT, PATCH | needs formType on the resource |
Delete | /{plural}/{id} | DELETE | |
BulkDelete | /{plural}/bulk_delete | DELETE | |
ApplyStateMachineTransition | /{plural}/{id}/{transition} | GET | requires a transition name |
Read src/Entity/{ModelName}.php to locate the #[AsResource(...)] attribute and find:
Sylius\Resource\Metadata\*operations: [...] array (may be missing if this is the first call)When writing the operations array, place Create before any operation whose path starts with {id} (Show, Update, Delete). The Symfony router matches routes in the order they are registered, so a path like /{id} declared before /new can swallow the literal new.
Recommended order when all are present:
operations: [
new Index(grid: Admin{ModelName}Grid::class),
new Create(),
new Update(),
new Delete(),
new BulkDelete(),
new Show(),
],
For each operation added, add its use statement if not already present:
use Sylius\Resource\Metadata\ApplyStateMachineTransition;
use Sylius\Resource\Metadata\BulkDelete;
use Sylius\Resource\Metadata\Create;
use Sylius\Resource\Metadata\Delete;
use Sylius\Resource\Metadata\Index;
use Sylius\Resource\Metadata\Show;
use Sylius\Resource\Metadata\Update;
For Index, also add:
use App\Grid\Admin{ModelName}Grid;
operations: [...] does not exist in #[AsResource(...)], add it.IndexAdmin{ModelName}Grid.src/Grid/Admin{ModelName}Grid.php), tell the user to run /sylius-stack:add-grid first and stop.new Index(grid: Admin{ModelName}Grid::class),
ShowAdd the operation:
new Show(),
Then scaffold the Twig Hook and template so the page renders out of the box.
Edit config/packages/sylius_bootstrap_admin_ui.yaml:
sylius_twig_hooks:
hooks:
'sylius_admin.{model_snake}.show.content':
body:
template: '{model_snake}/show/content/body.html.twig'
Create templates/{model_snake}/show/content/body.html.twig:
{% set {model_snake} = hookable_metadata.context.{model_snake} %}
<div class="page-body">
<div class="container-xl">
<div class="row">
<div class="col-12">
{# Access any field from the resource #}
<p>{{ {model_snake}.id }}</p>
</div>
</div>
</div>
</div>
If a grid exists, also ask the user whether to add the ShowAction item action:
use Sylius\Bundle\GridBundle\Builder\Action\ShowAction;
ItemActionGroup::create(
ShowAction::create(),
UpdateAction::create(),
DeleteAction::create(),
),
Create / UpdateAdd directly:
new Create(),
new Update(),
Both rely on formType declared at the #[AsResource] level. If formType is missing, tell the user and stop.
Validation via symfony/validator constraints on the entity runs automatically on Create and Update. To disable it on a specific operation:
new Update(validate: false),
Delete / BulkDeleteAdd directly:
new Delete(),
new BulkDelete(),
ApplyStateMachineTransitionAsk the user for the transition name (e.g. publish). Add:
new ApplyStateMachineTransition(stateMachineTransition: 'publish'),
The resulting route will be /{plural}/{id}/publish.
bin/console cache:clear
bin/console sylius:debug:resource 'App\Entity\{ModelName}'
bin/console debug:router | grep {model_snake}
Each operation should appear with its expected path.
Index and have no grid yet, run /sylius-stack:add-grid/sylius-stack:add-menu to expose the resource in the admin sidebar/sylius-stack:add-template to customize the rendered blocks (override, add or disable a block)