Hi guys,
Just noticed a stack of warnings coming up at admin/structure/file-types/manage/image/file-display/*
Starting with this one:

Warning: array_keys() expects parameter 1 to be array, null given in bg_image_formatter_field_formatter_settings_form() (line 40 of /home/website/htdocs/drupal/sites/all/modules/bg_image_formatter/bg_image_formatter.module).

Then continuing on to a bunch of invalid argument supplied complaints like this one:

Warning: Invalid argument supplied for foreach() in bg_image_formatter_field_formatter_settings_form() (line 44 of /home/website/htdocs/drupal/sites/all/modules/bg_image_formatter/bg_image_formatter.module).

Any idea what needs to change here? I did a queue search for "bg_image_formatter_field_formatter_settings" but did not hit anything...

We are using the WYSIWYG module, and I have just installed the entity_view_modes module. No other changes to the site. Not sure if this warning has been there all along or if it has just appeared.

Thanks for any advice or guidance.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Pol’s picture

Status: Active » Closed (cannot reproduce)

Hello,

Unable to reproduce the bug here, sorry.

BrightBold’s picture

Status: Closed (cannot reproduce) » Active

Hmm. I'm now getting this error too, although I was not earlier. I also use Entity View Modes, but I am using CKEditor module instead of WYSIWYG. I'll try to look back through the git logs and see how recently Entity View Modes was installed as that may be the common thread.

BrightBold’s picture

Unfortunately I can't figure out when I installed Entity View Modes. I disabled it but the error persisted. Then I also disabled Media WYSIWYG View Modes so that only core view modes would remain, but that didn't clear up the error. There's a non-core view mode showing, "preview," but I don't know what module creates that. (Media?)

The line in the code that's throwing the error is foreach ($entity_types as $entity_type) { where $entity_types = array_keys($field['bundles']);. So it's clearly an entity-related problem of some sort. But I don't know where it's getting array_keys($field['bundles']) from, so I'm at my limit on troubleshooting here.

Xtal’s picture

I have made a patch for this (the stable release) which adds empty() clauses around the lines in question.
This is my first patch submitted to the community so I would appreciate some feedback on it.

Thanks!

Pol’s picture

Hi,

Thanks for your patch!

Here's a quick review

  1. +++ b/sites/all/modules/contrib/bg_image_formatter/bg_image_formatter.module
    @@ -37,13 +37,18 @@ function bg_image_formatter_field_formatter_settings_form($field, $instance, $vi
    +  if(empty($entity_types)){
    

    Could you please use !empty instead of this ?

  2. +++ b/sites/all/modules/contrib/bg_image_formatter/bg_image_formatter.module
    @@ -37,13 +37,18 @@ function bg_image_formatter_field_formatter_settings_form($field, $instance, $vi
    +    if(empty($entity_types)){
    

    Same here

Xtal’s picture

Xtal’s picture

Status: Active » Needs review
Pol’s picture

Status: Needs review » Needs work

Unable to apply the patch.

I suggest you to read: https://www.drupal.org/node/707484

Xtal’s picture

Cheers pol, will do!

Xtal’s picture

Pol’s picture

Hello,

The patch is applying successfully, however, here's my review:

  1. +++ b/bg_image_formatter.module
    @@ -80,13 +80,21 @@ function bg_image_formatter_field_formatter_settings_form($field, $instance, $vi
    +      if(!empty($entity_types)){
    

    $entity_types is not declared before. Is this condition really needed ?

  2. +++ b/bg_image_formatter.module
    @@ -80,13 +80,21 @@ function bg_image_formatter_field_formatter_settings_form($field, $instance, $vi
    +                    if ($entity_type == $entity_map ) {
    

    The same condition is used 4 lines before. Is this really necessary ?

Xtal’s picture

Apologies, that's a mistake. Here is a new patch.

Thanks

Pol’s picture

These are exactly the same patch as before, you just changed the spaces.

Please see my remarks in my previous comment.

Xtal’s picture

Patch 8 and 11 do differ, 8 had an unwanted if statement in it.
Regarding your comment #11,
The way I see it there are two points where the code depends on $entity_types having a value.
There were 2 errors showing for me which where null value warning.

Attached is the patch with just the first check for the $entity_type not being empty.

Thanks

 if(!empty($entity_types)) {
      $entity_types = array_keys($field['bundles']);
    }
    $tokens_list = array();
    foreach ($tokens_mapping as $token_map => $entity_map) {
      foreach ($entity_types as $entity_type) {
        if ($entity_type == $entity_map) {
          $tokens_list[] = $token_map;
        }
      }
    }
Pol’s picture

You're right about the patches, sorry.

Now I'm reviewing your patch but there's still something that I don't understand.

When I look at the code of the module at line 83, you see:

    $entity_types = array_keys($field['bundles']);

It's the first time that the variable $entity_types gets declared.

What's the use of your patch then ?

Your patch try to replace that line with:

if (!empty($entity_types)) {
  $entity_types = array_keys($field['bundles']);
  }

Is your patch really necessary ? $entity_types will always be empty before line 83 and will never be prepopulated because it's not used before anywhere else.

Could you explain me please ?

Xtal’s picture

It's a bug that appears with display suite when setting the files display with a view mode.
It's only when Display suite view modes are used with file display settings.

Pol’s picture

I'm sorry but I'm unable to reproduce the bug here.

Could you tell me the minimum step to do to reproduce it please so I can fix the bug properly ?

Thanks.

Xtal’s picture

Ok maybe it's too specific.
I saw this bug by the following modules being enabled...
- display suite
- entity view modes
and then trying to configure an image display at admin/structure/file-types/manage/image/file-display

Im happy to leave this issue closed but should i create a sandbox project to recreate the error ?

Thanks

Pol’s picture

No need of a sandbox, don't worry.

I will first try to recreate the bug here and report here my findings.

  • Pol committed 08f4632 on 7.x-1.x
    Fix issue #2354563: Null value in settings line 40
    
Pol’s picture

Status: Needs work » Fixed

I just pushed a fix, could you tell me if it's ok ?

Thanks.

Xtal’s picture

Hi Pol thanks, this has solved the error.
I appreciate your help with my first patch!

Pol’s picture

You're welcome.

Xtal’s picture

Please can you credit me for this patch.

Thanks

Pol’s picture

Sorry, it will be for the next time.

Keep in mind that I credit people when:

  1. The patch apply
  2. The patch make sense
  3. The changes on the repository match the patch
Xtal’s picture

No attribute

Pol’s picture

Sorry ?

Xtal’s picture

Forget it, no worries pol

Status: Fixed » Closed (fixed)

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

Xtal’s picture