Skip to content

Commit

Permalink
Merge pull request #152 from localgovdrupal/151-error-on-cache-clear
Browse files Browse the repository at this point in the history
Fixed error about non-existent config entity name that can show up after install.
  • Loading branch information
rupertj committed Apr 16, 2024
2 parents 440dbb6 + 04c0205 commit 73bf905
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
26 changes: 26 additions & 0 deletions localgov_publications.install
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,29 @@ function localgov_publications_install() {
$wysiwygFormat->save();
}
}

/**
* Fixes error messages after this module is installed.
*
* Remove references to the book content type from the key value store that are
* left over after book's config is removed.
*/
function localgov_publications_update_10001() {

// If the book content type is still installed in the site, don't do anything.
$entityTypeManager = \Drupal::service('entity_type.manager');
$bookType = $entityTypeManager->getStorage('node_type')->load('book');
if ($bookType) {
return;
}

// See localgov_publications_modules_installed() for what this code does.
// It's added here so it runs on existing installs too.
$kvStore = \Drupal::keyValue('entity.definitions.bundle_field_map');
$fieldMap = $kvStore->get('node');
if (isset($fieldMap['body']['bundles']['book'])) {
unset($fieldMap['body']['bundles']['book']);
$kvStore->set('node', $fieldMap);
}
\Drupal::cache('discovery')->delete('entity_field_map');
}
12 changes: 12 additions & 0 deletions localgov_publications.module
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ function localgov_publications_modules_installed($modules, $is_syncing) {
\Drupal::configFactory()->getEditable($config_name)->delete();
}
\Drupal::configFactory()->getEditable('node.type.book')->delete();

// The mapping of fields to bundles is stored in the key-value store. As we
// removed the content type and its fields on a config level, we also need
// to clear out the book data from here, as it won't be done for us like it
// is when you delete a content type via the UI.
$kvStore = \Drupal::keyValue('entity.definitions.bundle_field_map');
$fieldMap = $kvStore->get('node');
unset($fieldMap['body']['bundles']['book']);
$kvStore->set('node', $fieldMap);

// Clear the cache where the full map is stored.
\Drupal::cache('discovery')->delete('entity_field_map');
}
}

Expand Down

0 comments on commit 73bf905

Please sign in to comment.