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

  1. Wrap the foreach with a isset($layout_settings['wrappers']). See #2
  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 (?)

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

realityloop created an issue. See original summary.

realityloop’s picture

Status: Active » Needs review
FileSize
1.86 KB

Status: Needs review » Needs work

The last submitted patch, 2: invalid_argument_in_ds_module-2904575-2.patch, failed testing. View results

realityloop’s picture

Status: Needs work » Needs review
gambry’s picture

Issue summary: View changes

I'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 on ds_preprocess_ds_layout() or - even better - ds_theme_registry_alter()?

gambry’s picture

Issue summary: View changes

Worth noticing re-saving the affected view mode settings fixes the issue.

DigitalFrontiersMedia’s picture

Assigned: realityloop » Unassigned
FileSize
1.89 KB

Re-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:

Undefined index: wrappers in ds_preprocess_ds_layout() (line 504

Line 504 should be:
if (isset($layout_settings['wrappers']) && !empty($layout_settings['wrappers'])) {
instead of:
if (!is_null($layout_settings['wrappers'])) {

Revised patch attached.

gambry’s picture

@DigitalFrontiersMedia can you provide the interdiff ?

Thanks!

DigitalFrontiersMedia’s picture

FileSize
576 bytes

interdiff attached. However, it gave an odd message upon completion:

stephen@MotherPhoenix-3:~/Downloads [10:52:05]: interdiff invalid_argument_in_ds_module-2904575-2.patch invalid_argument_in_ds_module-2904575-7.patch > interdiff_7-9.txt
patch unexpectedly ends in middle of line
gambry’s picture

Status: Needs review » Needs work
+++ b/ds.module
@@ -501,6 +501,6 @@
+  if (isset($layout_settings['wrappers']) && !empty($layout_settings['wrappers'])) {

!empty() produces in this case the same effect as isset() 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'])).

DigitalFrontiersMedia’s picture

!empty() produces in this case the same effect as isset() and still doesn't ensure $layout_settings['wrappers'] is an array.

No, 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.

akalata’s picture

Thanks @DigitalFrontiersMedia, the preprocess warning is no longer bugging my users! (Not marking RTBC since I have not reviewed the code.)

gambry’s picture

Issue summary: View changes
Issue tags: +Novice

No, 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 ''.

From 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 sure is_array($layout_settings['wrappers']).

DigitalFrontiersMedia’s picture

I 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.

DigitalFrontiersMedia’s picture

@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.

gambry’s picture

Totally agree @DigitalFrontiersMedia !

Thanks

DigitalFrontiersMedia’s picture

Status: Needs work » Needs review
FileSize
1.9 KB

New patch with suggestion per gambry.

dieuwe’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #17 looks good and works well.

The last submitted patch, 7: invalid_argument_in_ds_module-2904575-7.patch, failed testing. View results

kclarkson’s picture

Patch in 17 also fixed my issues! Thanks!

swentel’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Does 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:

  $layout_settings += ['wrappers' => []];

is a more elegant line than moving the complete code into one if check.

DigitalFrontiersMedia’s picture

Also, maybe something like this:

$layout_settings += ['wrappers' => []];
is a more elegant line than moving the complete code into one if check.

Pffft. 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.

  • swentel committed d4479e6 on 8.x-3.x
    Issue #2904575 by DigitalFrontiersMedia, realityloop, gambry, akalata,...
swentel’s picture

Status: Postponed (maintainer needs more info) » Fixed

Can't say I really know how to consistently reproduce, unfortunately.

Mmm, no problem. I committed it like my suggestion, should be good. You're all still credited though, don't worry :)

gambry’s picture

Amazing solution though! Thanks @swentel

Status: Fixed » Closed (fixed)

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