When using Bean with an autocomplete EntityReference field, the autocomplete text field uses the bean's optional title field to indicate the block rather than the label, thus making the editorial process more confusing than it should be.

Files: 
CommentFileSizeAuthor
#5 bean-label-in-entity-reference-field-1911262-7945347.patch1.08 KBSofiaSund
PASSED: [[SimpleTest]]: [MySQL] 98 pass(es).
[ View ]

Comments

DamienMcKenna’s picture

Approaching this from both sides - a corresponding request for the EntityReference module: #1911266: autocomplete field should use field selected for sorting

indytechcook’s picture

Status:Active» Closed (duplicate)

Duplicate of #1916938: Empty block name in entity reference field. I'm moving to that one since it has a better description.

stBorchert’s picture

Version:7.x-1.0-rc10» 7.x-1.x-dev
Status:Closed (duplicate)» Active

Sorry to reopen but this isn't really a duplicate of #1916938: Empty block name in entity reference field.
Having an empty title for a Bean makes it unfindable via Entity reference. On the other hand if you have multiple Beans with identical titles (but different labels) it is not possible to find the correct bean to insert.
Adding this simple sub-class of EntityReference_SelectionHandler_Generic fixes this UX problem (at least it has been fixed for us ;) ):

<?php
/**
 * A selection handler for Bean entities.
 */
class EntityReference_SelectionHandler_Generic_bean extends EntityReference_SelectionHandler_Generic {

 

/**
   * Implements EntityReferenceHandler::getLabel().
   */
 
public function getLabel($entity) {
    return
$entity->label;
  }

}

?>
indytechcook’s picture

Issue summary:View changes
Status:Active» Needs work

@stBorchert can you please format this as a patch so I can see the full impact.

SofiaSund’s picture

Status:Needs work» Needs review
StatusFileSize
new1.08 KB
PASSED: [[SimpleTest]]: [MySQL] 98 pass(es).
[ View ]

I couldn't find this fixed anywhere in the 7.x-1.x-dev branch. Here is a patch with stBorchert's code from #3. It works well for me (previously beans with empty title fields where displayed as empty lines in entity reference fields, now the admin label is displayed instead of the title).

joel_osc’s picture

I tried this patch and I am still unable to find via autocomplete untitled beans from my entityreference field. I ended up doing the following (hack) to make the autocomplete work, by adding this to the entityreference.handler.bean.inc file:

 
  public function entityFieldQueryAlter(SelectQueryInterface $query) {
    $conditions = &$query->conditions();
    foreach ($conditions as $key => &$condition) {
      if ($key !== '#conjunction' && is_string($condition['field']) && $condition['field'] === 'bean.title') {
        $condition['field'] = 'bean.label';
        break;
      }
    }
  }
joelpittet’s picture

This is related #1995770: Issue with Automatic Entity Label and may be an easier fix.

joel_osc’s picture

Yup, that seems to do the trick. Thanks!

indytechcook’s picture