Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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();
Comment | File | Size | Author |
---|---|---|---|
#1 | 2202501-1-undefined-notice-prefix.patch | 691 bytes | hanoii |
Comments
Comment #1
hanoiiFollow up patch of @spesso recommendation with a slight line remove as it's not needed with the change.
Comment #2
MustangGB CreditAttribution: MustangGB commentedComment #3
MustangGB CreditAttribution: MustangGB commentedComment #4
MustangGB CreditAttribution: MustangGB commentedWhoops!
Comment #5
othermachines CreditAttribution: othermachines commentedMarked another issue as duplicate: #2203705: Nodes that start with " are not getting listed
Comment #7
spotzero CreditAttribution: spotzero at Coldfront Labs Inc. commentedCommitted.