When metadata is mapped to a field of a given entity, this metadata will update the field only if the field was empty. If metadata changes, the mapped field is not updated.
looking at the preSave method in the media entity class, where the mapping is handled, it seems to be intentionally this way. The given comment says
"Only save value in entity field if empty. Do not overwrite existing data.
@TODO We might modify that in the future but let's leave it like this
for now."
Is there any plan to change this behaviour? I think it would be better, if mapped fields would be updated, when the original data has changed as well.
Comments
Comment #2
slashrsm commentedWe would definitely like to make this logic a bit smarter. The main problem is that it is hard to reliably detect whether the field changed on the source or if there was a manual change on the Drupal's side. In first case you generally want to update it, while in the other you most likely don't.
One solution would be to make this configurable (on bundle or even on a field level). Maybe there is some better way. I am not sure.
Any suggestions?
Comment #3
marcoscanoPerhaps a first step could be to always update from the source when the fields mapped to meta-data are hidden from the form?
When these fields are then exposed to the user:
- They will be populated if empty
- They won't be modified if they contain any data
Does that make sense to improve things a little bit?
Comment #4
slashrsm commentedSolution proposed in #3 still have the potential performance problem. IF media type relies on 3rd party to fetch this metadata we'll have to call it on every save (think about Twitter API). I think that we want to avoid that.
Comment #5
marcoscanoIt is true that if we always update from source when the fields are hidden, we would be (potentially) degrading the performance, sometimes unnecessarily. (Although one could argue that the "mapping" functionality has this "inherent" drawback, because if I want to import/syncrhonize the retweet count, for instance, I need to accept that a new call will be needed on each entity save)
But I agree that a better solution would mean leaving this decision to the end user, and make everything configurable.
What about one of these 2 approaches:
Option 1 (configurable per bundle)
- When creating a media bundle, we have a new field settings for the bundle:
If the second option is checked, then we have a second config value:
This way the user could opt out of the automatic update for a given field, by just exposing the field on the entity form.
Option 2 (configurable per field)
On the bundle creation / edit form, we have a new field inside the "Field Mapping" fieldset, which would be a set of checkboxes for the existing mapping relations:
Comment #6
slashrsm commentedPer-field is better solution I think. It allows us to really define what we want. I also assume that in most cases people care just about a field or two being really up to date.
UI wise... Could we add a checkbox next to the existing mapping configuration?
Comment #7
scoff commentedI have file size mapped to a field (using media_entity_document) and it works on initial upload - the field gets populated. If I replace the file though the size stays the same. I really don't understand why it's the way it is. I know there's a similar issue with thumbnails.
I see what't the problem here, we don't want to overwrite some possible manual input, but what's the purpose of those mappings in this case? Let's force all the mapped fields hidden then. Is there a good use case for manually updating the mime type / file size / width / height or whatever?
Comment #8
dkh commentedI'm working on a project that would benefit from smarter metadata update logic. I might be able to assist in this (such as contributing a patch) or doing research.
It seems that the entity edit form could have a check box called "re-scan file metadata" -- for individual media enitities. Then on the "edit-media-bulk-form" form there could be a bulk action to rescan more than one entity. There shouldn't be any performance issues with this approach.
Comment #9
marcoscanoThere isn't much work done on this issue so far, and at this point no new big features are foreseen for the 1.x branch of this module. New feature requests should be done against core 8.4.x+.
Comment #10
marcoscanoForgot to close it.
Comment #11
spiffl commented@marcoscano media_entity_image links to this issue, see https://github.com/drupal-media/media_entity_image
Do you have specific pointers to the issues discussed above or is the idea to just recreate them individually against core?
Comment #12
marcoscanomedia_entity was added to core in #2831274: Bring Media entity module to core as Media module, and media_entity_image will be added to core in #2831937: Add "Image" MediaSource plugin.
I don't believe the feature request from this issue being discussed in any of those, but there are some issues (for example #2882801: Review and improve the media creation form or #2836153: Improve metadata mapping UI on Media type form) that are intended to improve the UI of the metadata when media is in core. I don't know if they will end up solving entirely the problem of the metadata not being refreshed when there is content in the fields. If that is the case, a new issue should probably be opened against core to deal with that.