Skip to content

Commit

Permalink
MOC-813-85849 getting CPR field value
Browse files Browse the repository at this point in the history
  • Loading branch information
stankut committed Mar 23, 2020
1 parent eafb10e commit f5e0e66
Showing 1 changed file with 5 additions and 31 deletions.
36 changes: 5 additions & 31 deletions modules/os2forms_sbsys/src/Element/WebformAttachmentSbsysXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,41 +175,15 @@ public static function getElementConfiguration(array $element) {
* Submission value.
*/
protected static function getFirstValueByType($type, WebformSubmissionInterface $webform_submission) {
$value = NULL;
$webform = $webform_submission->getWebform();
$webform_elements = $webform->getElementsDecoded();
foreach ($webform_elements as $key => $webform_element) {
if ($el_key = self::getElementKeyByType($webform_element, $type, $key)) {
$value = $webform_submission->getElementData($el_key);
break;
}
}
return $value;
}

/**
* Gets key of first element by field type.
*
* @param array $webform_element
* The element of the webform.
* @param string $type
* Element value type.
* @param string $el_key
* Current element key.
*
* @return mixed
* Element key.
*/
protected static function getElementKeyByType(array $webform_element, $type, $el_key) {
foreach ($webform_element as $key => $value) {
if ($key == '#type' && $value == $type) {
return $el_key;
}
elseif (is_array($value)) {
return self::getElementKeyByType($value, $type, $key);
$webform_elements = $webform->getElementsDecodedAndFlattened();

foreach ($webform_elements as $key => $webform_element) {
if ($webform_element['#type'] == $type) {
return $webform_submission->getElementData($key);
}
}
return FALSE;
}

/**
Expand Down

0 comments on commit f5e0e66

Please sign in to comment.