Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handled nested elements in webform inherit #73

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa

## [Unreleased]

- [#73](https://github.com/OS2Forms/os2forms/pull/73a)
Fix issue with nested elements in webform inherit
- [#72](https://github.com/OS2Forms/os2forms/pull/72)
Fix certificate testing, also testing for RSA/PEM certs as well as PKCS12

Expand Down
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,18 @@ 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 sections or field groups
// on the target form. Therefore, we need to load that form and get
// element information to properly set default element values nested
// inside 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
Loading