- 🇪🇸Spain cbccharlie
In case this helps someone with the same need, here's what we have done:
In our case, we wanted the block to always be placed, both in the public and private parts, without having to do it through Drupal block management. To achieve this, we have:
- Loaded it into our module using the hook_page_top and always at the beginning for accessibility.
- By doing this, we didn't get the cookie blocked message in each component due to the logic of the CookiesKnockOutService class, which checks if the block is placed. Since we always want it to be placed, we need to alter this logic. To do this, we have converted that class to a service in a merge request (MR) from another issue on Drupal.org ( https://www.drupal.org/project/cookies/issues/3422880 ✨ Convert CookiesKnockOutService in service Needs review ), and in our module, using a ServiceProvider, we alter the service so that the doKnockOut method always returns true.
$cookies_ui_block = Drupal::service('plugin.manager.block')->createInstance('cookies_ui_block'); if ($cookies_ui_block instanceof BlockPluginInterface) { $block['cookies_ui_block'] = $cookies_ui_block->build(); $page_top = $block + $page_top; }
- 🇩🇪Germany Anybody Porta Westfalica
Thanks @cbccharlie while I don't think we should switch to a hook generally, I'm totally fine with providing better API ways to use COOKiES like this, if there are no other downsides :)
I commented the other issue.