Skip to content

Commit 5eca594

Browse files
committed
Avoided accessing non-initialized property
1 parent 8410760 commit 5eca594

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

modules/os2forms_nemid/src/Service/FormsHelper.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,15 @@ public function retrieveCprLookupResult(FormStateInterface $form_state) {
147147
$authProviderPlugin = $this->getAuthProvider($form_state);
148148

149149
$userCpr = $authProviderPlugin->fetchValue('cpr');
150-
$lookedUpCpr = $cprLookupResult->getCpr();
151-
152-
$this->auditLogger->info('DataLookup', 'User with cpr ' . $userCpr . ' looked up cpr ' . $lookedUpCpr);
150+
$lookedUpCpr = $cprLookupResult->getFieldValue('cpr');
151+
152+
// Current method is called whenever the webform is rendered.
153+
// As a result, it is also called in situations where both
154+
// userCpr and lookedUpCpr does not make sense, e.g.
155+
// adding an element to a webform.
156+
if ($userCpr && $lookedUpCpr) {
157+
$this->auditLogger->info('DataLookup', 'User with cpr ' . $userCpr . ' looked up cpr ' . $lookedUpCpr);
158+
}
153159

154160
return $cprLookupResult;
155161
}

0 commit comments

Comments
 (0)