Pardon the slightly naive question, but I’m still working on my first block, and am new to both Gutenberg and React. For lots of reasons ([hopefully] simplicity, reusability, extensibility, etc…), I’m trying to use existing stuff wherever possible. In this particular case, I’m trying to use MediaPlaceholder, but I need to make a couple of modifications:
- I want to specify the directory that’s used, both for "upload" and for "media library"
- I want to change the link text for "Media Library" to something else
- I want to add a fourth option (beyond "Upload", "Media Library", and "Insert from URL")
I don’t want to do the above everywhere that MediaPlaceholder is called; only in my new plugin’s block.
The doc’s have a hook for a filter to "replace or extend" it, but I can’t find any examples of someone doing this; and, based on similar filters in other parts of the block editor, it seems like it’s mostly for "extend", and "replace" would be a PITA. Another possibility is to set the
disableMediaButtons prop, and add a child with my own buttons — but that seems like it would involve a ton of repetitive code. I also looked at React’s concept of "composition", which might be what I need, but if it is, I need a much better tutorial.
Am I thinking about this the right way? If I want a "placeholder" that lets someone upload files to a specific location, or point to a URL, or do something else (the specific something else is schedule a cron job, but I don’t think that detail matters), am I best off starting with MediaPlaceholder? And, if so, what’s the Right Way to go about modifying it to do this?