-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hotfix: Applied patch to handle nested elements in webform inherit
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
patches/drupal/os2forms/handle_nested_elements_in_webform_inherit.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
diff --git a/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php b/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php | ||
index b04137c..8bd0040 100644 | ||
--- a/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php | ||
+++ b/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php | ||
@@ -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; | ||
|
||
@@ -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; | ||
+ } | ||
+ } | ||
} | ||
} | ||
} |