Problem/Motivation

Similar to image styles, the responsive image formatter should implement dependencies and dependency resolving.

Proposed resolution

  1. Implement calculateDependencies()
  2. Implement onDependencyRemoval() —­ We don't deal with the removal that meaning we are falling back to the default behaviour and that is disabling the formatter.
  3. Tests.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

When a responsive image style is deleted, the responsive image formatter using that style will be disabled,

Comments

claudiu.cristea created an issue. See original summary.

claudiu.cristea’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: +missing config dependencies
FileSize
7.5 KB

Here's a patch.

claudiu.cristea’s picture

Assigned: Unassigned » attiks

@attiks, maybe you'll find some time to look into this.

claudiu.cristea’s picture

Assigned: attiks » Unassigned
Issue tags: +Configuration system
FileSize
8.53 KB
3.33 KB

Ouch, the test.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Looks great!

  1. +++ b/core/modules/responsive_image/src/Tests/Update/ResponsiveImageUpdateTest.php
    @@ -0,0 +1,82 @@
    +    // avoid installation of configurations shipped in module.
    

    Nit: s/configurations/configuration/

  2. +++ b/core/modules/responsive_image/tests/src/Kernel/ResponsiveImageIntegrationTest.php
    @@ -0,0 +1,77 @@
    +    // Check that the view display wa snot deleted.
    

    Nit: s/wa snot/was not/

alexpott’s picture

Version: 8.0.x-dev » 8.1.x-dev

8.0.x has now had its final release.

alexpott’s picture

Shouldn't this be using the replacement image style if the image style gets deleted.

claudiu.cristea’s picture

@alexpott, hm. I thought the same. But now I'm not sure.

catch’s picture

Status: Reviewed & tested by the community » Needs review
Orizontal’s picture

testing the issu

Orizontal’s picture

Issue tags: +neworleans2016, +#nola2016
mdrummond’s picture

Let's test to see what is happening right now:

  • Apply this patch in a feature branch
  • On your local, for the article content type, set the image field to the responsive image formatter, and set the style to Narrow.
  • Go to the responsive image style config and delete the Narrow style
  • Go back to the article field display and check what the image formatter is now set to. Take a screenshot or two for bonus points.
Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Shouldn't this be using the replacement image style if the image style gets deleted.

No, because that would mean it's no longer a responsive image style. The fallback image style is specifically intended for the case of the browser not supporting responsive images. It is not okay to just make all images using a certain responsive image style use the same image style always (i.e. the fallback).

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 4: 2657110-4.patch, failed testing.

Wim Leers’s picture

Issue tags: +Needs reroll, +Novice, +php-novice

Patch no longer applies.

claudiu.cristea’s picture

Status: Needs work » Needs review
Issue tags: -neworleans2016, -#nola2016, -Needs reroll, -Novice, -php-novice
FileSize
8.52 KB
1.72 KB

I fixed also the typos/nits from #5.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 16: 2657110-16.patch, failed testing.

Wim Leers’s picture

Status: Needs work » Reviewed & tested by the community
fail: [Other] Line 139 of core/modules/migrate_drupal_ui/src/Tests/MigrateUpgradeTestBase.php:
"Congratulations, you upgraded Drupal!" found

Random migrate fails strike again!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/responsive_image/responsive_image.post_update.php
@@ -0,0 +1,28 @@
+    $entity_view_display->save();

we can do less here by only saving if the dependencies are different - see views_post_update_serializer_dependencies().... something like:

    $old_dependencies = $entity_view_display->getDependencies();
    $new_dependencies = $entity_view_display->calculateDependencies()->getDependencies();
    if ($old_dependencies !== $new_dependencies) {
      $entity_view_display->save();
    }
joginderpc’s picture

Issue tags: +re-roll patch

Re-roll patch @claudiu.cristea with resolve given solution in last comment #20.

claudiu.cristea’s picture

Status: Needs work » Needs review
Issue tags: -re-roll patch
FileSize
8.73 KB
1.04 KB

@alexpott, here is the change requested in #20 even it seems to me a little... over-engeneering for a one time task :)

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
  1. +++ b/core/modules/responsive_image/responsive_image.post_update.php
    @@ -0,0 +1,32 @@
    +  array_walk($displays, function(EntityViewDisplayInterface $entity_view_display) {
    +    $old_dependencies = $entity_view_display->getDependencies();
    +    $new_dependencies = $entity_view_display->calculateDependencies()->getDependencies();
    +    if ($old_dependencies !== $new_dependencies) {
    +      $entity_view_display->save();
    +    }
    
    index b91ef18..ff91e68 100644
    --- a/core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php
    

    This is indeed a nice pattern!

  2. +++ b/core/modules/responsive_image/src/Tests/Update/ResponsiveImageUpdateTest.php
    @@ -0,0 +1,82 @@
    +/**
    + * @file
    + * Contains \Drupal\responsive_image\Tests\Update\ResponsiveImageUpdateTest.
    + */
    
    +++ b/core/modules/responsive_image/tests/src/Kernel/ResponsiveImageIntegrationTest.php
    @@ -0,0 +1,77 @@
    +
    +/**
    + * @file
    + * Contains \Drupal\Tests\responsive_image\Kernel\ResponsiveImageIntegration.
    + */
    +
    

    Let's ensure to remove them right before the comment.

+++ b/core/modules/responsive_image/tests/src/Kernel/ResponsiveImageIntegrationTest.php
@@ -0,0 +1,77 @@
+    $this->assertFalse(array_key_exists('bar', $display->get('hidden')));
...
+    $this->assertTrue(array_key_exists('bar', $display->get('hidden')));

For future reference, you could leverage $this->assertArrayHasKey().

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 22: 2657110-22.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
8.52 KB
2.08 KB

Thank you @dawehner. I fixed based on suggestions from #23.

claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC as per #23.

dawehner’s picture

Back to RTBC. Thank you @claudiu.cristea

  • catch committed 1905428 on 8.2.x
    Issue #2657110 by claudiu.cristea: ResponsiveImageFormatter should...

  • catch committed 134e02b on 8.1.x
    Issue #2657110 by claudiu.cristea: ResponsiveImageFormatter should...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.2.x and cherry-picked to 8.1.x, thanks!

Status: Fixed » Closed (fixed)

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