Problem/Motivation
Core will make media entity the standard wrapper for files. But file name currently does not bubble up to the media name (so this stays the originally uploaded file name). This is a PITA.
Even worse, there is no voodoo-free fix for this in custom hooks as
* the filefield_paths file name is generated in hook_media_insert/update which is *after* saving
In some cases this can be mitigated, but not if the logic relies on the actual file system name with possible serial suffix which is not known before file save.
Proposed resolution
* Move the filefield_paths logic to a late hook_entity_presave (which is after media field magick, see \Drupal\Core\Entity\EntityStorageBase::doPreSave)
* add an option "Adjust media name" if file field is on a media item
Remaining tasks
Code, test, commit.
User interface changes
Added option.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#3 | filefield_paths-2879540-3-Generate-file-name-in-presave.patch | 1.11 KB | geek-merlin |
Comments
Comment #2
geek-merlinComment #3
geek-merlinSimple patch flying in that implements this.
Comment #4
ptmkenny CreditAttribution: ptmkenny commentedI attempted to apply this patch because Filefield Paths is causing the generated media names on my site to be the temporary file name (example: _6b4f2e5a-d5d4-49cc-a184-3a2107a64f1a.jpeg) instead of the name generated with filefield paths (cat-waiting-at-the-window.jpeg).
Unfortunately, the patch no longer applies to the current version of the module so I'm marking as "Needs Work."