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.

  • The ‘Responsive image style’ changes to ‘narrow’ is highlighted in red and the error ‘An illegal choice has been detected. Please contact the site administrator.‘ is generated.
  • 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’
    Views screenshot
    Everything working OK.
    Now edit the View ‘Cottage Progress’
    Click on Fields → Image change the Formatter to ‘Responsive Image’

    Views error Screenshot

    • 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

    Log Outptu screenshot
    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.
    screenshot showing issue resolved
    and this one
    screenshot showing issue resolved

    Remaining Tasks

    ============================================================================

    Comments

    themetman created an issue. See original summary.

    cilefen’s picture

    Component: views.module » views_ui.module

    I think this is the UI module. Daniel will correct me if wrong!

    Version: 8.2.x-dev » 8.3.x-dev

    Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

    Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

    asghar’s picture

    I confirm, face the same issue. Thanks

    asghar’s picture

    Assigned: Unassigned » asghar
    asghar’s picture

    Hi

    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

    asghar’s picture

    Status: Active » Needs review
    Pavan B S’s picture

    Rerolled the patch, please review.

    themetman’s picture

    Sorry 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

    lendude’s picture

    Component: views_ui.module » responsive_image.module
    Status: Needs review » Needs work
    Issue tags: +VDC

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

    Version: 8.3.x-dev » 8.4.x-dev

    Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

    Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

    themetman’s picture

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

    themetman’s picture

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

    themetman’s picture

    Version: 8.4.x-dev » 8.5.x-dev
    Issue summary: View changes

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

    themetman’s picture

    Issue summary: View changes
    themetman’s picture

    Issue summary: View changes
    StatusFileSize
    new35.41 KB
    new35.61 KB
    themetman’s picture

    Assigned: asghar » Unassigned
    Issue tags: +Needs tests

    Thanks @asghar for your input. In discussion with @YesCT we have unassigned you so that this can be reviewed by the Views Maintainer @lendude.

    themetman’s picture

    Issue summary: View changes
    themetman’s picture

    Issue summary: View changes
    themetman’s picture

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

    lendude’s picture

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

    themetman’s picture

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

    lendude’s picture

    Status: Needs work » Needs review
    Issue tags: -Needs tests
    StatusFileSize
    new2.42 KB
    new3.3 KB

    @themetman great opportunity to learn a new skill then :)

    I'd just go for something like this.

    The last submitted patch, 23: 2849187-22-TEST_ONLY.patch, failed testing. View results

    dbjpanda’s picture

    Status: Needs review » Reviewed & tested by the community
    StatusFileSize
    new357.46 KB

    This Patch #23 works perfect for me. works

    Status: Reviewed & tested by the community » Needs work

    The last submitted patch, 23: 2849187-22.patch, failed testing. View results

    Anonymous’s picture

    Status: Needs work » Reviewed & tested by the community

    Back to RTBC after random fail.

    wim leers’s picture

    1. +++ b/core/modules/responsive_image/tests/src/Functional/ViewsIntegrationTest.php
      @@ -0,0 +1,66 @@
      + * Tests the integration of responsive image Views.
      

      s/Views/with Views/

    2. +++ b/core/modules/responsive_image/tests/src/Functional/ViewsIntegrationTest.php
      @@ -0,0 +1,66 @@
      +  public static $testViews = ['entity_test_row'];
      

      Nit: missing inheritdoc.

    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.

    alexpott’s picture

    Status: Reviewed & tested by the community » Needs work
    +++ b/core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php
    @@ -138,7 +138,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
    -      '#default_value' => $this->getSetting('responsive_image_style'),
    +      '#default_value' => $this->getSetting('responsive_image_style') ?: NULL,
    

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

    alexpott’s picture

    Also #28 needs addressing.

    chiranjeeb2410’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new910 bytes

    @alexpott, addressed #28.

    Status: Needs review » Needs work

    The last submitted patch, 32: 2849187-32.patch, failed testing. View results

    yogeshmpawar’s picture

    Assigned: Unassigned » yogeshmpawar
    yogeshmpawar’s picture

    Assigned: yogeshmpawar » Unassigned
    Status: Needs work » Needs review
    StatusFileSize
    new3.29 KB
    new1.73 KB

    Updated patch with all changes addressed in #28 & #30.
    Also added an interdiff.

    chiranjeeb2410’s picture

    Status: Needs review » Reviewed & tested by the community

    Above patch addresses the issues mentioned in #28 and #30 as required. Applies cleanly and RTBC good to go!

    lendude’s picture

    Status: Reviewed & tested by the community » Needs review
    StatusFileSize
    new3.23 KB
    new4.76 KB
    +++ b/core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php
    @@ -138,7 +138,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
    -      '#default_value' => $this->getSetting('responsive_image_style'),
    +      '#default_value' => NULL,
    

    This 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::defaultSettings to 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)

    Status: Needs review » Needs work

    The last submitted patch, 37: 2849187-37.patch, failed testing. View results

    lendude’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new1.57 KB
    new4.51 KB

    Ok 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 ?: NULL seems 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.

    borisson_’s picture

    Status: Needs review » Needs work

    I have one really small nit to pick, sorry @Lendude

    +++ b/core/modules/responsive_image/tests/src/Functional/ViewsIntegrationTest.php
    @@ -0,0 +1,94 @@
    +  public static $modules = ['views', 'views_ui', 'responsive_image', 'field', 'image', 'file', 'entity_test', 'breakpoint', 'responsive_image_test_module'];
    

    This array is over 80 cols wide, and should be broken up onto multiple lines.

    lendude’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new2.16 KB
    new4.58 KB

    @borisson_ no worries, that will teach me to remember to 'Reformat code' before uploading a patch!

    borisson_’s picture

    Status: Needs review » Reviewed & tested by the community

    Wow, that was a super quick response! The rest of the patch already looked solid to me. Setting to RTBC.

    yogeshmpawar’s picture

    +1 for RTBC, looks good to me.

    Status: Reviewed & tested by the community » Needs work

    The last submitted patch, 41: 2849187-41.patch, failed testing. View results

    lendude’s picture

    Status: Needs work » Reviewed & tested by the community

    unrelated fails

    alexpott’s picture

    Status: Reviewed & tested by the community » Fixed

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

    • alexpott committed ed99d34 on 8.6.x
      Issue #2849187 by Lendude, Yogesh Pawar, asghar, chiranjeeb2410, Pavan B...

    • alexpott committed 3c256be on 8.5.x
      Issue #2849187 by Lendude, Yogesh Pawar, asghar, chiranjeeb2410, Pavan B...
    Anonymous’s picture

    You are really unstoppable heroes! A lot of respect to the participants!

    Anonymous’s picture

    #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! 🎉

    Status: Fixed » Closed (fixed)

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