Skip to content

Instantly share code, notes, and snippets.

@heddn
Last active December 31, 2015 01:49
Show Gist options
  • Select an option

  • Save heddn/7916936 to your computer and use it in GitHub Desktop.

Select an option

Save heddn/7916936 to your computer and use it in GitHub Desktop.
Entity Reference autocomplete FAPI example.
$form['product_line_item_ref'] = array(
'#type' => 'textfield',
'#title' => t('Product Line Item Reference'),
'#description' => t('Enter the product line item.'),
// The last 4 URL parameters are important.
// 4: Use <NULL> as a placeholder in the URL when we don't have an entity.
// 3: Bundle, in our case the specific type of commerce line item but for node, that could page, etc.
// 2: Entity type, commerce line item in our example but node is also a valid type.
// 1: Field name that is the entityreference field.
'#autocomplete_path' => 'entityreference/autocompelete/single/commerce_product_line_item_ref/commerce_line_item/related_lines/NULL',
'#size' => 60,
'#maxlength' => 255,
'#required' => FALSE,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment