Skip to content

Commit

Permalink
feat: guards against RE-creating field config, storage config (#196)
Browse files Browse the repository at this point in the history
The original code shouldn't fail in most cases, but if `drush cim` runs
prior to `drush updb`, it will. The change prevents that from happening.
  • Loading branch information
ctorgalson authored Sep 16, 2024
1 parent d421dbe commit 3728f14
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,17 @@ function localgov_subsites_paragraphs_update_10001() {

foreach (array_merge($existingFields, $newFields) as $fieldName => $config) {
if (array_key_exists($fieldName, $newFields)) {
// Field Storage.
$fieldStorage = FieldStorageConfig::create($config['field_storage']);
$fieldStorage->save();
if (!FieldStorageConfig::loadByName('paragraph', $fieldName)) {
// Field Storage.
$fieldStorage = FieldStorageConfig::create($config['field_storage']);
$fieldStorage->save();
}

// Field Config.
$fieldConfig = FieldConfig::create($config['field_config']);
$fieldConfig->save();
if (!FieldConfig::loadByName('paragraph', 'localgov_accordion', $fieldName)) {
// Field Config.
$fieldConfig = FieldConfig::create($config['field_config']);
$fieldConfig->save();
}

// View Display.
if ($viewDisplay) {
Expand All @@ -88,11 +92,10 @@ function localgov_subsites_paragraphs_update_10001() {

if (!in_array($dependency, $dependencies, TRUE)) {
$dependencies[] = $dependency;
$viewDisplay->set('dependencies', ['config' => $dependencies]);
$viewDisplay->removeComponent($fieldName);
$viewDisplay->save();
}

$viewDisplay->set('dependencies', ['config' => $dependencies]);
$viewDisplay->removeComponent($fieldName);
$viewDisplay->save();
}

// Form Display.
Expand All @@ -107,10 +110,9 @@ function localgov_subsites_paragraphs_update_10001() {
'region' => 'content',
'settings' => ['display_label' => TRUE],
]);
$formDisplay->set('dependencies', ['config' => $dependencies]);
$formDisplay->save();
}

$formDisplay->set('dependencies', ['config' => $dependencies]);
$formDisplay->save();
}
}

Expand Down

0 comments on commit 3728f14

Please sign in to comment.