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.

CommentFileSizeAuthor
#4 3151376-4.patch1.95 KBmrinalini9
#3 3151376-3.patch1.94 KBupchuk
#2 3151376-2.patch1.15 KBupchuk

Comments

Upchuk created an issue. See original summary.

upchuk’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new1.15 KB

Here 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?

upchuk’s picture

StatusFileSize
new1.94 KB

Including also the fix on the form where the selection handler is again instantiated incorrectly.

mrinalini9’s picture

StatusFileSize
new1.95 KB

Rerolled patch #3 as it failed to apply, please review.

  • mrinalini9 authored b660ddf on 8.x-5.x
    Issue #3151376 by Upchuk, mrinalini9: WebformEntityTrait::setOptions...

  • mrinalini9 authored b660ddf on 6.x
    Issue #3151376 by Upchuk, mrinalini9: WebformEntityTrait::setOptions...
jrockowitz’s picture

Status: Needs review » Fixed

@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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.