please look at these screenshots.
When I use entity reference in a views and autocomplete widget, It worked well.
but when I edit node, it chenged referenced field value as a screenshot 2
Other widgets worked perfect like list or select box (didn't change its value) only has a problem with autocomplete widget.
It automatically changes its value to original(referenced) title I think , but I'm using profile2 I can't change its title.
How can I use autocomplete widget without this problem?
or can I change profile2's title what I want?

#14 entityreference-1896210-14.patch3.93 KBAnybody
PASSED: [[SimpleTest]]: [MySQL] 124 pass(es).
[ View ]
#5 entityreference-1896210-5.patch3.94 KBmarcoscano
PASSED: [[SimpleTest]]: [MySQL] 121 pass(es).
[ View ]
#2 entityreference-1896210-2.patch3.84 KBkleinmp
PASSED: [[SimpleTest]]: [MySQL] 119 pass(es).
[ View ]
#1 entityreference-1896210-1.patch3.79 KBJody Lynn
PASSED: [[SimpleTest]]: [MySQL] 119 pass(es).
[ View ]
Screenshot_2.png3.23 KBnicolo2
Screenshot_1.png4.77 KBnicolo2


Jody Lynn’s picture

Status:Active» Needs review
new3.79 KB
PASSED: [[SimpleTest]]: [MySQL] 119 pass(es).
[ View ]

The default value of the autocomplete fields is being set to just the label of the entity (ignoring the views settings).

This patch adds functionality to the views plugin to get the output from the view not just the entity label.

kleinmp’s picture

new3.84 KB
PASSED: [[SimpleTest]]: [MySQL] 119 pass(es).
[ View ]

I tested this out and it solves the problem of this issue.

I made a couple of minor tweaks to check if the entity_id is empty before initializing the view and using the php end of line character.

rvilar’s picture

Patch in #2 works for me.

Balbo’s picture

News? Should this be committed?

marcoscano’s picture

Issue summary:View changes
Status:Needs review» Reviewed & tested by the community
new3.94 KB
PASSED: [[SimpleTest]]: [MySQL] 121 pass(es).
[ View ]

Same problem here

Patch in #2 doesn't apply cleanly anymore. Re-created a new one with the same code, patch attached.

Marking as RTBC once this solves the problem for me also

tame4tex’s picture

Patch #5 works for me

MustangGB’s picture

Title:Problem with autocomplete widget and Views » When filtering autocomplete by a view #default_value always be the entity title instead of the custom view result (e.g. a field on the entity)

RTBC from me as well.

Chasen’s picture

Confirming Patch #5 works for me as well.

Incidentally, is there an option to further remove the [user:uid] which shows up in parentheses in the autocomplete field on the edit page after searching and selecting the referenced field?

For example, if I have a profile2 called "Main Profile" and reference a street address field for a user (who has the user ID 23) this patch correctly changes the display of the reference entity from "Main Profile (23)" on the edit page, to "123 Fake Street (23)" - however, I think hiding the user ID would be handy as well as possible a further option (or possibly as the default)?

Just to confirm for anyone else searching for this, the patch edits the display on the /node/[node:nid]/edit page, not the view page (/name-of-content). The view display can be handled by an entity reference view and modifying the "Manage Display" page of the content type (/admin/structure/types/manage/[name-of-content-type]/display

phponwebsites’s picture

Ya its working fine.
Similarly i want to set default autocomplete value. The value shouln't displayed with nid. How to set default autocomplete value without nid?

Anybody’s picture

Important issue. I can confirm that this problem still exists and the patch fixes it.
Is there an active maintainer willing to pull this into the next release to have a consistent behaviour?

Anybody’s picture

Priority:Normal» Major

Setting the priority up because the UI is inconsistent currently and it's not possible to fix this without patching / coding.

Anybody’s picture

As it seems this patch eventually breaks entity label output from an entity reference field in a view. I'll check that and write how to reproduce. Leaving state until it's clear that the patch is the reason.

Anybody’s picture

Status:Reviewed & tested by the community» Needs work

My guess in #12 was right. There is a logical bug in the patch which leads to wrong label display.

This part is wrong:

 * Implements hook_field_formatter_view().
function entityreference_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $result = array();
  $settings = $display['settings'];

  // Rebuild the items list to contain only those with access.
  foreach ($items as $key => $item) {
    if (empty($item['access'])) {

  switch ($display['type']) {
    case 'entityreference_label':
      $handler = entityreference_get_selection_handler($field, $instance, $entity_type, $entity);

      foreach ($items as $delta => $item) {
        $label = $handler->getLabel($item['entity'], $item['target_id']);

In this function it doesn't seem right to me to use the views output of the label.
The given function handles the output of the entityreference field in a view. What we'd like to output there is NOT the result of the entityreference_view but the label of the referenced entity!

So this line should still return the old value which is simply possible by usig NULL as second argument:

$label = $handler->getLabel($item['entity'], NULL);

I've tested this and the behaviour is correct afterwards. I'll upload a corrected patch.
This is still an important bugfix from my point of view to correct the inconsistent, wrong behaviour.

Anybody’s picture

Status:Needs work» Needs review
new3.93 KB
PASSED: [[SimpleTest]]: [MySQL] 124 pass(es).
[ View ]

Patch with fixed field_formatter_view attached. Please review for RTBC! :)
That should hopefully be final.

thomas.frobieter’s picture

+1 for RTBC!

drenton’s picture

+1 for RTBC!

Anybody’s picture

Status:Needs review» Reviewed & tested by the community

#14 ready to be commited as soon as possible.
Is there an active module maintainer?