Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure array key exists before accessing it #102

Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa
NemLogin autologout pop-up styling.
- [#99](https://github.com/OS2Forms/os2forms/pull/99)
Fix coding standards.
- [#102](https://github.com/OS2Forms/os2forms/pull/102)
Fix array access with `purge_days` configuration.

## [3.14.1] 2024-01-16

Expand Down
12 changes: 6 additions & 6 deletions modules/os2forms_forloeb/os2forms_forloeb.module
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ function os2forms_forloeb_webform_create(WebformInterface $webform) {
if (empty($webform->getSetting('purge_days'))) {
/** @var \Drupal\webform\WebformThirdPartySettingsManagerInterface $third_party_settings_manager */
$third_party_settings_manager = \Drupal::service('webform.third_party_settings_manager');
$os2forms_forloeb_settings = $third_party_settings_manager->getThirdPartySetting('os2forms', 'os2forms_forloeb') ?: 30;
$os2forms_forloeb_settings = $third_party_settings_manager->getThirdPartySetting('os2forms', 'os2forms_forloeb');

$webform->setSetting('purge_days', $os2forms_forloeb_settings['purge_days']);
$webform->setSetting('purge_days', $os2forms_forloeb_settings['purge_days'] ?? 30);
}
}

Expand All @@ -165,9 +165,9 @@ function os2forms_forloeb_webform_presave(WebformInterface $webform) {
if (empty($webform->getSetting('purge_days'))) {
/** @var \Drupal\webform\WebformThirdPartySettingsManagerInterface $third_party_settings_manager */
$third_party_settings_manager = \Drupal::service('webform.third_party_settings_manager');
$os2forms_forloeb_settings = $third_party_settings_manager->getThirdPartySetting('os2forms', 'os2forms_forloeb') ?: 30;
$os2forms_forloeb_settings = $third_party_settings_manager->getThirdPartySetting('os2forms', 'os2forms_forloeb');

$webform->setSetting('purge_days', $os2forms_forloeb_settings['purge_days']);
$webform->setSetting('purge_days', $os2forms_forloeb_settings['purge_days'] ?? 30);
}
}

Expand Down Expand Up @@ -392,12 +392,12 @@ function _os2forms_forloeb_helper(): MaestroHelper {
function os2forms_forloeb_form_os2forms_settings_alter(&$form, FormStateInterface $form_state) {
/** @var \Drupal\webform\WebformThirdPartySettingsManagerInterface $third_party_settings_manager */
$third_party_settings_manager = \Drupal::service('webform.third_party_settings_manager');
$os2forms_forloeb_settings = $third_party_settings_manager->getThirdPartySetting('os2forms', 'os2forms_forloeb') ?: 30;
$os2forms_forloeb_settings = $third_party_settings_manager->getThirdPartySetting('os2forms', 'os2forms_forloeb');

$form['third_party_settings']['os2forms']['os2forms_forloeb']['purge_days'] = [
'#type' => 'textfield',
'#title' => t('Default number of days to retain submissions'),
'#default_value' => !(empty($os2forms_forloeb_settings)) ? $os2forms_forloeb_settings['purge_days'] : 30,
'#default_value' => $os2forms_forloeb_settings['purge_days'] ?? 30,
'#description' => t('Default value is used when creating a new form, after that it is saved on a form level'),
];
}
Loading