Currently entityreference do not support filtering (via views like references). I have to filter the returned result of option lists manually via hook_form_alter.
$new_options = array(1 => 'One', 2 => 'Two', 3 => 'Three'); // while old values without filtering results in 10 items
$form['field_entityreference'][$lang]['#options'] = $new_options;
This works fine at front end, but when I viewed via dsm($form);, the old values are still there.
A couple of tries to no avail:
if ($old_options = $form['field_entityreference'][$lang]['#options']) {
foreach ($old_options as $key => $old_option) {
unset($form['field_entityreference'][$lang]['#options'][$key]);
}
}
Or even unset($form['field_entityreference'][$lang]['#options']);
With array_diff_key also the old options are still held there.
The front end is just fine, only new options shown, but I need to exclude the unneeded from the source, because rules always evaluates to true when they are not totally removed which is unexpected.
How do you remove lingering old values, so that only the new values are held even in the backend?
The helpful function is not there yet: http://drupal.org/node/1085704. Any hint would be very much appreciated. Thanks