Problem/Motivation

Once the Media module currently doesn't ship enabled by default on the standard profile, we can't assume the state of the image styles when the module is installed.

I have reproduced two bugs related to this so far:

Bug 1: Missing "thumbnail" image style breaks media add form for image type

Steps to reproduce:

1) Go to simplytest.me and install Drupal Core 8.5.x and Devel
2) Go to /admin/config/media/image-styles and delete the "thumbnail" image style
3) Enable the Media module by going to /devel/php and executing: \Drupal::service('module_installer')->install(['media']);
4) Try to create a media image item by going to /media/add/image

You will see that the form has no image field:

And that's because the field is disabled on the form view settings:

Bug 2: Missing "medium" image style prevents default view display from being installed

In #2895382: Hide label, thumbnail, etc. for default display of media file and image references we improved the default entity view display of media images by providing some defaults.

However, if, before installing the Media module, the site has deleted the "medium" image style, the core.entity_view_display.media.image.default.yml config won't be installed due to the missing dependency.

As a result, the image media default view display will show something like:

Instead of the expected default, which was something like:

Proposed resolution

Agree on the best way to solve this and implement it. After discussing with seanB on IRC, some options appeared:

1) Delete the dependency on the "medium" image style, and show the original image by default (only applies to Bug 2)
2) Re-create the missing image styles in hook_install(). I'm not sure, however, if the config import would already have been attempted by then, in which case this creation here would be useless. (applies to both bugs)
3) Ship our own media-specific image styles and use them. (applies to both bugs)
4) Something else?

Remaining tasks

User interface changes

API changes

Data model changes

Comments

marcoscano created an issue. See original summary.

marcoscano’s picture

Title: Missing image style prevents default media config from being installed » Missing image styles during "Media" install causes issues in media form and view display.
Issue summary: View changes
StatusFileSize
new26.84 KB
new46.2 KB

Turns out there is a bigger problem, if you delete the thumbnail image style.
Updated the IS accordingly.

seanb’s picture

Thanks for testing this marcoscano. I see a couple of possible solution right now:

  1. We could ship with new media-specific image styles
  2. Conditionally reinstall the image styles we need from the image module when enabling the module
  3. Detect missing image styles and ask the user for replacement image styles on install
  4. Remove the dependencies on image styles and show the original image

I think option 2 might be the best way, but if anyone has other ideas they are more than welcome.

marcoscano’s picture

I'm also in favor of just recreating the missing image styles. To make it more evident, we could show a message on the UI letting the user know this was done. However, I'm not sure if these messages during module install could cause issues with people installing from the command line, or as part of a deployment / build script.

chr.fritsch’s picture

If we want to go with option 2 we could implement hook_module_preinstall in the standard profile.

phenaproxima’s picture

I would prefer that we don't recreate the image styles. I can imagine this having unexpected repercussions during config sync, in addition to being mysterious to users: if you installed something other than Standard, something with doesn't have the correct image styles, you expect them not to be there. Media recreating them will look like a bug, and potentially frustrate site builders.

IMHO, we should simply fall back to the original image, without any style applied, if the desired style does not exist.

seanb’s picture

For the missing medium image style that could be an acceptable alternative. For the missing thumbnail style that is a bigger issue. If you install media and the media browser (the last patch isn't finished, but still), you would see a modal showing all the original images.

I agree re-installing the image styles could lead to confusion, but at least everything will look nice by default. We can inform the users it happened and they can replace and delete the image styles if they want. Not doing anything and having original images messing up the layout would be a bigger problem to me.

marcoscano’s picture

In Bug 1, I believe what's happening is that the image widget requires the thumbnail image style by default. If it's not present, the component is directly hidden in the form display. While showing the original image inside the widget would still be better than missing the field entirely, it would probably look quite bad, and I'm not sure the benefit of "not creating anything magically" outweights how this would look like. I'm really doubting between the two options, I see pros and cons in both.

Maybe some screenshots with different scenarios would help take the best decision?

robpowell’s picture

Issue summary: View changes
StatusFileSize
new48.35 KB
  1. Go to simplytest.me and install Drupal Core 8.5.x and Devel
  2. Select standard profile
  3. Go to /admin/config/media/image-styles and delete the "thumbnail" image style
  4. Go to /admin/modules and enable Devel
  5. Enable the Media module by going to /devel/php and executing: \Drupal::service('module_installer')->install(['media']);

This was as far as I could get before hitting an error:

The website encountered an unexpected error. Please try again later.

xjm’s picture

Priority: Normal » Major
marcoscano’s picture

I was thinking a bit more about this, pondering the weirdness of "something that you deleted appearing back again" (if we re-created the styles), versus something "looking really off" (if we fallback to the original images), and maybe a good solution to both issues could be just to use our own styles? We could, for example:

1) ship a media_big or media_hd image style, big enough to fill most screens, but without the risk of showing the original 10Mb image an angry user uploaded. (This would also be useful in other places, as pointed out in #2934850-9: Media Images should be rendered at a reasonable size by default, a concern I wholeheartedly agree with).

2) use that style in core.entity_view_display.media.image.default.yml, solving Bug 2

3) have a hook_post_update_NAME() or some similar mechanism to detect whether the config objects depending on the thumbnail image style were not installed due to the image style not present. If that's the case, then we create there our own media_thumbnail image style, and create the form display with the widget using this style. This way, Bug 1 is solved, and we don't really need to either re-create thumbnail again, or rely on the original image for the widget. I guess we could also use the media_big style here if we wanted, but IMHO I still think having a huge image for an image widget will be very confusing.

Thoughts?

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Jaesin’s picture

In my opinion, it's not that big of a deal that installing the media module would recreate some missing image styles.

  1. Most site builders don't remove the default image styles so we are talking about avoiding a rare use case.
  2. The repercussions of recreating an image style that was already removed from the system is easily remedied if it is even noticed.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

luke.stewart’s picture

This is the daily target for The Bug Smash Initiative "Last Updated Core Issue Queue page"

I've just verified this on 11.3.2 following the steps above - modified (removing both thumbnail and media image style - and installing via the UI)

I've added https://www.drupal.org/project/drupal/issues/2940205 as a related issue.

It seems live from reading the above the next steps required here are to either mark this as works as designed, or decide on a solution.

Given the lack of engagement over the last 8 years I think I'd lean towards closing works as designed.

However while it might be true that

"The repercussions of recreating an image style that was already removed from the system is easily remedied if it is even noticed."

I think the problem would be understanding that this is what has caused the issue - as there is no indication via the UI that this is what has caused the issue.

If we do want to accept this behaviour perhaps it would be okay to flag the missing config on install via a warning? Then leave it up to the site builder as to how they want to handle it?

marcoscano’s picture

Thank you for bringing this back to life :)

If we do want to accept this behaviour perhaps it would be okay to flag the missing config on install via a warning? Then leave it up to the site builder as to how they want to handle it?

I am not a huge fan of messages displayed during module installs, because not all modules are installed through the UI, and in certain scenarios it can add noise or even break some CI scripts. That said, many modules do that, and informing users that there's something off is certainly better than the current status quo. So I'd be +1 for detecting the missing styles, and logging that as an error condition both in Drupal's watchdog and on a message to the user.