- Issue created by @milos.kroulik
Overriding #default_value
in variant has no effect (other element properties such as #description
work fine). The problem lies in that method WebformInterface::getElementsDefaultData()
(which is responsible for populating \Drupal\webform\Entity\WebformSubmission::$data
) is called only once before variants are applied, but the resulting property is fetched afterwards (at src/WebformSubmissionForm.php:817
) and subsequently used in \Drupal\webform\WebformSubmissionForm::populateElements()
where the overridden #default_value
is changed back to the default value.
It should be possible to override default value just as other element properties.
Decide what should be done to fix this and do it.
It looks like one possible way could be altering \Drupal\webform\Plugin\WebformVariant\OverrideWebformVariant::applyVariant
to set not only element properties, but also submission data, so they're correctly applied:
$webform_submission->setElementData($element_key, $element_properties['#default_value']);
$this->setWebformSubmission($webform_submission);
The problem is that $webform_submission
is not available in the WebformVariant
plugin and it's not available by using WebformEntityInjectionTrait
.
Another approach could possibly be creating another WebformVariant
plugin, used for directly overriding WebformSubmission::$data
.
Active
6.2
Code