@@ -51,6 +51,13 @@ class OpenFiscaJourneyHandler extends WebformHandlerBase {
5151 */
5252 protected RacContentHelperInterface $ racContentHelper ;
5353
54+ /**
55+ * The debug data from the last API call to OpenFisca.
56+ *
57+ * @var array<string, \Drupal\webform_openfisca\OpenFisca\Payload>
58+ */
59+ protected array $ recentDebugData = [];
60+
5461 /**
5562 * {@inheritdoc}
5663 */
@@ -83,7 +90,9 @@ public function submitForm(array &$form, FormStateInterface $form_state, Webform
8390 public function alterElement (array &$ element , FormStateInterface $ form_state , array $ context ) : void {
8491 $ form_object = $ form_state ->getFormObject ();
8592 if (!$ form_object instanceof WebformSubmissionForm) {
93+ // @codeCoverageIgnoreStart
8694 return ;
95+ // @codeCoverageIgnoreEnd
8796 }
8897 if ($ form_object ->getOperation () !== 'add ' ) {
8998 return ;
@@ -157,7 +166,7 @@ public function requestOpenFiscaImmediateResponse(array $form, FormStateInterfac
157166 }
158167 else {
159168 $ triggering_element = $ form_state ->getTriggeringElement ();
160- if (isset ($ values [$ triggering_element ['#name ' ]])) {
169+ if (isset ($ triggering_element [ ' #name ' ], $ values [$ triggering_element ['#name ' ]])) {
161170 $ data = [
162171 'name ' => $ triggering_element ['#name ' ],
163172 'webform ' => $ triggering_element ['#webform ' ] ?? $ webform ->id (),
@@ -260,7 +269,9 @@ protected function prepareOpenfiscaPayload(WebformSubmissionInterface $webform_s
260269 $ role = $ fisca_entity_role ['role ' ] ?? NULL ;
261270 $ is_array = $ fisca_entity_role ['is_array ' ] ?? FALSE ;
262271 if (empty ($ role )) {
272+ // @codeCoverageIgnoreStart
263273 continue ;
274+ // @codeCoverageIgnoreEnd
264275 }
265276 // The role will be in the format
266277 // group_entity.group_entity_key.role.entity_key
@@ -350,7 +361,10 @@ protected function determineBenefits(RequestPayload $request_payload, ?ResponseP
350361 foreach ($ fisca_field_mappings as $ webform_key => $ openfisca_key ) {
351362 // Always ignore period key.
352363 if ($ webform_key === 'period ' ) {
364+ // @codeCoverageIgnoreStart
365+ // Period should be alread unset while being prepared.
353366 continue ;
367+ // @codeCoverageIgnoreEnd
354368 }
355369 if ($ openfisca_key !== '_nil ' ) {
356370 // The openfisca_key will be in the format
@@ -461,6 +475,15 @@ protected function overrideConfirmationUrl(ResponsePayload $response_payload) :
461475 public function logDebug (RequestPayload $ request_payload , ?ResponsePayload $ response_payload , bool $ show_message = TRUE ) : void {
462476 $ webform = $ this ->getWebform ();
463477 $ openfisca_settings = WebformOpenFiscaSettings::load ($ webform );
478+
479+ // Set the debug data.
480+ if ($ openfisca_settings ->isDebugEnabled ()) {
481+ $ this ->recentDebugData = [
482+ 'request ' => $ request_payload ,
483+ 'response ' => $ response_payload ,
484+ ];
485+ }
486+
464487 if (!$ openfisca_settings ->isDebugEnabled () && !$ openfisca_settings ->isLoggingEnabled ()) {
465488 return ;
466489 }
@@ -554,4 +577,16 @@ public function logDebug(RequestPayload $request_payload, ?ResponsePayload $resp
554577 }
555578 }
556579
580+ /**
581+ * Return the debug data from the last API call to OpenFisca.
582+ *
583+ * @return \Drupal\webform_openfisca\OpenFisca\Payload[]
584+ * The data array with 2 keys if debug mode is enabled:
585+ * - request
586+ * - response
587+ */
588+ public function getRecentDebugData () : array {
589+ return $ this ->recentDebugData ;
590+ }
591+
557592}
0 commit comments