Skip to content

Commit

Permalink
feat(phpcs): Correct linting errors"
Browse files Browse the repository at this point in the history
  • Loading branch information
sylus committed Dec 12, 2023
1 parent 5e33225 commit 61ccb99
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 45 deletions.
19 changes: 1 addition & 18 deletions modules/custom/wxt_core/wxt_core.install
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand All @@ -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.
Expand Down
47 changes: 20 additions & 27 deletions modules/custom/wxt_ext/wxt_ext_page/wxt_ext_page.install
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down

0 comments on commit 61ccb99

Please sign in to comment.