Problem/Motivation
Thanks for the excellent module! My content authors are so happy.
It would be nice for the edit button to be available even if the parent entity (e.g. node) is not yet saved.
Currently the edit button is not added to media if the parent entity has not yet been saved. This logic appears in media_library_edit_field_widget_form_alter:
$entity = $context['items']->getEntity();
if (!$entity || !$entity->id()) {
// Bail out if parent entity is not yet saved.
return;
}
$edit_url_query_params = [
'media_library_edit' => 'ajax',
'media_library_edit_field_name' => $context['items']->getFieldDefinition()->getName(),
'media_library_edit_entity_type' => $entity->getEntityTypeId(),
'media_library_edit_entity_id' => $entity->id(),
];
However, after #3242982: Follow-up: On fields with multiple media items, other items disappear after saving, these query parameters are no longer needed or used. And that's the only place the $entity variable is used. Therefore we should be able to allow the edit button even if the parent entity is not yet saved.
Steps to reproduce
- Click "Add new content" and pick a content type that has a media field using the media library widget.
- Before saving the node, add media to the media field
- The edit pencil is not available
- Save the node
- Edit the node
- The edit pencil is available.
I want the edit to be available in step 3. The node is not yet saved, but we should still be able to edit the media.
Proposed resolution
Remove the dead code.
Profit.
Remaining tasks
Patch to follow quickly.
Tell me if I'm missing something! I'm new to the module. :)
User interface changes
Edit pencil available even if parent entity is not saved.
API changes
node
Data model changes
none
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | media_library_edit-unsaved_node-3278706-2.patch | 1.42 KB | danflanagan8 |
Comments
Comment #2
danflanagan8Here's the patch that (hopefully) makes the magic happen. It appears to work for me locally, but like I said, I'm new to the module. There may be something I'm missing. :)
Comment #3
andybroomfieldThanks for the patch @danflanagan8 I've installed this and verified that I can now see the edit media button, and edit media before the node has been saved. When I do save the node the media is present as expected.
Comment #4
bisonbleu commentedJust tested this on simplytest.me with 9.4 alpha 1. Patch works as advertised. Thanks @danflanagan8!
Comment #6
ahebrank commentedThanks for the cleanup. I'll do a patch release for this shortly.