/symfony:symfony-formfrom symfony
Guides Symfony developers on FormType conventions: using data_class as single source of truth, placing DataTransformers in forms (not controllers), and using property_path for collection mapping.
Ships in symfony. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
data_class Is the Single Source of TruthAll form data must flow through the data_class, not through options.
Options configure the form type behavior (labels, choices, validation rules), not transport data.
// ❌ AVOID - Data passed as options
$this->formFactory->create(IdentityDocumentType::class, $data, [
'customer_birth_date' => $birthDate,
'existing_files' => $existingFiles,
]);
// In configureOptions:
$resolver->setRequired('customer_birth_date');
$resolver->setRequired('existing_files');
// ✅ CORRECT - Everything is in the data_class
$this->formFactory->create(IdentityDocumentType::class, new IdentityDocument(
customerBirthDate: $birthDate,
existingFiles: $existingFiles,
));
// The FormType accesses data via $options['data']
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$identityDocument = $options['data'];
$existingFiles = $identityDocument->existingFiles;
}
The conversion between Symfony's native form objects and application model objects belongs in a DataTransformer, not in the controller.
The controller must only manipulate model objects, never form-internal types.
// ❌ AVOID - Conversion in the controller
foreach ($fieldNames as $fieldName) {
$file = $formData->getFileByFieldName($fieldName);
if ($file instanceof UploadedFile) {
$uploadFile = new UploadFile(
file_get_contents($file->getPathname()),
$file->getClientOriginalName(),
);
}
}
// ✅ CORRECT - DataTransformer in the FormType
$builder->get($fieldName)->addModelTransformer(new CallbackTransformer(
static fn (): mixed => null,
static fn (?UploadedFile $file): ?UploadFile => $file instanceof UploadedFile
? new UploadFile(
file_get_contents($file->getPathname()),
$file->getClientOriginalName(),
)
: null,
));
// The controller only manipulates model objects
foreach ($formData->getUploadFiles() as $file) {
// $file is already a model object
}
property_path for Non-Standard MappingsUse property_path to map multiple fields to an indexed collection, instead of creating a getter/setter per field.
// ❌ AVOID - One property per file
final class FormData
{
private ?UploadedFile $frontFile = null;
private ?UploadedFile $backFile = null;
private ?UploadedFile $passportFile = null;
public function getFrontFile(): ?UploadedFile { ... }
public function setFrontFile(?UploadedFile $file): void { ... }
// ... x3 getters/setters
}
// ✅ CORRECT - A collection with property_path
final class FormData
{
private array $uploadFiles = [];
public function getUploadFiles(): array { return $this->uploadFiles; }
public function setUploadFiles(array $files): void { ... }
}
// In the FormType:
foreach (FieldName::ALL as $fieldName) {
$builder->add($fieldName, FileUploadType::class, [
'property_path' => sprintf('uploadFiles[%s]', $fieldName),
]);
}
| Rule | Principle |
|---|---|
Data → data_class | Never in form type options |
| Form → model conversion | DataTransformer, not the controller |
| N fields → 1 collection | property_path to an indexed array |
| Zero-option form | If the data_class carries everything, no custom options |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
5 skills in this plugin
/prg-patternACTIVATE when implementing form handling, POST endpoints, or any controller that modifies data. ACTIVATE for 'form submission', 'POST redirect', 'PRG', 'duplicate submission'. Covers: POST success always redirects, POST error re-renders (no redirect), flash messages after redirect. DO NOT use for: FormType design (see symfony:symfony-form), API endpoints returning JSON./symfony-frontendACTIVATE when adding or modifying frontend behaviour in a Symfony project — any new feature whose Twig template would otherwise contain inline script or style blocks, or any new JS/CSS file to load for a specific page. ACTIVATE for 'inline script in twig', 'inline style in twig', 'WebpackEncore', 'addEntry', 'encore_entry_link_tags', 'encore_entry_script_tags', 'where to put my JS', 'how to load CSS for one page', 'FormType injecting class', 'js- hook in template'. Covers: forbidden inline script/style tags in Twig, one Encore entry per feature, per-page asset loading via stylesheets/javascripts blocks extending parent, SCSS imported by the JS module (one entry bundles both), FormType stays domain/server (no CSS-only classes via `attr`), `js-*` hooks added at render time. DO NOT use for: jQuery style (see jquery:jquery), Twig conventions (see symfony:twig-conventions), FormType conventions (see symfony:symfony-form), autonomous visual debugging (see frontend:frontend-best-practices).Other plugins' skills for the same job
npx claudepluginhub fabiensalles/claude-marketplace --plugin symfony