Skip to content

Commit

Permalink
#867: Applied coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
jekuaitk committed Mar 21, 2024
1 parent 0f4e07c commit 49c1565
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
6 changes: 2 additions & 4 deletions modules/os2forms_nemid/os2forms_nemid.module
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ function os2forms_nemid_webform_third_party_settings_form_alter(&$form, FormStat
'#description' => t('Redirection will happen right after user has is accessing the form, if user is already authenticated via NemID, redirection will not happen.'),
];


$nemloginProtectionSettings = $webform->getThirdPartySetting('os2forms', 'os2forms_nemid_address_protection');

// OS2Forms NemID.
Expand All @@ -94,7 +93,6 @@ function os2forms_nemid_webform_third_party_settings_form_alter(&$form, FormStat
'#open' => TRUE,
];


// Nemlogin auto redirect.
$form['third_party_settings']['os2forms']['os2forms_nemid_address_protection']['nemlogin_hide_form'] = [
'#type' => 'select',
Expand All @@ -119,7 +117,7 @@ function os2forms_nemid_webform_third_party_settings_form_alter(&$form, FormStat
],
'required' => [
[':input[name="third_party_settings[os2forms][os2forms_nemid_address_protection][nemlogin_hide_form]"]' => ['value' => FormsHelper::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_DISPLAY_ERROR]],
]
],
],
];
}
Expand All @@ -129,7 +127,7 @@ function os2forms_nemid_webform_third_party_settings_form_alter(&$form, FormStat
*/
function os2forms_nemid_webform_submission_form_alter(array &$form, FormStateInterface $form_state, $form_id) {

// Handle address protection
// Handle address protection.
if ($tempValue = $form_state->getTemporaryValue(FormsHelper::TEMPORARY_KEY)) {
if (FALSE === ($tempValue['access'] ?? TRUE)) {
// Flattening the elements makes it much easier to access nested elements.
Expand Down
19 changes: 12 additions & 7 deletions modules/os2forms_nemid/src/Service/FormsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class FormsHelper {
'os2forms_nemid_postal_code',
'os2forms_nemid_city',
'os2forms_nemid_kommunekode',
'os2forms_nemid_coaddress'
'os2forms_nemid_coaddress',
];

/**
Expand Down Expand Up @@ -77,6 +77,8 @@ class FormsHelper {
* Auth provider service.
* @param \Drupal\os2web_datalookup\Plugin\DataLookupManager $dataLookPluginManager
* Datalookup plugin manager.
* @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
* Route match service.
*/
public function __construct(AuthProviderService $authProviderService, DataLookupManager $dataLookPluginManager, RouteMatchInterface $routeMatch) {
$this->authProviderService = $authProviderService;
Expand Down Expand Up @@ -361,27 +363,29 @@ public function webformSubmissionPrepareForm(WebformSubmissionInterface $webform
return;
}

// Check if hide address protection is selected
// Check if hide address protection is selected.
$hideForm = $webformSubmission->getWebform()->getThirdPartySettings('os2forms')['os2forms_nemid_address_protection']['nemlogin_hide_form'] ?? NULL;

if ($hideForm === self::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_DISPLAY_ERROR) {
$cprResult = $this->retrieveCprLookupResult($formState);

if ($cprResult && $cprResult->isNameAddressProtected()) {

// Check if any element violating address protection is present in webform.
$elements = $webformSubmission->getWebform()->getElementsDecodedAndFlattened();
// Check if any element violating address
// protection is present in webform.
$elements = $webformSubmission->getWebform()->getElementsDecodedAndFlattened();

foreach ($elements as $element) {

if(in_array($element['#type'], self::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_ELEMENT_TYPES)) {
if (in_array($element['#type'], self::WEBFORM_NEM_LOGIN_ADDRESS_PROTECTION_ELEMENT_TYPES)) {

// Violation detected, mark form state with temporary key and return.
// Violation detected,
// mark form state with temporary key and return.
$message = $webformSubmission->getWebform()->getThirdPartySettings('os2forms')['os2forms_nemid_address_protection']['nemlogin_hide_message'];

$formState->setTemporaryValue(self::TEMPORARY_KEY, [
'access' => FALSE,
'message' => $message
'message' => $message,
]);

return;
Expand All @@ -390,4 +394,5 @@ public function webformSubmissionPrepareForm(WebformSubmissionInterface $webform
}
}
}

}

0 comments on commit 49c1565

Please sign in to comment.