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

Comments

marcoscano created an issue. See original summary.

seanb’s picture

The 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.

marcoscano’s picture

Status: Active » Needs review
StatusFileSize
new679 bytes

Yep, 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.

chr.fritsch’s picture

+1 for preventing the change of a source type.

Is it possible to prevent this on API level as well?

chr.fritsch’s picture

Maybe we could implement MediaAccessControlHandler::checkFieldAccess for that

chr.fritsch’s picture

Status: Needs review » Needs work
seanb’s picture

Issue tags: +Needs tests

This 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."

+++ b/core/modules/media/src/MediaTypeForm.php
@@ -126,6 +126,9 @@ public function form(array $form, FormStateInterface $form_state) {
+      '#disabled' => !empty($source),

#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.

marcoscano’s picture

Status: Needs work » Needs review
StatusFileSize
new2.19 KB
new2.1 KB

I 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?

seanb’s picture

Status: Needs review » Needs work

@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.

  1. +++ b/core/modules/media/src/MediaTypeForm.php
    @@ -118,14 +118,23 @@ public function form(array $form, FormStateInterface $form_state) {
    +      $source_description = $this->t('<em>The source plugin has been set and cannot be changed after the media type is created.</em>');
    

    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.

  2. +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php
    @@ -49,6 +49,10 @@ public function testMediaTypeCreationFormWithDefaultField() {
    +    $assert_session->pageTextContains('The source plugin has been set and cannot be changed after the media type is created.');
    

    Make sure we change the text here as well.

marcoscano’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new2.16 KB
new1.53 KB

@seanB thanks for reviewing!

seanb’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 10: 2928256-10.patch, failed testing. View results

chr.fritsch’s picture

Status: Needs work » Reviewed & tested by the community

Testbot hickup

larowlan’s picture

Adding review credit for @seanB

  • larowlan committed b5b3949 on 8.5.x
    Issue #2928256 by marcoscano, seanB: Users shouldn't be able to change...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed 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

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.