I have an entityreference field on users and I can't find a way to select more than one value. I want to make like a multiple select, but with the entityreference.

I use the EntityReference module, here is my form item :

$form['maj_planning']['suivi_par'] = array(
  '#type' => 'entityreference',
  '#title' => t('Suivi par'),
  '#required' => FALSE,
  '#default_value' => $entity->suivi_par,
  '#era_entity_type' => 'user',
  '#era_bundles' => array(),
  '#era_cardinality' => 1,
  '#era_query_settings' => array(
    'limit' => 15, // Default is 50.
    'property_conditions' => array(),
    'field_conditions' => array(),

How can I achieve this ?


Try this in your .theme file:

function MyTheme_user_form_user_form_alter(&$form, FormStateInterface $form_state, $form_id) {
   $form['maj_planning']['suivi_par']['#multiple'] = TRUE;
  • In what content type can I choose unlimited ? My entityreference is on users, and my content types doesn't make sense about a search on users (I have blog page, page, slideshow, webform) – Jess Nov 30 '18 at 11:35
  • check my update please. – MiharbKH Dec 2 '18 at 15:04

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.