As per a discussion with webchick, the usability of the responsive images UI would be greatly improved if there were intelligent defaults that site builders could select.
Problem/Motivation
Responsive images can be complicated, particularly when using sizes for viewport sizing, even though that is the best practice. While we have a patch that cleans up the UI and improves the help text, having site builders start from scratch makes it intimidating to actually use responsive images.
Proposed resolution
Provide a default breakpoint group called viewport sizing with an empty breakpoint that can be used for this primary use case. Create two default responsive image styles, wide and narrow, which can be used in main content areas and sidebars (or floated in main content areas) accordingly. These will require at least two new image styles so images will look good on high-resolution screens.
While these responsive image styles may not be ideal for every theme layout, that is also true for the default image styles in core. This at least provides examples that may work reasonably well.
Remaining tasks
- Create default breakpoint group and breakpoint in Breakpoint module
- Create new default image styles
- Create default responsive image styles in Responsive Image module
User interface changes
This will provide default options for those using responsive images.
API changes
None.
Data model changes
None.
Beta phase evaluation
| Issue category | Task because this is required for a major issue (https://www.drupal.org/node/2334387) that is a follow-up to a recent critical change (https://www.drupal.org/node/2260061) |
|---|---|
| Issue priority | Major because this is required for another major, which is a follow-up to a recent critical change. This greatly improves the UX of using responsive images. |
| Prioritized changes | The main goal of this issue is improve usability for the new sizes attribute. Making this easier to use will give Drupal 8 full ability to make use of the responsive images specification, which ultimately means better front-end performance for Drupal 8 sites. This is also a follow-up change to a recent critical, https://www.drupal.org/node/2260061./td> |
| Disruption | This adds new defaults but does not change existing defaults. |
Comments
Comment #1
rainbowarrayHere is a first patch that adds the default breakpoint group, breakpoint, image styles and responsive image styles.
Comment #2
rainbowarrayComment #4
rainbowarrayHad some extra things in the previous patch. This revised version also eliminates one of the image styles. The new styles are named Gigantic and Huge, which just so happens to order the styles from largest to smallest.
Comment #6
rainbowarrayIn theory this should fix the test fails.
There was a capitalization error in one of the image style definitions, and I think the formatting of the breakpoints.yml file was wrong. Also needed to fix a test since there is an additional breakpoint group now.
Comment #8
rainbowarrayFixed a couple more bugs in expected UI text and ordering of breakpoint groups by label.
Comment #10
rainbowarrayFixing patch based on error report.
Comment #11
attiks commentedthis doesn't look right, see http://cgit.drupalcode.org/drupal/tree/core/modules/toolbar/toolbar.brea...
Comment #12
jelle_sI moved the new 'Viewport Sizing' breakpoint from the breakpoint module to the responsive_image module because the breakpoint wouldn't make much sense without responsive images. I renamed the group to responsive_image.all because of it. Then I fixed the 'group' property for the breakpoints. Tests should be green.
(BTW: your patch in #10 was empty so I had to reconstruct it using the patch in #8 and the interdiff in #10 ;-) )
Comment #13
rainbowarrayThe trouble with the new name for the breakpoint group, is that it looks very unfriendly in the UI: 'responsive_image.all' vs 'All viewports'
I haven't been able to figure out how to add a human-friendly name for a breakpoint group besides just using that as the name (which does seem to work, even if it's wrong).
Is there any way to do so? There are no schema files for breakpoints.yml files and very little documentation on how they should be written. Would be great to get that into the docs.
Comment #14
attiks commented#13 Valid point regarding the name, we need to figure out a way to fix this
Comment #15
rainbowarrayAdded #2538884: Add labels and weights for breakpoint groups to discuss custom breakpoint group labels (and possibly weights).
Comment #16
rainbowarrayIn light of the fact that we cannot create human-friendly breakpoint group labels, this patch removes the custom group so that the Viewport Sizing breakpoint shows up under the Responsive Image breakpoint group, and Responsive Image shows up as the default breakpoint group. The All Viewports label would have been good, but this is still pretty user-friendly I think.
This patch also updates a test to account for the change in the breakpoint group.
Comment #17
larowlanI recall that we don't include UUIDs in default config
Comment #18
rainbowarray@larowlan: The existing image styles in core have uuid's, so I kept those for the new image styles and responsive image styles. Certainly can remove those, just trying to follow the pattern already in core.
Comment #19
attiks commentedPatch looks good to me and makes it easier for people to use sizes
Comment #22
jelle_sComment #23
alexpottThese image styles might not exist. Someone could delete them before installing responsive image. Not sure what to do.
Comment #24
attiks commentedWe can always provide our own image styles to avoid it?
Comment #25
rainbowarrayHere's a patch that adds default image styles within the responsive images module so that the responsive image module is entirely self-sufficient upon installation.
I added more default image styles to fully provide sensible defaults for how responsive images work. It's a lot of image styles, yes, but any site that actually uses responsive images is going to end up with a ton of image styles. So we might as well do this right if we're going to provide defaults.
Also, it should be noted that these responsive styles won't look right in the UI until #2334387: UI changes to support current responsive image standards goes in.
Comment #26
rainbowarrayHelps if I add the patch.
Comment #27
attiks commentedWhy the need to upscale? I think it is safer to never upscale.
Comment #28
rainbowarrayIn most cases an image needs to fill a certain amount of space in a layout. Not upscaling means you may get lower-quality images uploaded that break a layout. That's why I also prefer width 100% to max-width 100% for img styles.
Comment #29
attiks commented##2 True, but upscaling means PHP will upscale and lower the image quality, while creating a bigger file, that will get downloaded by the browser.
If we don't upscale a themer can still decide to add
width: 100%risking the upscaling effect.Comment #30
rainbowarrayHere's a revised patch with upscaling turned off. This keeps these styles consistent with those in the image module. As attiks pointed out, undersized images can still be upscaled in the browser when width: 100% is set.
Comment #31
attiks commentedAssuming bot will be happy, back to RTBC
Comment #32
rainbowarrayDiscussed this with webchick. Narrowing down the list of image styles to not overwhelm the user interface. This still provides sensible defaults for the narrow and wide responsive image styles, just with fewer in-between style options.
Comment #33
webchickHad a call today with @mdrummond and @Bojhan where this patch came up.
When demoing the patch, Marc showed the list of image styles approximately quadrupling in size, with numerous very similarly-named options (Max 325x325, Max 400x400, Max 600x600, etc. times about 12 or 16).
The problem is:
a) All of those additional image styles selections are going to show up everywhere that image styles are used in configuration: display modes, views, etc., not just encapsulated within responsive image's configuration.
b) There is no clear signal to end users why all of those sizes are predefined. In talking to Marc it's basically:
Narrow: small, medium, large, plus retina for each.
Wide: small, medium, large, plus retina for each.
However, this is very hard to tell from just raw pixel sizes.
c) And even if we were to rename these with more "human-readable" names, the fact is that each individual site needs to decide for itself what form factors/viewport sizes it wants to support. Core currently ships with three image styles: Thumbnail, Medium, and Large with some opinions on what those sizes should be. Many sites override these, and for ~three image styles that's basically fine. But if you have to go in and edit an additional ~12 image styles, each with almost identical names, that will get both very confusing and very irritating very fast.
So Marc and I discussed a compromise which is still providing additional image styles, still naming them "Max XXX" so we don't need to come up with nonsensical English words that happen to flow alphabetically, but limit it to just 4 sizes: 325x325, 600x600, 1300x1300, 2600x2600. This allows for a Narrow/Wide regular/retina, and individual sites can extrapolate from there.
Comment #34
rainbowarrayOne last note that naming the image styles Narrow Small/Medium/Large and Wide Small/Medium/Large is also challenging, because the Narrow responsive image style might need to use some of the image styles with the Wide names, and the Wide responsive image style would need to use some of the image styles with the Narrow names. So a reduced set of image styles with the Max name still works as defaults but hopefully causes less confusion.
Comment #35
attiks commented#32 Looks good and agree on the naming
Comment #36
alexpottSo I'm wondering if we can put this all in the standard profile - so if you install in minimal it stays minimal. One thing we need to do if to add an enforced dependency on responsive image module. See the node type provided by the book module for an example. It also needs to go in a new folder in standard config/optional... This should also result in this patch not changing tests. Well, I think that StandardTest should assert the new optional config does not exist until the responsive image module is installed.
Comment #37
attiks commentedI'll have a try later today.
Comment #38
attiks commentedIf I understand correctly the attached patch is correct, but when I enable the responsive_image module, the optional config isn't loaded, I tried with and without adding the enforced.
PS: If I add responsive_image as a dependency for the standard profile, everything works.
Comment #39
attiks commentedComment #40
attiks commentedAccording to #2453919: all installed modules' config/optional directories are searched for any configuration entities of the new type
So this doesn't work for profiles?
Comment #42
attiks commentedIt wasn't working for optional config in install profiles, fixed it
Comment #43
attiks commentedFix added for failing tests
Comment #45
attiks commentedTests added to StandardTest to make sure the image styles are not installed by default.
Comment #47
attiks commentedTests extended to make sure the optional styles are installed once responsive_image is enabled.
Comment #49
attiks commentedBack tot Alex to make sure this is good
Comment #50
alexpottI need to review exactly what this is going to do. And it needs further testing... but the idea of having optional config in install profiles is sound. And perhaps deserves it's own issue.
This is not necessary the dependency is implied from the name of the configuration object.
Comment #51
attiks commented1. There's a test added to make sure the optional config gets read, not sure what else I can do. Unless you mean you want to have the tests somewhere else as well, so they don't depend on the install profile and/or responsive_image module.
2. Removed the lines
Comment #52
rainbowarrayManually tested this, and I can confirm the image styles and responsive image styles do not show up on the minimal profile after enabling the responsive image module, while they do on the the standard profile.
Standard profile: before enabling responsive image module

