Here is my problem. I have a drupal website I’m working on where I’ve got webform with custom settings (such as checklist with custom elements and some others). I was on 5.0-beta24 and everything was fine. I saw that an update to the RC3 was available so I tried to see if there was any breaking change. And it seems that my custom settings are no longer saved.
What is the breaking change, and is there a solution so I can still define my custom settings / another way to do it ?
You can find below my current function to alter the settings form and add my custom’s one.
<?php function mymodule__form_webform_settings_form_alter(&$ form, FormStateInterface $ form_state, $ form_id) { $ settings = $ form_state->getFormObject()->getEntity()->getSettings(); $ form['general_settings']['description']['#title'] = t("Subtitle"); $ form['general_settings']['description']['#type'] = 'textfield'; $ form['form_settings_categories'] = [ '#type' => 'details', '#title' => 'Catégories', '#open' => TRUE, '#input' => FALSE, ]; $ form['form_settings_categories']['categories'] = [ '#type' => 'checkboxes', '#options' => \Drupal\avantages\Services\PopulationsService::getPopulationList(), '#title' => t('Catégories'), '#default_value' => $ settings['categories'] ?? ['test'], '#required' => FALSE, ]; }
Edit :
After some research, it seems (but I can be wrong) that the line that cause trouble is this one
/** * {@inheritdoc} */ public function setSettings(array $ settings) { // Always apply the default settings. $ this->settings += static::getDefaultSettings(); // Now apply new settings. foreach ($ settings as $ name => $ value) { if (array_key_exists($ name, $ this->settings)) { $ this->settings[$ name] = $ value; } } return $ this; }
As my custom setting is not is getDefaultSettings, I can’t save it.
Is there any new way to save custom settings ?
Thanks