Great time saving module - thanks, but getting 'Warning: array_intersect(): Argument #1 is not an array in stickynav_page_attachments() (line 18 of modules/contrib/stickynav/stickynav.module).'.

If no roles are excluded, $config->get('roles') returns NULL causing array_intersect to give a warning.

Comments

davewilly created an issue. See original summary.

davewilly’s picture

StatusFileSize
new676 bytes

Here is a quick patch.

davewilly’s picture

Status: Active » Needs review
skein’s picture

Status: Needs review » Postponed (maintainer needs more info)

Hello

Thank you for your contribution, but I have tried to reproduce the issue with no success (although I do remember seeing that notice before). Although your fix will solve the issue it seems the issue is with the schema config, which does not return the correct default value, which should be an empty array. Strangely enough it did not happen to me, but may be it's due to my PHP or Server version.

Could you please provide the information about your installation so we can get to the root of the notice instead of treating a symptom.

davewilly’s picture

StatusFileSize
new467.07 KB

Hey skein,

Drupal version : 8.1.7
PHP Version => 5.6.18-1+deb.sury.org~trusty+1
System => Linux drupalvm 4.2.0-41-generic #48~14.04.1-Ubuntu SMP Fri Jun 24 17:09:15 UTC 2016 x86_64

I've just retested after reinstalling module, and warning is there, screenshot attached.

davewilly’s picture

Further info - after enabling the module and accessing /admin/config/user-interface/stickynav, $config->get('roles') returns NULL.
However after enabling stickynav for the current admin theme and saving (admin/config/user-interface/stickynav/seven/edit), $config->get('roles') returns an empty array as expected. It seems it requires a config save in order to return the empty array, or we just get NULL.

skein’s picture

It seems that the stickynav module tries to check values even if the theme is not enabled. Technically the enabled key for the theme should prevent this. Possibly an issue in the initial condition.

davewilly’s picture

StatusFileSize
new1.47 KB

Ok this try this one. $config->isNew() returns bool (TRUE) if the configuration object does not exist in storage.
If stickynav has not been enabled for the current theme, which will always be the case after enabling the module, we can check $config->isNew() and do nothing if TRUE.
For any active theme where stickynav has been enabled, $config->isNew() will be FALSE, so we can fetch the configs and attach the library etc.

See https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Config%21...

davewilly’s picture

Status: Postponed (maintainer needs more info) » Needs review
skein’s picture

StatusFileSize
new681 bytes

Hello

I think I found the issue. It should check if the theme is enabled for stickynav first and then check the roles.

Please test the latest patch.

davewilly’s picture

Status: Needs review » Reviewed & tested by the community

Yes looks good.

  • skein committed 2ae5106 on 8.x-1.x
    Issue #2771713 by davewilly, skein: Warning: array_intersect(): Argument...
skein’s picture

Status: Reviewed & tested by the community » Closed (fixed)

Great committed.