Problem/Motivation
Currently it's possible to perform the following steps:
1) Create a media type using any source plugin (for instance: "Instagram")
-> This will auto-generate the source field field_media_instagram of the type Text (plain)
2) Go back to the media type edit form and change the "Media source" to use the Image plugin
This will result in a media type that uses the source plugin Image, but with a source field of a type that is not one of the allowed types defined in the plugin's annotation.
I'm not even sure if we should allow changing source plugins once the type is created, but in any case, I believe we should at least prevent this field mismatching from happening.
Proposed resolution
1) Decide if it should be possible to change the source plugin once the type is created
2) If it should be possible, restrict the available source plugins in the dropdown to only show plugins that accept source fields of the type the current media type is using as source field (if any).
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | interdiff-8-10.txt | 1.53 KB | marcoscano |
| #10 | 2928256-10.patch | 2.16 KB | marcoscano |
| #8 | interdiff-3-8.txt | 2.1 KB | marcoscano |
| #8 | 2928256-8.patch | 2.19 KB | marcoscano |
| #3 | 2928256-3.patch | 679 bytes | marcoscano |
Comments
Comment #2
seanbThe source field type and also the provided metadata are very media source specific. Changing media source could potentially get you into all kinds of trouble, so +1 for not allowing this to be changed through the interface.
Changing the source will probably not be a 80% use case. If this really needs to be changed in some cases there could be a contrib module that supports this or you could write a custom update hook when needed.
Comment #3
marcoscanoYep, I agree that the safest is just to prevent changing the source at all, once the type is created.
The patch attached should be enough for that.
Comment #4
chr.fritsch+1 for preventing the change of a source type.
Is it possible to prevent this on API level as well?
Comment #5
chr.fritschMaybe we could implement MediaAccessControlHandler::checkFieldAccess for that
Comment #6
chr.fritschComment #7
seanbThis needs some tests as well. Besides that, I'm not sure if we should use a disabled field or should just show a message. I think we should at least add a explanation that the source setting can not be changed.
Maybe we can add a message like the one you see when changing field storage settings:
"The media source impact the way that data is stored in the database and cannot be changed once data has been created."
#5, not sure if we want to prevent this on API level, what would we gain from doing that? There could be use cases for this, especially when we starting adding different oEmbed based providers that all kind of add the same metadata.
Comment #8
marcoscanoI don't have strong feelings either way, but I lean towards preferring to leave the door open to change it at API level, once we never know what sorts of crazy things people will want to do with contrib or custom code. Preventing "normal" users from messing up things through the UI seems to be good enough for me.
@seanB, in the user-message you suggested in #7 you mention "data has been created". Do you really mean we should check if there is media items of that type, and only preventing the change if there is data, or it was just a wording thing?
Comment #9
seanb@marcoscano, it would be nice to allow changes as long as you don't have media assets, but that could be a followup. This already fixes the most important issue. I just copied the message from the field storage settings form.
We should probably not use the term "plugin" here.
So maybe:
Media source cannot be changed after the media type is created.
Terminology is not my strongest suit though.
Make sure we change the text here as well.
Comment #10
marcoscano@seanB thanks for reviewing!
Comment #11
seanbLooks good to me! Created #2928851: Allow the media source of a media type to be changed when creating a new media type as a followup.
Comment #13
chr.fritschTestbot hickup
Comment #14
larowlanAdding review credit for @seanB
Comment #16
larowlanCommitted as b5b3949 and pushed to 8.5.x.
This can't be backported to 8.4.x because it has a new translatable string/string change