`FileField::setUploadedFileNamePattern()` with closure not working as expected
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start by reproducing the create and edit cases described in the issue, then inspect StringToFileTransformer and the upload field's submission flow. Determine where the filename callback runs relative to parent-form mapping, and identify the relevant tests or entry points for that flow. Done means the callback can use the submitted year and produces filename-2037.pdf or filename-2038.pdf as appropriate.
Written by the indexing model from the issue text.
Description
Describe the bug
I want to generate an uploaded PDF’s filename using the event’s year entered in the same form.
However, the entity passed to the setUploadedFileNamePattern() callback does not yet contain the submitted values.
When creating an event with year = 2037, the callback sees year = null and generates filename-.pdf instead of filename-2037.pdf. The saved entity correctly contains 2037.
To Reproduce
Create an Event entity with a year property initially set to null, a getYear(): ?int getter, and a media property storing the uploaded filename.
Create a CRUD with these fields:
IntegerField::new('year', 'Year'),
FileField::new('media', 'File')
->hideOnIndex()
->setBasePath('uploads/events')
->setUploadDir('public/uploads/events')
->setUploadedFileNamePattern(
fn (UploadedFile $file, Event $event): string =>
'filename-'.$event->getYear().'.[extension]'
)
->mimeTypes('.pdf'),
Create a new event, enter 2037 as the year, upload a PDF, and save.
Expected filename: filename-2037.pdf.
Actual filename: filename-.pdf.
(OPTIONAL) Additional context
EasyAdmin version: 5.6.1.
The issue also occurs when editing an event: changing the year from 2037 to 2038 and uploading another PDF generates filename-2037.pdf instead of filename-2038.pdf.
StringToFileTransformer invokes the filename callback during the upload field’s submission, before Symfony maps the parent form’s submitted values to the entity. Placing the year field before the upload field does not resolve the issue.
I am not sure if this is expected, but passing the entity before mapping is not really helpful.
- Dominant language
- PHP
- Stars
- 4.3k
- Forks
- 1.1k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 52
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from EasyCorp/EasyAdminBundle
-
bug design
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
EasyCorp/EasyAdminBundle#7958 ·
Maintainers usually reply within 2 days
-
design feature
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
EasyCorp/EasyAdminBundle#7930 ·
Maintainers usually reply within 2 days
-
design
Difficulty 2/5 Under an hour Newbie friendliness 88/100
EasyCorp/EasyAdminBundle#7879 ·
Maintainers usually reply within 2 days
-
design
Difficulty 1/5 Under an hour Newbie friendliness 90/100
EasyCorp/EasyAdminBundle#7875 ·
Maintainers usually reply within 2 days
-
#[AdminRoute]: the requirements of an action silently replace the ones of the classPossibly taken @anthonyhacart claimed this 1 day ago. Openfeature
Difficulty 3/5 Half a day Newbie friendliness 30/100
EasyCorp/EasyAdminBundle#7956 ·
Maintainers usually reply within 2 days
All issues in EasyCorp/EasyAdminBundle
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
area/import type/enhancement when/later
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
parime/glpi-iso27001-management#1165 ·
Maintainers usually reply within 1 day
-
15.0
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
opnsense/plugins#5976 · 1 comment ·
Maintainers usually reply within 1 day