Problem/Motivation
I reported that when creating a responsive Image Field in a View of a content type with an image field, there is an error as shown below. nicoz suggested I report it as an Issue.
This is what I have done on a fresh install of Drupal 8.2.6 with PHP 7.0.13 , CentOS 6 kernel 2.6.32-642.6.2.el6.x86_6, on webfaction.com server.
I Added a Content Type with 2 fields ‘Cottage Progress’
- Body with default settings
- Image with reused field ‘Image’ and default values except for
- Required Field checked
- File Directory ‘sites/default/files/cottage_progress’
- and
- Default form display
- and
- display settings
- changed Body Label to ‘Above’
- Image Label to ‘Hidden’
Then I Added a View ‘Cottage Progress’

Everything working OK.
Now edit the View ‘Cottage Progress’
Click on Fields → Image change the Formatter to ‘Responsive Image’

- Leaving the ‘responsive Image Style’ as ‘Narrow’ I click on ‘Apply’ and all is well
The displayed view is now working with a responsive image as expected, and no more log errors
- here is the log output

Edit Views ‘Cottage Progress’ and change the ‘Responsive image style’ to ‘wide’.
- There is no error shown on the page or in the log, but the displayed view does not change the image size.
Proposed resolution
To fix this module so that this error does not occur, and selection of the Narrow or Wide style is allowed.
Since Applying the Patch
The problem is now resolved. see the attached images.

and this one

