一键导入
extends-form
Expose a custom field in an existing Sylius admin form (Product, Taxon, Channel, …) via a Symfony FormTypeExtension, Twig hook and translation
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Expose a custom field in an existing Sylius admin form (Product, Taxon, Channel, …) via a Symfony FormTypeExtension, Twig hook and translation
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | extends-form |
| description | Expose a custom field in an existing Sylius admin form (Product, Taxon, Channel, …) via a Symfony FormTypeExtension, Twig hook and translation |
| argument-hint | [TargetModel] [FieldName] |
| allowed-tools | AskUserQuestion, Bash, Read, Edit, Write, Glob, Grep |
Ask the user if not provided:
Product, Taxon, Channel, Customer)metadataTitle)TextType, TextareaType, IntegerType, CheckboxType) or a custom type such as {Related}AutocompleteType for a relationfalse)general). To list available sections, on Sylius 2.3+:
bin/console sylius:debug:twig-hooks sylius_admin.{target_model_snake}
On older versions, fall back to bin/console debug:config sylius_twig_hooks.Prerequisites:
/sylius-app:extends-model first for a Sylius core entity, or add the column on your own resource./sylius-app:add-autocomplete first so {Related}AutocompleteType exists.bin/console sylius:debug:resource sylius.{target_model_snake}
The classes.form row in the output is the FormType FQCN used by the admin. Use it directly as the use statement and as the getExtendedTypes() return. Without an argument, the command lists every resource alias.
src/Form/Extension/{TargetModel}/{TargetModel}TypeExtension.php:
<?php
declare(strict_types=1);
namespace App\Form\Extension\{TargetModel};
use {TargetFormFqcn}; // value returned by step 1
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\{FieldType}; // or your custom type
use Symfony\Component\Form\FormBuilderInterface;
final class {TargetModel}TypeExtension extends AbstractTypeExtension
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('{field_name}', {FieldType}::class, [
'label' => 'app.form.{target_model_snake}.{field_name}',
'required' => {required},
]);
}
public static function getExtendedTypes(): iterable
{
return [{TargetModel}Type::class];
}
}
Add to config/services.yaml:
services:
app.form.extension.{target_model_snake}_type:
class: App\Form\Extension\{TargetModel}\{TargetModel}TypeExtension
tags:
- { name: form.type_extension }
templates/admin/{target_model_snake}/form/sections/{section}/{field_name}.html.twig:
{{ form_row(hookable_metadata.context.form.{field_name}) }}
One file per action under config/packages/twig_hooks/{target_model_snake}/. Loaded via the imports: block at the top of config/packages/_sylius.yaml (add - { resource: "twig_hooks/**/*.yaml" } if not already there).
If files already exist for this target (from a previous extends-form run), add the new entry under the existing hook key — do not overwrite.
config/packages/twig_hooks/{target_model_snake}/create.yaml:
sylius_twig_hooks:
hooks:
'sylius_admin.{target_model_snake}.create.content.form.sections.{section}':
{field_name}:
template: 'admin/{target_model_snake}/form/sections/{section}/{field_name}.html.twig'
priority: -100
config/packages/twig_hooks/{target_model_snake}/update.yaml — same content, replace .create. with .update..
A negative priority places the field at the bottom of the section without renumbering existing entries.
Get the project's default locale:
bin/console debug:container --parameter=kernel.default_locale
Add to translations/messages.{locale}.yaml:
app:
form:
{target_model_snake}:
{field_name}: '{Field label}'
bin/console cache:clear
bin/console debug:form '{TargetFormFqcn}' (FQCN from step 1) lists {field_name} among the type's fieldsbin/console debug:translation {locale} --domain=messages 2>&1 | grep 'app.form.{target_model_snake}.{field_name}' finds the label./sylius-app:extends-model (typical paired workflow: extend the entity, then expose the field here)/sylius-app:add-autocomplete/sylius-app:extends-gridImplement 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