I've create a custom field form widget for an entity reference field. When only one value is allowed it shows a (filtered) select list, but I want to allow user to assign multiple reference values to that field.
In my use case I want it to be shown as checkboxes when multiple values are allowed, but by default it shows my checkboxes in a 'add-another' fieldset.
How can this be accomplished?
Below some code, $type is now a field setting and is manually set.
// Construct element
$widget = $element;
$widget['#delta'] = $delta;
$type = $settings['option_limit_type'];
... extra logic ...
switch ($type) {
case 'select':
$widget += array(
'#type' => 'select',
'#prefix' => '<div id="' . $settings[$element['#field_name']]['ajax_wrapper'] . '">',
'#suffix' => '</div>',
'#options' => $options,
'#delta' => $delta,
'#element_validate' => array('_entityreference_hierachy_option_limit_validate'),
'#default_value' => $saved_target_id,
);
break;
case 'checkboxes':
$widget += array(
'#type' => 'checkboxes',
'#prefix' => '<div id="' . $settings[$element['#field_name']]['ajax_wrapper'] . '">',
'#suffix' => '</div>',
'#options' => $options,
'#delta' => $delta,
'#element_validate' => array('_entityreference_hierachy_option_limit_validate'),
'#default_value' => $saved_target_id,
);
break;
}
return $widget;