Problem/Motivation
I found the following notice in some cases:

Notice: Undefined variable: prefix in entityreference_autocomplete_callback_get_matches() (line 1045 of entityreference.module

Proposed resolution
Checking the code it seems that $prefix has a chance of not being defined in the following [ from row 1037 of current dev version, entityreference.module ]:

if ($type == 'tags') {
    // The user enters a comma-separated list of tags. We only autocomplete the last tag.
    $tags_typed = drupal_explode_tags($string);
    $tag_last = drupal_strtolower(array_pop($tags_typed));
    if (!empty($tag_last)) {
      $prefix = count($tags_typed) ? implode(', ', $tags_typed) . ', ' : '';
    }
  }
  else {
    // The user enters a single tag.
    $prefix = '';
    $tag_last = $string;
  }

I simply propose to declare

$prefix = ''

at the beginning of entityreference_autocomplete_callback_get_matches function just before or after

$matches = array();
CommentFileSizeAuthor
#1 2202501-1-undefined-notice-prefix.patch691 byteshanoii
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hanoii’s picture

Status: Active » Needs review
FileSize
691 bytes

Follow up patch of @spesso recommendation with a slight line remove as it's not needed with the change.

MustangGB’s picture

Status: Needs review » Reviewed & tested by the community
othermachines’s picture

  • spotzero committed 40771c1 on 7.x-1.x authored by hanoii
    Issue #2202501 by hanoii: Notice: Undefined variable: prefix in...
spotzero’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

Status: Fixed » Closed (fixed)

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