This is linked to [issue 158](https://lab.civicrm.org/dev/drupal/-/issues/158) and [issue 37](https://lab.civicrm.org/dev/drupal/-/issues/37).
It takes an alternative approach, adding a Util hook function to rebuild the route cache which we can then invoke from multiple places.
Trigger `rebuildDrupalRouteCache()` when running `triggerRebuild()`
Fix checkstyle issues
Change function from `protected` to `public`
Update Drupal8.php
Add base for `invalidateRouteCache()`
Add invalidateRouteCache function
Add call to userFramework->invalidateRouteCache
Update Base.php
Correct `userFramework` to `userSystem`
Remove stray whitespace.
Move invalidateRouteCache call to the same place as resetNavigation.
Update Invoke.php
Switch to the `router.builder' option as invalidating the cache doesn't cut it.
CRM_Utils_Request::retrieve('triggerRebuild', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET')
) {
CRM_Core_DAO::triggerRebuild();
+ $config->userSystem->invalidateRouteCache();
}
CRM_Core_DAO_AllCoreTables::reinitializeCache(TRUE);
CRM_Core_ManagedEntities::singleton(TRUE)->reconcile();
return [];
}
+ /**
+ * Invalidates the cache of dynamic routes and forces a rebuild.
+ */
+ public function invalidateRouteCache() {
+ }
+
}
return \Drupal::entityTypeManager()->getStorage('user')->load($userID);
}
+ /**
+ * Helper function to rebuild the Drupal 8 or 9 dynamic routing cache.
+ * We need to do this after enabling extensions that add routes and it's worth doing when we reset Civi paths.
+ */
+ public function invalidateRouteCache() {
+ if (class_exists('\Drupal') && \Drupal::hasContainer()) {
+ \Drupal::service('router.builder')->rebuild();
+ }
+ }
+
}