Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
This is due $layout_settings['wrappers'] (AKA $variables['settings']['wrappers']) being NULL
in loop:
foreach ($layout_settings['wrappers'] as $region_name => $wrapper) {
[...]
}
Proposed resolution
- Wrap the foreach with a
isset($layout_settings['wrappers'])
. See #2 - Fill in settings with default values, as 'wrappers' can be only the bug being triggered while other settings silently fail somewhere else.
Remaining tasks
Agree on best solution and fix it.- Make sure
is_array($layout_settings['wrappers'])
, see #10
User interface changes
No
API changes
No (?)
Comments
Comment #2
realityloopComment #4
realityloopComment #5
gambryI'm assuming this is happening when you use "class: '\Drupal\ds\Plugin\DsLayout'" in your layout definition, so why don't we merge the DsLayout default configuration to
$variables['settings']
before is processed onds_preprocess_ds_layout()
or - even better -ds_theme_registry_alter()
?Comment #6
gambryWorth noticing re-saving the affected view mode settings fixes the issue.
Comment #7
DigitalFrontiersMediaRe-saving the view mode settings didn't fix this for me.
The patch in #2 gets rid of the Warning but produces a Notice in its place:
Line 504 should be:
if (isset($layout_settings['wrappers']) && !empty($layout_settings['wrappers'])) {
instead of:
if (!is_null($layout_settings['wrappers'])) {
Revised patch attached.
Comment #8
gambry@DigitalFrontiersMedia can you provide the interdiff ?
Thanks!
Comment #9
DigitalFrontiersMediainterdiff attached. However, it gave an odd message upon completion:
Comment #10
gambry!empty()
produces in this case the same effect asisset()
and still doesn't ensure $layout_settings['wrappers'] is an array.I think what you want is
isset($layout_settings['wrappers']) && is_array($layout_settings['wrappers'])
(or!empty($layout_settings['wrappers']) && is_array($layout_settings['wrappers'])
).Comment #11
DigitalFrontiersMediaNo, use of !empty in addition to isset is for different reasons. isset makes sure the array key 'wrappers' is actually valid and its value is not NULL, !empty makes sure its value isn't just ''.
Additional assurance that it is an array (and not null and not an empty array) is a good safety check.
Comment #12
akalata CreditAttribution: akalata commentedThanks @DigitalFrontiersMedia, the preprocess warning is no longer bugging my users! (Not marking RTBC since I have not reviewed the code.)
Comment #13
gambryFrom empty() PHP documentation: " No warning is generated if the variable does not exist. That means empty() is essentially the concise equivalent to !isset($var) || $var == false. ".
So "!empty() produces in this case the same effect as isset() and still doesn't ensure $layout_settings['wrappers'] is an array." is still valid. One between
isset()
and!empty()
can be removed, and the only remaining task is still to make sureis_array($layout_settings['wrappers'])
.Comment #14
DigitalFrontiersMediaI see what you're saying now.
That being the case, and since checking if it's an array before passing into the loop is recommended, we should probably use
!empty($layout_settings['wrappers']) && is_array($layout_settings['wrappers'])
since there's no point bothering to enter that loop if it's set and an array but that array is empty.
Comment #15
DigitalFrontiersMedia@akalata Glad to hear! I know how hard it can be when you've got lots of users coming to you with complaints.
Per discussion with gambry, it looks like while the patch stops the warnings and such, it may not yet be the ideal, final solution. Hopefully, we'll get that done and hopefully have it committed soon.
Comment #16
gambryTotally agree @DigitalFrontiersMedia !
Thanks
Comment #17
DigitalFrontiersMediaNew patch with suggestion per gambry.
Comment #18
dieuwePatch in #17 looks good and works well.
Comment #20
kclarkson CreditAttribution: kclarkson commentedPatch in 17 also fixed my issues! Thanks!
Comment #21
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commentedDoes anyone have steps to reproduce to trigger this notice ? I'm trying to think if the actual problem isn't somewhere else.
Also, maybe something like this:
is a more elegant line than moving the complete code into one if check.
Comment #22
DigitalFrontiersMediaPffft. Yeah, sure that works too...if you want to get all fancy and elegant. :-D
If you're looking for initial cause, I think Gambry is probably on the right track in #5.
Can't say I really know how to consistently reproduce, unfortunately.
Comment #24
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commentedMmm, no problem. I committed it like my suggestion, should be good. You're all still credited though, don't worry :)
Comment #25
gambryAmazing solution though! Thanks @swentel