I have a custom module where its only purpose is going to be serving up a block. I basically used these instructions: https://www.drupal.org/docs/creating-custom-modules/creating-custom-blocks/create-a-custom-block
These are my files' content.
modules/cat_custom/cat_custom.info.yml
name: Cat Custom
type: module
description: Custom functionality for Cat Custom
core_version_requirement: ^9
dependencies:
- drupal:block
modules/cat_custom/src/Plugin/Block/CatCounterBlock.php
namespace Drupal\cat_custom\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a 'Cat Counter' Block.
*
* @Block(
* id = "cat_counter_block",
* admin_label = @Translation("Cat Counter Block"),
* )
*/
class CatCounterBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
return [
'#markup' => $this->t('Hello, World!'),
];
}
}
When I first enable the module, I can see the block in the Add block list. When I run drush cr
, it disappears from that list. If I visit /admin/config/development/performance and click on Clear all caches, it re-appears. As soon as I run drush cr
, it disappears again.
If I place it when it's showing up, it works as expected initially. When I run drush cr
, the block's text gets replaced with the following message.
This block is broken or missing. You may be missing content or you might need to enable the original module.
I enabled and tried the block example from https://www.drupal.org/project/examples; it works as expected, even after a drush cr
.
What am I missing or doing wrong?
drush status
. Are both using the same PHP version? Are you using the latest Drush version installed via composer in the vendor directory?