Block access
Another major area where you will deal with access is when trying to control access to a custom block. If you remember, in Chapter 2, Creating Your First Module, we created the HelloWorldSalutationBlock
plugin so that our salutation can also be rendered using a block. Now that block can be placed in a region and even configured to show up only on certain pages, for certain user roles, or even on node pages restricted by bundle. This is all done in the UI:
Figure 10.3: Configuring our custom block
However, this is oftentimes not enough, and you will want to have a block placed in a region and control under what circumstances it should show up yourself. Enter block access.
Inside the BlockBase
plugin base class, there is the blockAccess()
method, which always returns positively. This is because, by default, all blocks will be rendered once they are placed in a region. Unless, of course, they are configured to only show in certain cases, in...