Problem/Motivation

Currently when configuring a responsive image format for a field, the list of responsive styles are sorted by machine name, not the style label. This can be confusing if the style labels are set so they display in a particular order, just as to map to a size scale.

Also, since the machine name is going to be removed from the styles table list with: #2988905: Remove machine name data from Responsive image styles table this will make the formatter list appear unsorted altogether.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

PCate created an issue. See original summary.

pcate’s picture

pcate’s picture

Patch attached. I went ahead and cleaned up some code sniffer errors I saw as well.

pcate’s picture

Status: Active » Needs review

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.

kristen pol’s picture

Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative

Thanks for the issue and patch.

The only thing in the patch that is for the issue summary is below. The rest of the changes are formatting and other unrelated fixes. Either the issue summary needs to be updated to reflect all the changes in the patch or the patch needs to be updated to only have the fix for the issue in the issue summary.

+++ b/core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php
@@ -136,8 +139,11 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
+    // Sort styles by their labels in 'natural order'.
+    asort($responsive_image_options, SORT_NATURAL);
ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new773 bytes

Patch #3 was not applying on Drupal 9.1.x, so I have rerolled the patch #3 on Drupal 9.1.x and I have removed unrelated fixes.

kristen pol’s picture

Issue tags: +Needs manual testing

Thanks for the update. The changes address #6.

Not sure this warrants tests but still needs manual testing.

kristen pol’s picture

Moving back to needs work as the sorting for the drop down doesn't match the sorting for Responsive Image Styles list.

Responsive image styles

Listing page

Dropdown without patch

Dropdown with patch

pcate’s picture

StatusFileSize
new776 bytes

Updated patch to use regular PHP array sort method. I think this should match the style list order.

pcate’s picture

StatusFileSize
new765 bytes

Forgot to test for case insensitive, the sorting of this patch should match the style list.

pcate’s picture

Status: Needs work » Needs review
kristen pol’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new40.1 KB
new65.74 KB

Thanks for the update. Marking RTBC based on:

1) Tested and now the order is the same as the Responsive Image Styles listing as expected. See screenshots.

2) Patch applies cleanly and tests pass.

3) Title & issue summary seem clear.

4) natcasesort is used elsewhere in core code.

5) Not sure tests need to be added for this as the only natcasesort checking I see is in one test (LanguageLocaleListTest).

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php
@@ -135,6 +135,9 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
+    // Sort styles by their labels in 'natural order'.
+    asort($responsive_image_options, SORT_NATURAL);

Config entities come with built-in sorting methods.

Above this we do ]

    $responsive_image_styles = $this->responsiveImageStyleStorage->loadMultiple();

after this we should do

uasort($responsive_image_styles, '\Drupal\responsive_image\Entity\ResponsiveImageStyle::sort');

and then if we add weights or some other custom sorting stuff to image styles this with get the same functionality without us having to remember about it.

Vidushi Mehta’s picture

Status: Needs work » Needs review
StatusFileSize
new1.33 KB

As mentioned by #14 added a patch for the same.

thalles’s picture

StatusFileSize
new52.49 KB

After apply #15, Drupal show me the pre set before and only so show the style that I created sorted correctly, so if I doed this correctly, I think this need more work.

See:

thalles’s picture

Status: Needs review » Needs work

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.

rajneeshb’s picture

Status: Needs work » Needs review
StatusFileSize
new1.3 KB

Re-rolled the #15 for 9.2.x and also fixed the issue mentioned on #16

thalles’s picture

After #19 works to me:

thalles’s picture

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

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php
@@ -135,6 +136,8 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
+    // Sort styles by their labels.
+    natcasesort($responsive_image_options);

This can be removed. The initial sort works as expected. (I think).

kishor_kolekar’s picture

Status: Needs work » Needs review
StatusFileSize
new1017 bytes
new629 bytes

Worked on comment # 22

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.

quietone’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new18.01 KB

I tested this on Drupal 9.3.x and when the patch is applied the sorting at /admin/config/media/responsive-image-style and for the field formatter at admin/structure/types/manage/article/display are the same.

For all the reasons in #14, back to RTBC

  • larowlan committed 7cff929 on 9.2.x
    Issue #3107130 by PCate, kishor_kolekar, ravi.shankar, Vidushi Mehta,...
  • larowlan committed baa711c on 9.3.x
    Issue #3107130 by PCate, kishor_kolekar, ravi.shankar, Vidushi Mehta,...
larowlan’s picture

Version: 9.3.x-dev » 9.2.x-dev
Status: Reviewed & tested by the community » Fixed

Discussed this with @catch w.r.t. whether we'd require a test - as per our typical policy on tests.

He agreed we don't in this specific instance, because 'it's barely a bug' 😅

Committed baa711c and pushed to 9.3.x. Thanks!

Backported to 9.2

kristen pol’s picture

Thanks for committing the "barely-bug". :) Should it be marked "minor" based on this?

Status: Fixed » Closed (fixed)

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