Skip to content

Commit

Permalink
Handled nested elements in webform inherit
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed Oct 27, 2023
1 parent b6dc947 commit cfa38c8
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Drupal\os2forms_forloeb\Plugin\EngineTasks;

use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\maestro\Engine\MaestroEngine;
use Drupal\maestro_webform\Plugin\EngineTasks\MaestroWebformTask;
use Drupal\webform\Entity\Webform;
use Drupal\webform\Entity\WebformSubmission;
use Drupal\webform\Utility\WebformArrayHelper;

Expand Down Expand Up @@ -152,9 +154,15 @@ public static function webformSubmissionFormAlter(array &$form, FormStateInterfa
if ('webform_submission' === ($entityIdentifier['entity_type'] ?? NULL)) {
$submission = WebformSubmission::load($entityIdentifier['entity_id']);
$data = $submission->getData();
foreach ($data as $key => $value) {
if (isset($form['elements'][$key])) {
$form['elements'][$key]['#default_value'] = $value;

// The target element may be hidden inside nested elements on the form.
if ($targetWebform = Webform::load($form['#webform_id'] ?? NULL)) {
foreach ($data as $key => $value) {
if ($targetElement = $targetWebform->getElement($key)) {
if ($element = &NestedArray::getValue($form['elements'], $targetElement['#webform_parents'])) {
$element['#default_value'] = $value;
}
}
}
}
}
Expand Down

0 comments on commit cfa38c8

Please sign in to comment.