From 61ccb99e9ff4e6a2b0081a5da4e28900a7510be7 Mon Sep 17 00:00:00 2001 From: sylus Date: Mon, 11 Dec 2023 21:36:52 -0500 Subject: [PATCH] feat(phpcs): Correct linting errors" --- modules/custom/wxt_core/wxt_core.install | 19 +------- .../wxt_ext/wxt_ext_page/wxt_ext_page.install | 47 ++++++++----------- 2 files changed, 21 insertions(+), 45 deletions(-) diff --git a/modules/custom/wxt_core/wxt_core.install b/modules/custom/wxt_core/wxt_core.install index 49606ad5..5d157427 100644 --- a/modules/custom/wxt_core/wxt_core.install +++ b/modules/custom/wxt_core/wxt_core.install @@ -675,19 +675,7 @@ function wxt_core_update_8500() { * Setup CountryManager lists [#3111375]. */ function wxt_core_update_8501() { - $config_namespace = 'wxt_core.settings.countries'; - $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)); - - // Get the configuration factory service. - $config_factory = \Drupal::configFactory(); - - // Save the configuration using the loaded data. - $config = $config_factory->getEditable($config_namespace); - $config->setData($country_data); - $config->save(); + // [#3399929] wxt_core_update_8502 in favour } /** @@ -704,11 +692,6 @@ function wxt_core_update_8502() { if ($hasUpdated) { $country_data = $config_factory->getEditable($legacy); $config = $config_factory->getEditable($updated); - if (!is_array($country_data)) { - // Update hook 8501 wasn't run correctly for some reason, or the yml was deleted. - wxt_core_update_8501(); - return; - } $config->setData($country_data); $config->save(); // Delete old data. diff --git a/modules/custom/wxt_ext/wxt_ext_page/wxt_ext_page.install b/modules/custom/wxt_ext/wxt_ext_page/wxt_ext_page.install index 355284a8..b2be99ff 100644 --- a/modules/custom/wxt_ext/wxt_ext_page/wxt_ext_page.install +++ b/modules/custom/wxt_ext/wxt_ext_page/wxt_ext_page.install @@ -42,39 +42,32 @@ function wxt_ext_page_install() { * Add field_lead_title to page content type. */ function wxt_ext_page_update_8500() { - $types = \Drupal::entityTypeManager() - ->getStorage('node_type') - ->loadMultiple(); + $config_directory = new FileStorage(\Drupal::service('extension.list.module')->getPath('wxt_ext_page') . '/config/optional/'); - if (in_array('page', array_keys($types))) { - - $config_directory = new FileStorage(\Drupal::service('extension.list.module')->getPath('wxt_ext_page') . '/config/optional/'); - - $entitytype_fields = [ - 'node' => [ - 'page' => [ - 'field_lead_title', - ], + $entitytype_fields = [ + 'node' => [ + 'page' => [ + 'field_lead_title', ], - ]; + ], + ]; - // Approach taken from https://thinkshout.com/blog/2020/11/populating-fields - foreach ($entitytype_fields as $entitytype => $bundles) { - foreach ($bundles as $bundle => $fields) { - foreach ($fields as $field) { - $field_storage_name = 'field.storage.' . $entitytype . '.' . $field; - $config_record = $config_directory->read($field_storage_name); + // Approach taken from https://thinkshout.com/blog/2020/11/populating-fields + foreach ($entitytype_fields as $entitytype => $bundles) { + foreach ($bundles as $bundle => $fields) { + foreach ($fields as $field) { + $field_storage_name = 'field.storage.' . $entitytype . '.' . $field; + $config_record = $config_directory->read($field_storage_name); - if (!FieldStorageConfig::loadByName($config_record['entity_type'], $config_record['field_name'])) { - FieldStorageConfig::create($config_record)->save(); - } + if (!FieldStorageConfig::loadByName($config_record['entity_type'], $config_record['field_name'])) { + FieldStorageConfig::create($config_record)->save(); + } - $field_config_name = 'field.field.' . $entitytype . '.' . $bundle . '.' . $field; - $config_record = $config_directory->read($field_config_name); + $field_config_name = 'field.field.' . $entitytype . '.' . $bundle . '.' . $field; + $config_record = $config_directory->read($field_config_name); - if (!FieldConfig::loadByName($config_record['entity_type'], $config_record['bundle'], $config_record['field_name'])) { - FieldConfig::create($config_record)->save(); - } + if (!FieldConfig::loadByName($config_record['entity_type'], $config_record['bundle'], $config_record['field_name'])) { + FieldConfig::create($config_record)->save(); } } }