This is an example module, which shows how to render custom block entities together with contextual links in Drupal 8
While rendering entities in a custom module, you may find that your markup is incorrect.. or rather incomplete, and contextual links are not showing up.
This very small example, will show you why is it happening when you try to render block content entity using BlockContentViewBuilder, but it might also happen while rendering content in any other way.
- A theme hook - a very simple one, just to provide custom template quickly
- Twig template which will wrap our entity in a container with all required markup
- A route - yet another page callback, to show visual example
- Custom controller - very simple one, it will load block content entities and render em in two different ways to show different behaviours
- Install this module using drush or UI, whatever
- Navigate to /admin/structure/block/block-content and add some custom blocks
- Navigate to /examples/block_content_contextual and check the output, the page will show 2 lists of custom blocks ( with and without contextual links )