Problem/Motivation

This code needs updating in order to actually iterate through all the rows:

      if (!empty($button_groups[0])) {
        foreach ($button_groups[0] as $button_group) {
          foreach ($button_group['items'] as $item) {
            $buttons[] = $item;
          }
        }
      }

The $button_groups array is an array of rows. It's only checking the first row.

This was found by phenaproxima at #2994699-52: Create a CKEditor plugin to select and embed a media item from the Media Library.12.

Why are we limiting this to the first button group? Shouldn't we loop through all of them?

I checked and this is indeed a bug.

Proposed resolution

The code should be replaced like this:

     $buttons = [];
-    $button_groups = json_decode($button_groups, TRUE);
-    if (!empty($button_groups[0])) {
-      foreach ($button_groups[0] as $button_group) {
-        foreach ($button_group['items'] as $item) {
-          $buttons[] = $item;
-        }
+    $button_groups = Json::decode($button_groups, TRUE);
+
+    foreach ($button_groups as $button_row) {
+      foreach ($button_row as $button_group) {
+        $buttons = array_merge($buttons, array_values($button_group['items']));
       }
     }

And for test coverage, change the text format button config so it has two row.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

oknate created an issue. See original summary.

oknate’s picture

Title: Filter Format validation bug, now iterating through all rows. » Filter Format validation bug, not iterating through all rows.
oknate’s picture

Issue summary: View changes
oknate’s picture

Issue summary: View changes
oknate’s picture

Issue summary: View changes
oknate’s picture

Status: Active » Needs review
StatusFileSize
new2.1 KB
new1.33 KB

Status: Needs review » Needs work

The last submitted patch, 6: 3073338-6--FAIL.patch, failed testing. View results

oknate’s picture

Status: Needs work » Needs review

Failure is unrelated: #3074061: Update CKEditor plugin to be compatible with Drupal 8.8
Marking back as "Needs review".

oknate’s picture

Status: Needs review » Needs work

This should be using Drupal\Component\Serialization\Json::decode(), per feedback from @phenaproxima.

See #2994699-52: Create a CKEditor plugin to select and embed a media item from the Media Library.11

oknate’s picture

Issue summary: View changes
oknate’s picture

Status: Needs work » Needs review
StatusFileSize
new1019 bytes
new2.54 KB

Status: Needs review » Needs work

The last submitted patch, 11: 3073338-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

oknate’s picture

Status: Needs work » Needs review

Marking back as needs review. The failure is unrelated, see #8.

oknate’s picture