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?