Skip to content

Commit dd80c38

Browse files
g2410gGaurav Garg
andauthored
[GOVRACPROD-45] Remove immediate exit feature. (#51)
* [GOVRACPROD-45] Remove immediate exit feature. * [GOVRACPROD-45] Fix PHPCS issue. * [GOVRACPROD-45] Remove immediate exit from Alter. * [GOVRACPROD-45] Remove unwanted change. * [GOVRACPROD-45] Remove immediate exit feature. * [GOVRACPROD-45] Fix PHPCS issue. * [GOVRACPROD-45] Fix PHPCS issue. * [GOVRACPROD-45] Remove immediate exit code from Tests. --------- Co-authored-by: Gaurav Garg <gauravgarg@Gauravs-MacBook-Pro-2.local>
1 parent 035cad9 commit dd80c38

28 files changed

+3
-1337
lines changed

config/schema/webform.third_party.webform_fisca.schema.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,3 @@ webform.settings.third_party.webform_openfisca:
3535
fisca_entity_roles:
3636
type: string
3737
label: 'JSON encoded entity roles'
38-
fisca_immediate_response_mapping:
39-
type: string
40-
label: 'JSON encoded immediate response mapping'
41-
fisca_immediate_response_ajax_indicator:
42-
type: boolean
43-
label: 'Display Ajax indicator for immediate response'
44-
fisca_immediate_exit_mapping:
45-
type: string
46-
label: 'OpenFisca return keys for immediate exit (comma-separated)'

js/webform_openfisca.immediate_response.js

Lines changed: 0 additions & 127 deletions
This file was deleted.

src/Form/WebformUiElementDeleteForm.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) : void
2525
$this->webform->setThirdPartySetting('webform_openfisca', 'fisca_field_mappings', $updated_settings->getJsonFieldMappings());
2626
$this->webform->setThirdPartySetting('webform_openfisca', 'fisca_variables', $updated_settings->getJsonVariables());
2727
$this->webform->setThirdPartySetting('webform_openfisca', 'fisca_entity_roles', $updated_settings->getJsonEntityRoles());
28-
$this->webform->setThirdPartySetting('webform_openfisca', 'fisca_immediate_response_mapping', $updated_settings->getJsonImmediateResponseMapping());
2928

3029
$this->webform->save();
3130
}

src/Plugin/WebformHandler/OpenFiscaJourneyHandler.php

Lines changed: 1 addition & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22

33
namespace Drupal\webform_openfisca\Plugin\WebformHandler;
44

5-
use Drupal\Component\Utility\Html;
65
use Drupal\Component\Utility\UrlHelper;
7-
use Drupal\Core\Ajax\AjaxResponse;
8-
use Drupal\Core\Ajax\InvokeCommand;
96
use Drupal\Core\Datetime\DrupalDateTime;
107
use Drupal\Core\Form\FormStateInterface;
11-
use Drupal\webform\Entity\WebformSubmission;
128
use Drupal\webform\Plugin\WebformHandlerBase;
139
use Drupal\webform\WebformSubmissionForm;
1410
use Drupal\webform\WebformSubmissionInterface;
@@ -108,88 +104,6 @@ public function alterElement(array &$element, FormStateInterface $form_state, ar
108104
if (!isset($element['#webform_key'])) {
109105
return;
110106
}
111-
112-
$element_key = $element['#webform_key'];
113-
// Add the immediate response handling to webform element.
114-
$fisca_immediate_response_ajax_indicator = $openfisca_settings->hasImmediateResponseAjaxIndicator();
115-
if ($openfisca_settings->fieldHasImmediateResponse($element_key)) {
116-
$element['#attributes']['data-openfisca-immediate-response'] = 'true';
117-
$element['#attributes']['data-openfisca-webform-id'] = $webform->id();
118-
$element['#attached']['library'][] = 'webform_openfisca/immediate_response';
119-
$element['#ajax'] = [
120-
'callback' => [$this, 'requestOpenFiscaImmediateResponse'],
121-
'disable-refocus' => TRUE,
122-
'event' => 'fiscaImmediateResponse:request',
123-
'progress' => [
124-
'type' => $fisca_immediate_response_ajax_indicator ? 'throbber' : 'none',
125-
],
126-
];
127-
}
128-
}
129-
130-
/**
131-
* Ajax callback to request immediate response from Openfisca.
132-
*
133-
* @param array $form
134-
* Form.
135-
* @param \Drupal\Core\Form\FormStateInterface $form_state
136-
* Form state.
137-
*
138-
* @return \Drupal\Core\Ajax\AjaxResponse
139-
* The Ajax response.
140-
*
141-
* @throws \Drupal\Core\Entity\EntityMalformedException
142-
*/
143-
public function requestOpenFiscaImmediateResponse(array $form, FormStateInterface $form_state) : AjaxResponse {
144-
$webform = $this->getWebform();
145-
$values = $form_state->getValues() ?: [];
146-
// Create a faux webform submission from current form values.
147-
$webform_submission = WebformSubmission::create([
148-
'data' => $values,
149-
'webform_id' => $this->getWebform()->id(),
150-
]);
151-
152-
$payload = $this->prepareOpenfiscaPayload($webform_submission);
153-
$openfisca_response = NULL;
154-
$total_benefits = $this->determineBenefits($payload, $openfisca_response);
155-
$query_append = $openfisca_response?->getDebugData('query_append') ?: [];
156-
157-
$immediate_response = [];
158-
// Override the confirmation URL if there is a benefit or an immediate exit.
159-
if (($total_benefits !== 0 || !empty($query_append['immediate_exit']))
160-
&& $openfisca_response instanceof ResponsePayload
161-
) {
162-
$confirmation_url = $this->overrideConfirmationUrl($openfisca_response);
163-
$immediate_response = [
164-
'confirmation_url' => $confirmation_url,
165-
'query' => $openfisca_response->getDebugData('query') ?: '',
166-
];
167-
}
168-
169-
$response = new AjaxResponse();
170-
if (!empty($immediate_response)) {
171-
$response->addCommand(new InvokeCommand('', 'webformOpenfiscaImmediateResponseRedirect', [$immediate_response]));
172-
}
173-
else {
174-
$triggering_element = $form_state->getTriggeringElement();
175-
if (isset($triggering_element['#name'], $values[$triggering_element['#name']])) {
176-
$data = [
177-
'name' => $triggering_element['#name'],
178-
'webform' => $triggering_element['#webform'] ?? $webform->id(),
179-
'selector' => $triggering_element['#attributes']['data-drupal-selector'] ?? '',
180-
'original_selector' => '',
181-
];
182-
if (!empty($triggering_element['#id'])) {
183-
$original_id = preg_replace('/--([a-zA-Z0-9]{11})$/', '', $triggering_element['#id'], 1);
184-
$data['original_selector'] = Html::getId($original_id);
185-
}
186-
$response->addCommand(new InvokeCommand('', 'webformOpenfiscaImmediateResponseContinue', [$data]));
187-
}
188-
}
189-
190-
$this->logDebug($payload, $openfisca_response);
191-
192-
return $response;
193107
}
194108

