Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions js/openfisca-checkbox-popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(function (Drupal, drupalSettings) {
Drupal.behaviors.openFiscaCheckboxPopup = {
attach: function (context, settings) {
// Ensure we only attach once per context.
const checkboxes = context.querySelectorAll(
'input[name="third_party_settings[webform_openfisca][fisca_enabled]"]'
);

checkboxes.forEach(function (checkbox) {
if (!checkbox.dataset.popupAttached) {
checkbox.dataset.popupAttached = true;

checkbox.addEventListener('change', function () {
if (checkbox.checked) {
Drupal.dialog(
'<p>Please make sure that you have disabled saving of submissions for this form.</p>',
{
title: 'Important Notice',
width: 400
}
).showModal();
}
});
}
});
}
};
})(Drupal, drupalSettings);
11 changes: 11 additions & 0 deletions src/WebformThirdPartySettingsFormAlter.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ public function alterForm(array &$form, FormStateInterface $form_state): void {
'#default_value' => $openfisca_settings->hasImmediateResponseAjaxIndicator(),
'#weight' => 20,
];

$form['#validate'][] = [$this, 'validateForm'];

// Add popup for fisca_enabled checkbox.
$form['#attached']['library'][] = 'webform_openfisca/openfisca-checkbox-popup';
}

/**
Expand All @@ -174,6 +178,13 @@ public function validateForm(array $form, FormStateInterface $form_state): void
// @codeCoverageIgnoreEnd
}

$enabled = $form_state->getValue(['third_party_settings', 'webform_openfisca', 'fisca_enabled']);
if ($enabled) {
$this->messenger->addWarning(
$this->t('Please make sure that you have disabled saving of submissions for this form.')
);
}

$fisca_endpoint = $form_state->getValue(
['third_party_settings', 'webform_openfisca', 'fisca_api_endpoint']
) ?: '';
Expand Down
6 changes: 6 additions & 0 deletions webform_openfisca.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ immediate_response:
- core/drupal
- core/jquery
- core/once

openfisca-checkbox-popup:
js:
js/openfisca-checkbox-popup.js: {}
dependencies:
- core/drupal.dialog
Loading