Hello,

It would be nice if the selection handler from entityreference module can be attachable directly on a form element without creating a field. For instance, when adding a new view, the form element 'tagged with' is the perfect use case for this kind of feature. We can implement this feature using a new property such as '#entity_reference' on a textfield element and fulfill it with all required settings needed by entityreference module.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jkuma’s picture

This is an attempt to solve this feature request. This patch only tackles the textfield form element.
The items bellow describes the list of accepted parameters for the '#entityreference' property:

type: (optional, default: tags) [single|tags]
handler: (optional, default: base) the entity_reference handler.
target_type: the target entity type.
handler_settings: (optional) An array of handler settings such as target_bundles, sort and auto_create.
This is an exemple of implementation:

    $form['returns'] = array(
      '#type' => 'textfield',
      '#title' => t("order's returns"),
      '#size' => 80,
      '#maxlength' => 160,
      '#required' => FALSE,
      '#entityreference' => array(
        'target_type' => 'commerce_order',
        'handler' => 'base',
        'type' => 'single',
        'handler_settings' => array(
          'target_bundles' => array('commerce_return' => 'commerce_return'),
          'sort' => array()
        )
      )
    );
jkuma’s picture

Status: Active » Needs review
Jelle_S’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good, tested with crm_core_contact entities and works as expected.

Damien Tournoud’s picture

Category: task » feature
Status: Reviewed & tested by the community » Needs work
Jelle_S’s picture

@Damien: what work needs to be done to this patch?

Damien Tournoud’s picture

Status: Needs work » Postponed

I'm going to postpone this to 2.x.

In the need work:

- the access control of the autocomplete needs to be figured out. In the current version of the patch access control is wide open which is not desirable. At the minimum we should add a signed token in the URL
- we should decouple the selection handler from the field system, which we can do in 2.x only

slv_’s picture

Issue summary: View changes

Just wanted to reference #2029567: Move the functionality to Entity refenrence?, to say that I'll be happy to give a hand to make this happen in a D8 release of the module.

Best regards,

Salva.