-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Filter Image Block attributes (or markup) when image is selected in Media Library #8472
Comments
It's a similar problem I've met: I'd like to output the image description field on the front-end. |
I'm a bit concerned about a front-end approach, since, if I'm understanding correctly, it'd move code written to be run once on image insert in the backend, to being run for every image every time a page is loaded on the frontend. In case it helps for context in a decision in either direction, here's the usage in the repo: |
Extending to add attributes on save should happen as block extension, with the caveat that it modifies source so it couples the source with the plugin (as already happens). The server extension keeps the markup source clean and flexible. It will always be a matter of tradeoffs. Pushing this to follow up milestones in case there are tangible proposals for improvements. |
@mtias This isn't quite a correct assessment of the issue. For this particular issue, we need a way of detecting when a new Image Block is inserted in order to only apply the behavior at that point. In Slack, you had mentioned something about comparing an empty |
@danielbachhuber Can this issue be closed? If not, what's left to be solved? |
@tomdevisser Sure, we can close it. I don't think it was ever solved, but it doesn't seem like it will be at this point. |
One of the plugins I work on, Tasty Pins, offers the ability to add "Pinterest Text" to an image (related #8473).
In the Classic Editor, the user can edit their Pinterest Text in the Media Library:
When the image is inserted into the post, the Pinterest Text is included as a
data-pinterest-description
data attribute:Even though all of this interaction is clientside, a plugin can modify the
<img>
image markup sent to the editor via theimage_send_to_editor
filter (ref):What's the best way to achieve equivalent behavior in Gutenberg?
One idea, albeit not necessarily a good one, is to make
onSelectImage
filterable:gutenberg/core-blocks/image/edit.js
Lines 113 to 128 in abb14b1
onSelectImage
seems to be common across Image, Cover Image, and Gallery Blocks. Other approaches?The text was updated successfully, but these errors were encountered: