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?

Issue fork webform-3316013

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jlenni created an issue. See original summary.

jlenni’s picture

Issue summary: View changes
jrockowitz’s picture

First, we need to create an example webform that can be used to replicate this issue.

jrockowitz’s picture

StatusFileSize
new5.76 KB

The attached webform replicates this issue.

jrockowitz’s picture

Status: Active » Needs review
StatusFileSize
new656 bytes

Status: Needs review » Needs work

The last submitted patch, 5: 3316013-4.patch, failed testing. View results

jlenni’s picture

Thank you @jrockowitz !

3316013-4.patch works

jrockowitz’s picture

Version: 6.1.3 » 6.2.x-dev
jrockowitz’s picture

Status: Needs work » Needs review

jrockowitz’s picture

Status: Needs review » Needs work
jrockowitz’s picture

Version: 6.2.x-dev » 6.3.x-dev
Status: Needs work » Needs review
jrockowitz’s picture

Status: Needs review » Reviewed & tested by the community

RTBC if tests pass

jrockowitz’s picture

Status: Reviewed & tested by the community » Needs work
jrockowitz’s picture

Status: Needs work » Reviewed & tested by the community
jrockowitz’s picture

Status: Reviewed & tested by the community » Needs work