Standard profile: after enabling responsive image module


Minimal profile: after enabling responsive image module


Comment #53
rainbowarrayBack to RTBC.
Comment #54
alexpottThe extra call to installDefaultConfig() doesn't make sense since this means that we have to loop through a lot of stuff twice. We can fix this in a different way. What I mean by tests is that this ability to install default configuration from profiles should be part of the configuration tests not hidden in the StandardTest where it's testing responsive_image.
Comment #56
alexpottAh not so simple - fortunately we have tests... patch adds a test around the new ability of profiles to provide completely new optional configuration.
Comment #57
rainbowarrayManually tested again. Image styles and responsive image styles added with standard profile, but not minimal profile.
Since tests have been refactored for optional config, moving this back to RTBC.
Comment #58
alexpottThis comment is no longer true. I think we should be a little more specific than "our"
Comment #59
rainbowarrayUpdated test comments as suggested.
Comment #60
attiks commentedLooking good, thanks all
Comment #61
attiks commentedOnce committed I'll updated the CR at https://www.drupal.org/node/2453919 or do we need to create a new one for the profile optional config?
Comment #62
alexpottI don't think that the config change needs a CR - it's an addition.
Comment #63
attiks commented#62 Anything else we need to do? Can you commit this, or is it better to ask @webchick?
Comment #64
alexpott@attiks I can not commit this - I've worked on it.
Comment #65
webchickSo I went to commit this, but it's failing on DrupalCI so I queued a re-test an hour and a bit ago and it's still re-queueing. Will check again tonight.
Comment #66
rainbowarrayI just double-checked the patch, and it still applies against HEAD, but I'm not sure what it means that it's failing on DrupalCI.
Comment #68
attiks commentedLast test is green, https://www.drupal.org/pift-ci-job/16985
Comment #70
rainbowarrayHere's a fresh reroll. Back to the bottom of the RTBC pile. :<
Comment #71
rainbowarrayMoving this back to RTBC since this was just a reroll.
Comment #72
webchickOh, crap, I am so sorry! I thought I committed this weeks ago.
Committed and pushed to 8.0.x. Thanks!