protected static function WebformComputedBase::getWebformSubmission in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Element/WebformComputedBase.php \Drupal\webform\Element\WebformComputedBase::getWebformSubmission()
Get the Webform submission for element.
Parameters
array $element: The element.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
array $complete_form: The complete form structure.
Return value
\Drupal\webform\WebformSubmissionInterface|null A webform submission.
3 calls to WebformComputedBase::getWebformSubmission()
- WebformComputedBase::ajaxWebformComputedCallback in src/
Element/ WebformComputedBase.php - Webform computed element Ajax callback.
- WebformComputedBase::processWebformComputed in src/
Element/ WebformComputedBase.php - Processes a Webform computed token element.
- WebformComputedBase::validateWebformComputed in src/
Element/ WebformComputedBase.php - Validates an computed element.
File
- src/
Element/ WebformComputedBase.php, line 333
Class
- WebformComputedBase
- Provides a base class for 'webform_computed' elements.
Namespace
Drupal\webform\ElementCode
protected static function getWebformSubmission(array $element, FormStateInterface $form_state, array &$complete_form) {
$form_object = $form_state
->getFormObject();
if ($form_object instanceof WebformSubmissionForm) {
/** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */
$webform_submission = $form_object
->getEntity();
// We must continually copy validated form values to the
// webform submission since a computed element's value can be based on
// another computed element's value.
//
// Therefore, we are creating a single clone of the webform submission
// and only copying the submitted form values to the cached submission.
if ($form_state
->isValidationComplete() && !$form_state
->isRebuilding()) {
if (!isset(static::$submissions[$webform_submission
->uuid()])) {
static::$submissions[$webform_submission
->uuid()] = clone $form_object
->getEntity();
}
$webform_submission = static::$submissions[$webform_submission
->uuid()];
$form_object
->copyFormValuesToEntity($webform_submission, $complete_form, $form_state);
}
return $webform_submission;
}
elseif (isset($element['#webform_submission'])) {
if (is_string($element['#webform_submission'])) {
return WebformSubmission::load($element['#webform_submission']);
}
else {
return $element['#webform_submission'];
}
}
else {
return NULL;
}
}