-1

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 ?

1 Answer 1

0

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;
}
2
  • 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
    Commented Nov 30, 2018 at 11:35
  • check my update please.
    – MiharbKH
    Commented Dec 2, 2018 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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