195109
/**
@@ -299,18 +213,6 @@ protected function prepareOpenfiscaPayload(WebformSubmissionInterface $webform_s
299213
}
300214
}
301215

302-
// Add immediate exit mapping to the payload.
303-
$immediate_exit_mapping = $openfisca_settings->getImmediateExitKeys();
304-
foreach ($immediate_exit_mapping as $immediate_exit_key) {
305-
$path = [];
306-
$parents = [];
307-
$variable = OpenFiscaHelper::parseOpenFiscaFieldMapping($immediate_exit_key, path: $path, parents: $parents);
308-
if (!empty($variable) && $openfisca_payload->keyPathExists($parents) && !$openfisca_payload->keyPathExists($path)) {
309-
$formatted_period = $openfisca_settings->formatVariablePeriod($variable, $period);
310-
$openfisca_payload->setValue($path, [$formatted_period => NULL]);
311-
}
312-
}
313-
314216
$openfisca_payload->setDebugData('query_append', $query_append);
315217

316218
return $openfisca_payload;
@@ -326,7 +228,7 @@ protected function prepareOpenfiscaPayload(WebformSubmissionInterface $webform_s
326228
* benefits will be stored in debug data of the payload.
327229
*
328230
* @return int
329-
* Number of benefits. -1 for immediate exit.
231+
* Number of benefits.
330232
*/
331233
protected function determineBenefits(RequestPayload $request_payload, ?ResponsePayload &$response_payload = NULL) : int {
332234
$openfisca_settings = WebformOpenFiscaSettings::load($this->getWebform());
@@ -400,21 +302,6 @@ protected function determineBenefits(RequestPayload $request_payload, ?ResponseP
400302
}
401303
$query_append['total_benefit'] = $total_benefits;
402304

403-
// Attempt to determine the special immediate exit.
404-
$immediate_exit_mapping = $openfisca_settings->getImmediateExitKeys();
405-
foreach ($immediate_exit_mapping as $immediate_exit_key) {
406-
$path = [];
407-
OpenFiscaHelper::parseOpenFiscaFieldMapping($immediate_exit_key, path: $path);
408-
if ($response_payload->keyPathExists($path)) {
409-
$immediate_exit = $response_payload->getValue($path);
410-
if (is_array($immediate_exit) && !empty(array_filter($immediate_exit))) {
411-
$query_append['immediate_exit'] = TRUE;
412-
$total_benefits = -1;
413-
break;
414-
}
415-
}
416-
}
417-
418305
// Set debug data to the response payload.
419306
$response_payload->setDebugData('query_append', $query_append);
420307
$response_payload->setDebugData('fisca_fields', $fisca_fields);

0 commit comments

Comments
 (0)