From 8fef06abedffd0e5e8089445fc551faf46a74eed Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Mon, 29 Apr 2024 13:57:40 +0200 Subject: [PATCH 1/2] Ensure array key exists before accessing it --- modules/os2forms_forloeb/os2forms_forloeb.module | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/os2forms_forloeb/os2forms_forloeb.module b/modules/os2forms_forloeb/os2forms_forloeb.module index 7720908f..4636ec3d 100644 --- a/modules/os2forms_forloeb/os2forms_forloeb.module +++ b/modules/os2forms_forloeb/os2forms_forloeb.module @@ -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); } } @@ -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); } } @@ -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'), ]; } From 2472c13348c87603dac87d1db0f37b44429884d1 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Mon, 29 Apr 2024 14:04:05 +0200 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6cd32dd..13817971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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