Skip to content

Commit

Permalink
Clear the correct cache
Browse files Browse the repository at this point in the history
  • Loading branch information
whikloj committed Sep 14, 2022
1 parent b6da7a5 commit 1d5abed
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Form/IslandoraSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,17 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
* Removes the Fedora Pseudo field from any entity bundles that have be unselected.
*
* @param array $current_config
* The current set of entity type & bundle to have the pseudo field, format {bundle}:{entity_type}
* The current set of entity types & bundles to have the pseudo field, format {bundle}:{entity_type}
* @param array $new_config
* The new set of entity type & bundle to have the pseudo field, format {bundle}:{entity_type}
* The new set of entity types & bundles to have the pseudo field, format {bundle}:{entity_type}
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\Core\Entity\EntityStorageException
*/
private function updateEntityViewConfiguration(array $current_config, array $new_config) {
$cache_tags = [];
$removed = array_diff($current_config, $new_config);
$added = array_diff($new_config, $current_config);
$entity_view_display = $this->entityTypeManager->getStorage('entity_view_display');
// types being removed
foreach ($removed as $bundle_type) {
Expand All @@ -384,10 +384,12 @@ private function updateEntityViewConfiguration(array $current_config, array $new
foreach ($entities as $entity) {
$entity->removeComponent(self::GEMINI_PSEUDO_FIELD);
$entity->save();
$cache_tags = array_merge($cache_tags, $entity->getCacheTags());
}
}
$entity_view_display->resetCache();
Cache::invalidateTags($cache_tags);
if (count($removed) > 0 || count($added) > 0) {
// If we added or cleared a type then clear the extra_fields cache.
// @see Drupal/core/lib/Drupal/Core/Entity/EntityFieldManager::getExtraFields
Cache::invalidateTags(["entity_field_info"]);
}
}
}

0 comments on commit 1d5abed

Please sign in to comment.