Scenario (Webform with OptionsLimitWebformHandler):
1. All options (entity references/ Entity radios) are reached
2. WebformEntityTrait gets called after all options are removed (by OptionsLimitWebformHandler), it loads "all options" (in my case all published nodes type "appointment")
WebformEntityTrait
...
public static function setOptions(array &$element, array $settings = []) {
if (!empty($element['#options'])) {
return;
}
// Make sure #target_type is not empty.
if (empty($element['#target_type'])) {
$element['#options'] = [];
return;
}
...
Workaround:
We can unset($element['#target_type']) in alterOptionsElement (OptionsLimitWebformHandler), so the options are not loaded again in WebformEntityTrait
OptionsLimitWebformHandler
...
protected function alterOptionsElement(array &$element, array $limits, array $reached) {
// Set options element's options labels.
$options = &$element['#options'];
$this->alterOptionsElementLabels($options, $limits);
// Disable or remove reached options.
if ($reached) {
switch ($this->configuration['option_none_action']) {
case WebformOptionsLimitHandlerInterface::LIMIT_ACTION_DISABLE:
$this->disableOptionsElement($element, $reached);
break;
case WebformOptionsLimitHandlerInterface::LIMIT_ACTION_REMOVE:
$this->removeOptionsElement($element, $reached);
break;
}
}
// Display limit reached message.
if (count($limits) === count($reached)) {
unset($element['#target_type']); // Workaround !!!
$this->setElementLimitReachedMessage($element);
}
}
...
What would be a cleaner Solution?
Comments
Comment #2
jlenni commentedComment #3
jrockowitz commentedFirst, we need to create an example webform that can be used to replicate this issue.
Comment #4
jrockowitz commentedThe attached webform replicates this issue.
Comment #5
jrockowitz commentedComment #7
jlenni commentedThank you @jrockowitz !
3316013-4.patch works
Comment #8
jrockowitz commentedComment #9
jrockowitz commentedComment #11
jrockowitz commentedComment #12
jrockowitz commentedComment #13
jrockowitz commentedRTBC if tests pass
Comment #14
jrockowitz commentedComment #15
jrockowitz commentedComment #16
jrockowitz commented