Warning: array_key_exists() [function.array-key-exists]: The first argument should be either a string or an integer in _multiselect_build_widget_code() (line 181 ....\multiselect\multiselect.module).

Issue:
_multiselect_build_widget_code() does not check for nid
fix by adding:

 elseif (array_key_exists($value['nid'], $options)) { // With FAPI, it's not.
        $selected_options[$value['nid']] = $options[$value['nid']];

Comments

Svekke’s picture

Issue tags: -multiselect
Svekke’s picture

Assigned: Svekke » Unassigned
Frogtown’s picture

Confirming this -- I am using this as a node reference, built from a view, after going back into the edit node form, I get the error: Warning: array_key_exists(): The first argument should be either a string or an integer in _multiselect_build_widget_code() (line 181 of /home/httpd/pages/sites/all/modules/multiselect/multiselect.module). --- And the selected node reference values have been reset.

jvandooren’s picture

Can you give the patch a try and let us know if it worked for you?

Frogtown’s picture

I applied the patch, and it seems to have resolved the issue. The values are still selected when going into the node edit form, and I am no longer getting the whole "Array key exists" error. I've tested it in a few other ways, removing, re-adding values, resaving, etc. And it seems to be stable now. Would be great if anyone else can confirm this, and hopefully implement it into the next stable release.

clemens.tolboom’s picture

Status: Needs review » Needs work

According to #5 this works for nodes.

But what about references to other entities like users?

Set to needs work with a '?'

Svekke’s picture

Status: Needs work » Needs review

This is only a patch for nodes.
You can add a new patch for the user reference.

clemens.tolboom’s picture

Status: Needs review » Needs work

This is not a patch for nodes as after applying this patch it will ignore user references as

+++ multiselect.module Locally Modified (Based On LOCAL)
@@ -178,8 +178,8 @@
-      elseif (array_key_exists($value, $options)) { // With FAPI, it's not.
-        $selected_options[$value] = $options[$value];
\ No newline at end of file
+      elseif (array_key_exists($value['nid'], $options)) { // With FAPI, it's not.
+        $selected_options[$value['nid']] = $options[$value['nid']];
\ No newline at end of file

With FAPI means probably all others such as node and user references

comfreak’s picture

if you add

elseif (array_key_exists($value['uid'], $options)) { // With FAPI, it's not.
        $selected_options[$value['uid']] = $options[$value['uid']];
      }
      elseif (array_key_exists($value['nid'], $options)) { // With FAPI, it's not.
        $selected_options[$value['nid']] = $options[$value['nid']];
      }

it works for user references and node references as well.

internetdevels’s picture

I am using module Entity Referece. I've got the same error when I wanted to apply multiselect widget to my entity reference field . The solution is shown in first patch (multiselect_array_keys_exists_entity_reference).

More flexible solution which includes references of all entities (node, user, term references) is shown in second patch (multiselect_array_whichexists_entity_reference_2). Module version is 7.x-1.x-dev (2011-Mar-07).

Also Entity Reference module can be included to multiselect_field_widget_info. Because for using multiselect widget for entity reference field I added

function my_module_field_widget_info_alter(&$info) {
  if (module_exists('multiselect') && module_exists('entityreference')) {
    if (isset($info['multiselect'])) {
      $info['multiselect']['field types'][] = 'entityreference';
    }
  }
}

to custom module.

internetdevels’s picture

clemens.tolboom’s picture

@InternetDevels.Com I like your second solution.

What I wonder is whether the code

+++ b/multiselect/multiselect.module
@@ -170,6 +170,9 @@ function _multiselect_build_widget_code($options, $items, $element, $required =
       if (is_array($value) && array_key_exists('value', $value)) { // With CCK, it's an array.
         $selected_options[$value['value']] = $value['value'];

Isn't this obsolete as fields are in core?

emptyvoid’s picture

In order for the patches to appear in the entity management pages you have to register the "entityreference" field type both in:

multiselect_form_alter()

multiselect_field_widget_info()

emptyvoid’s picture

Status: Needs work » Needs review
StatusFileSize
new3.06 KB

Created a combined patch from #11 (http://drupal.org/node/1330256#comment-5450838) and the additional registration changes I mention in my previous comment.

Now the multiselect appears as a display option for fields in any entity.

jdleonard’s picture

Status: Needs review » Closed (cannot reproduce)

This appears to be fixed in the dev releases.