Problem/Motivation

With current version of module we have an issue to see a stored configuration for WebformScore plugins (calculation rules in Webform element).

Steps to reproduce

Create one of provided Webform Score elements, set a scoring methodology in section Quiz answer and save element. Open element settings again and scoring methodology should be empty.

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

tomasbarej created an issue. See original summary.

tomasbarej’s picture

I was able to fix the behaviour, but I'm not so confident about the resolution because I don't really get how it might actually work before.

There is an initialisation of a plugin in QuizTrait.php with a method createWebformScorePlugin:

$plugin = $this->createWebformScorePlugin($this->configuration, $score_methodology_option);

First argument of the method should be an element where settings of the plugin should be loaded from element property #webform_score_plugin_configuration

  protected function createWebformScorePlugin(array $element, $plugin_id = NULL) {
    if (!$plugin_id) {
      $plugin_id = $this->getElementProperty($element, 'webform_score_plugin');
    }

    return $this->webformScoreManager->createInstance($plugin_id, $this->getElementProperty($element, 'webform_score_plugin_configuration'));
  }

It doesn't make sense to me to pass a $this->configuration array when there are not (or should not be) an element property.

It starts working when I pass an actual element props the method expects in form or an $element array like this:

        $element = [
          '#webform_score_plugin' => $score_methodology_option,
          '#webform_score_plugin_configuration' => $current_plugin_config,
        ];
        $plugin = $this->createWebformScorePlugin($element, $score_methodology_option);

What I'm not sure are the two more occurrences of plugin initialisation $plugin = $this->createWebformScorePlugin($this->configuration, $score_methodology_option); in methods validateConfigurationForm and submitConfigurationForm and wondering if it actually might validate or submit the values. In order to save config we need patch posted in issue https://www.drupal.org/project/webform_score/issues/2913371

tomasbarej’s picture

Status: Active » Needs review

nigelcunningham’s picture

Thanks for opening this issue. I've just pushed some work that I've done over the last few days - as you rightly pointed out, more was needed than just fixing the arguments. I'll credit your work on this when I get up to closing the issue. In the meantime, if you'd like to try the current dev branch, it will hopefully fix issues for you.