Skip to content

Commit

Permalink
Issue #3399929 by SKAUGHT: Change wxt_core countries config name
Browse files Browse the repository at this point in the history
  • Loading branch information
skaught authored and sylus committed Nov 13, 2023
1 parent 233dc55 commit 71d8742
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
4 changes: 2 additions & 2 deletions modules/custom/wxt_core/src/CountriesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function listCounties() {
*/
public function whitelistedOptions() {
$standartCountries = $this->listCounties();
$config = $this->configFactory->get('wxt_core_countries.settings');
$config = $this->configFactory->get('wxt_core.settings.countries');
$countries = $config->get('countries');
foreach ($countries as $abbr => $checkbox) {
if ($checkbox != 0) {
Expand All @@ -108,7 +108,7 @@ public function whitelistedOptions() {
* Returns the sorted whitelisted.
*/
public function whitelistedOptionsSorted() {
$config = $this->configFactory->get('wxt_core_countries.settings');
$config = $this->configFactory->get('wxt_core.settings.countries');
$whitelist = $this->whitelistedOptions();
switch ($config->get('whitelist-sort')) {
case 'alpha':
Expand Down
6 changes: 3 additions & 3 deletions modules/custom/wxt_core/src/Form/CountriesWhitelistForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CountriesWhitelistForm extends ConfigFormBase {
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['wxt_core_countries.settings'];
return ['wxt_core.settings.countries'];
}

/**
Expand All @@ -31,7 +31,7 @@ public function getFormId() {
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$countryManager = \Drupal::service('wxt.country_whitelist');
$config = $this->config('wxt_core_countries.settings');
$config = $this->config('wxt_core.settings.countries');
$savedCountries = $config->get('countries');
$whitelisted = $countryManager->getCountryData();
$options = $countryManager->listCounties();
Expand Down Expand Up @@ -96,7 +96,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('wxt_core_countries.settings')
$this->config('wxt_core.settings.countries')
->set('countries', $form_state->getValue('countries'))
->set('whitelist-sort', $form_state->getValue('whitelist-sort'))
->save();
Expand Down
36 changes: 25 additions & 11 deletions modules/custom/wxt_core/wxt_core.install
Original file line number Diff line number Diff line change
Expand Up @@ -675,17 +675,31 @@ function wxt_core_update_8500() {
* Setup CountryManager lists [#3111375].
*/
function wxt_core_update_8501() {
$config_namespace = 'wxt_core_countries.settings';
$module_handler = \Drupal::service('module_handler');
$module_path = $module_handler->getModule('wxt_core')->getPath();
$path = DRUPAL_ROOT . '/' . $module_path . '/config/install/' . $config_namespace . '.yml';
$country_data = Yaml::parse(\file_get_contents($path));
// [#3399929] wxt_core_update_8502 in favour
}

// Get the configuration factory service.
/**
* [#3399929] Change wxt_core countries config namespace.
*/
function wxt_core_update_8502() {
$legacy = 'wxt_core_countries.settings';
$updated = 'wxt_core.settings.countries';
$config_factory = \Drupal::configFactory();

// Save the configuration using the loaded data.
$config = $config_factory->getEditable($config_namespace);
$config->setData($country_data);
$config->save();
$module_handler = \Drupal::service('module_handler');
$module_path = $module_handler->getModule('wxt_core')->getPath();
$path = DRUPAL_ROOT . '/' . $module_path . '/config/install/' . $updated . '.yml';
$hasUpdated = $config_factory->get($legacy)->isNew();
if ($hasUpdated) {
$country_data = $config_factory->getEditable($legacy);
$config = $config_factory->getEditable($updated);
$config->setData($country_data);
$config->save();
// Delete old data.
$country_data->delete();
} else {
$country_data = Yaml::parse(\file_get_contents($path));
$config = $config_factory->getEditable($updated);
$config->setData($country_data);
$config->save();
}
}
6 changes: 3 additions & 3 deletions modules/custom/wxt_ext/wxt_ext_webform/wxt_ext_webform.module
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function _gcweb_did_you_find_form_ajax_submit($form, $form_state) {
* Implements hook_webform_options_WEBFORM_OPTIONS_ID_alter() for country names options.
*/
function wxt_ext_webform_webform_options_country_names_alter(array &$options, array $element = []) {
$config = \Drupal::configFactory()->get('wxt_core_countries.settings');
$config = \Drupal::configFactory()->get('wxt_core.settings.countries');
if ($config->get('webform-override') == 1) {
$countryManager = \Drupal::service('wxt.country_whitelist');
$options = $countryManager->whitelistedOptionsSorted();
Expand All @@ -145,7 +145,7 @@ function wxt_ext_webform_form_wxt_core_countries_settings_form_alter(&$form, For
$form['webform-box']['webform-override'] = [
'#type' => 'checkbox',
'#title' => t('Override Webform Options for Country Names'),
'#default_value' => \Drupal::config('wxt_core_countries.settings')->get('webform-override'),
'#default_value' => \Drupal::config('wxt_core.settings.countries')->get('webform-override'),
'#description' => t('@link can be edited or reset in many circumstances.', ['@link' => $link->toString()]),
];
$form['#submit'][] = 'wxt_ext_webform_form_wxt_core_countries_submit';
Expand All @@ -156,7 +156,7 @@ function wxt_ext_webform_form_wxt_core_countries_settings_form_alter(&$form, For
*/
function wxt_ext_webform_form_wxt_core_countries_submit(&$form, FormStateInterface $form_state) {
\Drupal::configFactory()
->getEditable('wxt_core_countries.settings')
->getEditable('wxt_core.settings.countries')
->set('webform-override', $form_state->getValue('webform-override'))
->save();
}

0 comments on commit 71d8742

Please sign in to comment.