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
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 3073338-11.patch | 2.54 KB | oknate |
| #11 | 3073338--interdiff-6-11.txt | 1019 bytes | oknate |
| #6 | 3073338-6--FAIL.patch | 1.33 KB | oknate |
| #6 | 3073338-6.patch | 2.1 KB | oknate |
Comments
Comment #2
oknateComment #3
oknateComment #4
oknateComment #5
oknateComment #6
oknateComment #8
oknateFailure is unrelated: #3074061: Update CKEditor plugin to be compatible with Drupal 8.8
Marking back as "Needs review".
Comment #9
oknateThis 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
Comment #10
oknateComment #11
oknateComment #13
oknateMarking back as needs review. The failure is unrelated, see #8.
Comment #14
oknateAdding a retest on #11 now that #3074061: Update CKEditor plugin to be compatible with Drupal 8.8 landed.