• Development

    Block Caching “Gotcha” in Drupal 8

    I recently had a fight with the Block system in Drupal 8. To be brief, if you’re trying to disable caching on a block, make sure to set the #cache element regardless of whether the block has output or not.

    This does not work (empty result gets cached):

     

    This does work (nothing gets cached, as desired):

     

  • Development

    Using module_list() to show active Drupal modules

    This code can be used in a custom module, a template.php file, or most easily in a block. This looks good in the header bar on a demo site, without a title, as you can see in the screenshot! The reason I am using this is because I do a lot of Drupal demos and it’s great to have the active modules showing so there is no question of what’s required to do whatever it is I am showing. The list of modules is ordered by weight, then filename, which makes it easy to determine if your custom modules are running at the right times.

    Screenshot of the block displayed in the sites header region:

    active_modules_block