- Issue created by @lolgm
When I install the module the local actions cache is not revalidated correctly.
In this example I have two roles, "Content Basic" and "Content Admin".
If I create a new user and add the "Content Basic" role and navigate to the "/admin/content" page, he will be able to view it as expected.
Now I change the user's role to "Content Admin" and reload the "/admin/content" page.
The expected result would be that an "Add content" button would be added to the local actions, but I still don't have any local action.
Now if I clear the cache and reload the page the "Add content" button will appear as expected.
The opposite effect also happens, if you change the role to "Content Basic" and reload the page the "Add content" button will continue to appear, it will only be removed after clearing the cache.
After investigating a bit it seems to me that the problem is being created by replacing the "router.route_provider" service in the src/MicroSiteServiceProvider.php file.
From some quick tests I did it seems the issue will be resolved if I add 'user.roles' as required_cache_contexts.
...
class MicroSiteServiceProvider extends ServiceProviderBase implements ServiceModifierInterface {
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container) {
...
// Permissions related to site context are based on user referenced by site.
// We need so to add the user as a cache context.
if (!in_array('user', $renderer_config['required_cache_contexts'])) {
$renderer_config['required_cache_contexts'][] = 'user';
$renderer_config['required_cache_contexts'][] = 'user.roles';
}
...
}
}
Check if this solution break any system in the module.
None.
None.
None.
Active
1.0
Code