Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Documentation for how to preserve/sanitize the original file name and custom alt text in repeatable field #32

Open
aerostah opened this issue Jun 17, 2024 · 0 comments
Assignees

Comments

@aerostah
Copy link

Feature Request

Thank you for putting together this integration, it will be very helpful to my use case once I can overcome these obstacles.

What I am trying to achieve

I'd like more control over how file names are stored in the media library, so I can reference them in the frontend. In my PageCrudController I've setup a repeatable field that uses withMedia, for the most part it works, I can successfully upload files, but my troubles start where your documentation stops -- I cannot get the certain values stored in the media table.

file_name and alt_text
I'd like the file_name column to take the original file name of what I uploaded, ideally after sanitizating it, shown here in the "sanitize the filename using a callable" example. If this cannot easily be achieved, then I'd defer to using a subfield to store a manually typed file name, so I can pass that value into the usingFileName method. Secondly, I need to associate image alt_text with each uploaded image, I plan to key in that data in another subfield named alt_text and use the customProperties method to store it.

Is there a clean way get the subfield data associated with each image into the whenSaving function?

collection_name
For my web app, I set the collection to the slug, this way I can filter the media in the frontend controller. Is there a better way to set the collection name because the slug doesn't exist until after the record is created, requiring to user to save once before uploading media?

name
This currently uses the of the repeater field's name. This makes sense for situations where there are multiple repeatables w/ images.

How I see it implemented

'withMedia' => [
   'collection' => $this->crud->getCurrentEntry()->slug,
   'whenSaving' => function($spatieMedia, $backpackMediaObject, ?????) {
   return $spatieMedia->usingFileName(?????->getClientOriginalName())
   ->withCustomProperties([
       'alt_text' => ?????
   ])
   ->withResponsiveImages();
   }
],

As you can see, the documentation got me most of the way there, it could use a strong finish! Hopefully I explained this clearly, I look forward to seeing what you suggest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

No branches or pull requests

2 participants