WebformEntityTrait::setOptions() creates an instance of the selection handler and sets the option to an entity reference type element. But it passes to the selection handler the settings incorrectly:
$selection_handler_options = [
'target_type' => $element['#target_type'],
'handler' => $element['#selection_handler'],
'handler_settings' => (isset($element['#selection_settings'])) ? $element['#selection_settings'] : [],
// Set '_webform_settings' used to limit and randomize options.
// @see webform_query_entity_reference_alter()
'_webform_settings' => $settings,
];
The "handler_settings" key doesn't really mean anything to the selection handler plugin and the values inside should go up to the top level of the array before being passed as configuration to the plugin. You can see this best when using the Views selection handler.
Comments
Comment #2
upchuk commentedHere is a patch that fixes the problem. Not sure where this would be tested though. Also, any way to run this against 8.x-6.x?
Comment #3
upchuk commentedIncluding also the fix on the form where the selection handler is again instantiated incorrectly.
Comment #4
mrinalini9 commentedRerolled patch #3 as it failed to apply, please review.
Comment #5
jrockowitz commentedBelow is some more information about this change
Comment #8
jrockowitz commented@Upchuk Thank you for finding and fixing this issue, especially because it is not something that would be detected in Drupal 9.x's deprecated code report.