一键导入
add-factory
Control how a resource is instantiated on Create — set defaults (timestamps, status), inject the creator, pre-fill relations from the URL.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Control how a resource is instantiated on Create — set defaults (timestamps, status), inject the creator, pre-fill relations from the URL.
用 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-factory |
| description | Control how a resource is instantiated on Create — set defaults (timestamps, status), inject the creator, pre-fill relations from the URL. |
| argument-hint | [ModelName] |
| allowed-tools | AskUserQuestion, Bash, Read, Edit, Write, Glob, Grep |
Ask the user if not provided:
ModelName).{ModelName}Factory.createNew() only, or also exposes a custom method (e.g. createForAuthor(string $authorId)) to be called via factoryMethod on the operation.src/Factory/{ModelName}Factory.php
<?php
declare(strict_types=1);
namespace App\Factory;
use App\Entity\{ModelName};
use Sylius\Resource\Factory\FactoryInterface;
final class {ModelName}Factory implements FactoryInterface
{
public function __construct(
// TODO: inject your dependencies (Security, related repositories, clocks…)
) {
}
public function createNew(): {ModelName}
{
$resource = new {ModelName}();
// TODO: set defaults (timestamps, status, owner…)
return $resource;
}
}
If the user needs a method that receives arguments (e.g. a route parameter), add it alongside createNew():
public function createForAuthor(string $authorId): {ModelName}
{
$resource = $this->createNew();
// TODO: resolve the Author via an injected repository and attach it
return $resource;
}
Two options — pick one:
createNew() is used for every Create)config/services.yaml:
services:
App\Factory\{ModelName}Factory:
decorates: 'app.factory.{model_snake}'
Your factory replaces the default for this resource everywhere it is auto-wired or used.
use App\Factory\{ModelName}Factory;
new Create(
factory: {ModelName}Factory::class,
factoryMethod: 'createForAuthor', // optional
factoryArguments: ['authorId' => "request.attributes.get('authorId')"], // optional, for custom methods with args
),
factoryArguments uses Symfony Expression Language. Available variables:
request — Symfony\Component\HttpFoundation\Requesttoken — authentication tokenuser — current userbin/console cache:clear
For option (a) — confirm the decorator is applied:
bin/console debug:container app.factory.{model_snake}
The resolved class should be App\Factory\{ModelName}Factory and the Tags row should contain container.decorator.
For option (b) — confirm the operation wiring:
bin/console sylius:debug:resource 'App\Entity\{ModelName}'
The Create operation's factory / factoryMethod / factoryArguments rows should show your configuration.
Create operations. Other operations do not use a factory./sylius-stack:add-provider./sylius-stack:add-processor.