`FileField::setUploadedFileNamePattern()` with closure not working as expected
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- PHP
- Stelle
- 4.3k
- Fork
- 1.1k
- Merge medio
- 2g 9h
- PR unite (30g)
- 52
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di EasyCorp/EasyAdminBundle
-
bug design
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
EasyCorp/EasyAdminBundle#7958 ·
I maintainer di solito rispondono entro 2 giorni
-
design feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
EasyCorp/EasyAdminBundle#7930 ·
I maintainer di solito rispondono entro 2 giorni
-
design
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 88/100
EasyCorp/EasyAdminBundle#7879 ·
I maintainer di solito rispondono entro 2 giorni
-
design
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
EasyCorp/EasyAdminBundle#7875 ·
I maintainer di solito rispondono entro 2 giorni
-
#[AdminRoute]: the requirements of an action silently replace the ones of the classForse già presa @anthonyhacart l’ha presa 1 giorno fa. Apertafeature
Difficoltà 3/5 Mezza giornata Idoneità per principianti 30/100
EasyCorp/EasyAdminBundle#7956 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di EasyCorp/EasyAdminBundle
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
taskforcesh/bullmq#5238 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] v-change-database-password reports success but doesn't change the password when MySQL validate_password rejects itForse già presa @bfs2021 l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Automattic/jetpack#55517 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
-
area/import type/enhancement when/later
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 1 giorno