#StackBounty: #8 #blocks Custom Block from module not showing on front-end?

Bounty: 50

I have created a custom block in a custom module. Sometimes the block appears correctly, and sometimes the block doesn’t appear. The same happens when I clear the cache.

The build() method returns the following value.

return [
  '#markup' => $html,
  '#cache' => array('max-age' => 0)

I also tried with the following code.

return (array(
  '#type' => 'markup',
  '#cache' => array('max-age' => 0),
  '#markup' => $html,

These are the other methods of the block.

protected function blockAccess(AccountInterface $account) {
  return AccessResult::allowedIfHasPermission($account, 'access content');

public function blockForm($form, FormStateInterface $form_state) {
  $config = $this->getConfiguration();

  return $form;

public function blockSubmit($form, FormStateInterface $form_state) {
  $this->configuration['custom_block_settings'] = $form_state->getValue('custom_block_settings');

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.