Remaining Tasks
============================================================================
| Comment | File | Size | Author |
|---|---|---|---|
| #41 | 2849187-41.patch | 4.58 KB | lendude |
| #41 | interdiff-2849187-39-41.txt | 2.16 KB | lendude |
| #39 | 2849187-39.patch | 4.51 KB | lendude |
Comments
Comment #2
cilefen commentedI think this is the UI module. Daniel will correct me if wrong!
Comment #4
asghar commentedI confirm, face the same issue. Thanks
Comment #5
asghar commentedComment #6
asghar commentedHi
We have different solutions to resolve this issue. You can see further details below
1- Make the field(responsive_image_style) as un-required
If admin user delete the all options for Responsive image style then empty select box will display. User can submit the form without selecting option.
2- Assign default value NULL
I think this is more sustainable because instead of An illegal message this shows the required field message which make more sense. I have attached the patch for this. Thanks
Comment #7
asghar commentedComment #8
Pavan B S commentedRerolled the patch, please review.
Comment #9
themetman commentedSorry to be a while checking this.
I have retested the View Image Field after updating to Drupal Core 8.3.1 and there is no error.
This would appear to be fixed.
Thank You
Comment #10
lendudeJust retested this and I can still reproduce this.
The fix changes the error to 'Responsive image style field is required.'
The current fix is in responsive image, so setting the component to that.
This still needs tests, so back to needs work.
Comment #12
themetman commentedI am at DrupalCon Vienna 2017 and decided to work on this issue further with robdebones.
We have a clean install of 8.4-x and tested the problem again which was still present.
Comment #13
themetman commentedWe applied the patch responsive-image-shows-an-error-in-views-2849187-8.patch. Now when choosing a Responsive Image Type for the Image in the View, a warning is issued that an Image Style must be selected. We selected both Narrow and Wide in turn and both worked as expected.
we would consider that this patch has fixed the issue.
Comment #14
themetman commentedChanged Version to 8.5.x because we have tested patch on 8.4.x and all is well. proceeding to test on 8.5.x
We considered if this is a Minor Bug, looked at https://www.drupal.org/core/issue-priority#minor and decided it is a Minor bug, because the functionality is still present despite the error warning.
Comment #15
themetman commentedComment #16
themetman commentedComment #17
themetman commentedThanks @asghar for your input. In discussion with @YesCT we have unassigned you so that this can be reviewed by the Views Maintainer @lendude.
Comment #18
themetman commentedComment #19
themetman commentedComment #20
themetman commented@robdebones and I have manually tested 8.5.x as we did with 8.4.x and find the same result. The patch appears to have done the job, and the Responsive Image Style for the Image in Views now works as expected.
We do not have time to continue this today. All that is needed now, as far as we can see, is the Automated Tests.
During the testing we have done today we noticed that the 'Save' Button is not showing when adding an image into the Content Type we created for these tests until the page has been Previewed.
We checked this out, and discovered the ' Preview before submitting' was set to 'Required', so changed this option to 'Optional' to show the Save Button as well as the Preview Button.
This is behaving as expected, so not an issue at all.
Auf Wiedersein Vienna DrupalCon!
Comment #21
lendude@themetman Thanks for the triage! I think this looks good, the 'required' message is much better then the 'illegal choice' error.
The patch looks fine, but like you said we really need a test for this.
Comment #22
themetman commented@lendude, how do you or we progress and design the Automated Tests required on this patch?
Quite honestly @robdebones & I have no idea how to design Automated Tests.
Comment #23
lendude@themetman great opportunity to learn a new skill then :)
I'd just go for something like this.
Comment #25
dbjpanda commentedThis Patch #23 works perfect for me.
Comment #27
Anonymous (not verified) commentedBack to RTBC after random fail.
Comment #28
wim leerss/Views/with Views/
Nit: missing inheritdoc.
Comment #30
alexpottWould a better fix be to change the default_setting to have a NULL instead of this check?
That would be more inline of how getSetting works. Also as we can't provide a default setting here how about just removing responsive_image_style from the default settings?
Comment #31
alexpottAlso #28 needs addressing.
Comment #32
chiranjeeb2410 commented@alexpott, addressed #28.
Comment #34
yogeshmpawarComment #35
yogeshmpawarUpdated patch with all changes addressed in #28 & #30.
Also added an interdiff.
Comment #36
chiranjeeb2410 commentedAbove patch addresses the issues mentioned in #28 and #30 as required. Applies cleanly and RTBC good to go!
Comment #37
lendudeThis would mean that the selected value is not selected when you look at this form after subitting. I think @alexpott meant setting the default value in
\Drupal\responsive_image\Plugin\Field\FieldFormatter\ResponsiveImageFormatter::defaultSettingsto NULL instead of an empty string.So here we go with that plus test coverage for the correct value getting set (which fails with #35)
Comment #39
lendudeOk so setting the default to NULL doesn't work because that doesn't match the config schema. Just removing the setting from defaults (thus making sure it's NULL) doesn't work either, then nothing get saved.
So the
?: NULLseems the best solution, so back to that.Also redid #28.2, $testViews is never set in any parent class (silly, I know) so @inheritdoc doesn't work there, but it was missing a docblock before, so changed that to a normal docblock.
No idea why the added test for saving the value fails in #37, passes fine locally, lets see what the bot makes of this.
Comment #40
borisson_I have one really small nit to pick, sorry @Lendude
This array is over 80 cols wide, and should be broken up onto multiple lines.
Comment #41
lendude@borisson_ no worries, that will teach me to remember to 'Reformat code' before uploading a patch!
Comment #42
borisson_Wow, that was a super quick response! The rest of the patch already looked solid to me. Setting to RTBC.
Comment #43
yogeshmpawar+1 for RTBC, looks good to me.
Comment #45
lendudeunrelated fails
Comment #46
alexpottCommitted and pushed ed99d34b12 to 8.6.x and 3c256be771 to 8.5.x. Thanks!
Thanks @Lendude for investigating my suggestion and finding out it does not work.
Crediting @borisson_ and @Wim Leers for reviews.
Comment #49
Anonymous (not verified) commentedYou are really unstoppable heroes! A lot of respect to the participants!
Comment #50
Anonymous (not verified) commented#49: Lol, I wanted to post this in the #1927648: Allow creation of file entities from binary data via REST requests, but I made a mistake with the tabs (very many pleasant news from @alexpott in such a short time, as always).
I'm glad that this post is also suitable here! 🎉