I create a new content type with a Node Reference field. Not select any node bundle for limit reference node type.

I use the Inline Entity Form to add existing node. The auto-complete only appear something like Array (article).

After read through the code and compare with Entityreference module, I see the bug:

-- Around the line #1045:

foreach ($entity_labels as $entity_id => $label) {
$key = "$label ($entity_id)";
// Strip things like starting/trailing white spaces, line breaks and tags.
$key = preg_replace('/\s\s+/', ' ', str_replace("\n", '', trim(decode_entities(strip_tags($key)))));
// Names containing commas or quotes must be wrapped in quotes.
if (strpos($key, ',') !== FALSE || strpos($key, '"') !== FALSE) {
$key = '"' . str_replace('"', '""', $key) . '"';
}
$matches[$prefix . $key] = '

' . $label . '

';
}

This should be change to

-----

foreach ($entity_labels as $value){
foreach ($value as $entity_id => $label) {
// entityreference has already check_plain-ed the title.
$results[] = t('!label (!entity_id)', array('!label' => $label, '!entity_id' => $entity_id));
}
}

---

Sorry, I cannot create a diff for this. But after change this, the plugin works normal.

Comments

tky’s picture

Priority: Normal » Critical

I have the same issue here.

I used 7.x-1.0-rc1 initially, but the autocomplete field for adding existing node gave me somehting like "array(content type)". I have updated this module to 7.x-1.x-dev, still got this error as well.

Hope this can be fixed soon.

eiriksm’s picture

Status: Active » Needs review
StatusFileSize
new1.37 KB

Attached patch fixes the issue for me. Please review and consider commiting.

darkodev’s picture

Thanks very much. Patch works for us.

malberts’s picture

#2 Works for me. I tested it with Entity Reference fields (Node) that allow only 1 bundle type and another that allows multiple bundle types.

I don't think I'm allowed to mark this RTBC (just 2 reviews), but this is quite a big fail when using IEF.

rob c’s picture

#2 seems to work ok and really opens up this module to huge number of cases, including simplenews content selection. See How to create a newsletter containing existing content, using entity reference, rules and VBO for an example of this.

jpstrikesback’s picture

Thanks eiriksm! This works, I would RTBC it but it needs to pass tests first, so here it is as a git compatible patch.

jpstrikesback’s picture

Oh well, looks like tests aren't running for IEF...if someone can confirm the patch applies we can RTBC this.

eiriksm’s picture

Thanks for testing.

My patch is very much git compatible (did you not test it?). It is only different from yours in the way that i have used git format-patch to make it. That way the maintainer can use git am to apply the patch, to save himself 33 seconds of writing the commit message and stuff like that. :)

Since you basically have an identical patch (except the header) i would say you can feel free to mark as RTBC if it works for you.

jpstrikesback’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the clarification! RTBC, patch in #2 works perfectly!

bojanz’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

dwalker51’s picture

Patch in #2 worked great. Thanks!

ser_house’s picture

Status: Closed (fixed) » Active

After #10 I have warning: "Warning: Invalid argument supplied for foreach() in inline_entity_form_autocomplete() (line 67"

Field options:
"Allow users to add existing nodes.": TRUE
"Target type": node
"Target bundles": my_type (one)

$entity_labels looks like:

array(
  nid => title
)
    foreach ($entity_labels as $bundle => $labels) {
      // Here it is already $entity_id as $bundle, $label as $labels
      // Loop through each entity type, and autocomplete with its titles.
      foreach ($labels as $entity_id => $label) {
        // entityreference has already check_plain-ed the title.
        $results[] = t('!label (!entity_id)', array('!label' => $label, '!entity_id' => $entity_id));
      }
    }
vasike’s picture

Status: Active » Closed (fixed)

i can't reproduce #13 : i get no warning message.
so i think this is closed (fixed).

@ser_house : please try the latest version of the module.

rolfmeijer’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

I still have this issue, both in 7x-1.5 and the dev release of 2015-Feb-26. The error I get is this:

Warning: Invalid argument supplied for foreach() in inline_entity_form_autocomplete() (line 68 of …/sites/all/modules/contrib/inline_entity_form/inline_entity_form.module). Backtrace:

inline_entity_form_autocomplete('node', 'field_questions', 'survey', 'beva')
call_user_func_array('inline_entity_form_autocomplete', Array) menu.inc:517
menu_execute_active_handler() index.php:21

I hope I can find some time this or next week to dive into this (because I really like this module).

  • bojanz committed 4b84a37 on 8.x-1.x
    Issue #1843316 by eiriksm, jpstrikesback | dinhtrung: Fixed Error when...
bluegeek9’s picture

Status: Active » Closed (outdated)

We appreciate your contributions to Inline Entity Form. Drupal 7 in End-of-Life. We encourage you to upgrade to a supported version of Drupal.

//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support makes this project sustainable.
There are multiple ways to show appreciation for the work contributed to this project including:

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.