1
votes

I am building a custom module for Drupal 8.4.4 and is not detecting the hook_theme from a block. I get an error message saying "Theme hook gardentheme not found". If I uninstall the module and install it again, it works fine, but as soon as I clear the cache, it doesn't find the theme_hook anymore.

I notice that die() and exit; wont do anything on my .module file after clearing the cache, I feel as after clearing the cache the .module is not run anymore.

My module file called garden.module

<?php

/**
 * @file
 *
 */


/**
 * Implements hook_theme()
*/ 
function garden_theme($existing, $type, $theme, $path){ 

 return array('gardentheme' =>
  array(
    'variables' => array(
      'description' => NULL
      ),
     )
   );
  }

My block placed on src/Plugin/Block/GardenScheduleBlock.php

 <?php
 namespace Drupal\garden\Plugin\Block;

 use Drupal\Core\Block\BlockBase;

 /**
  * Provides a 'GardenSchedule' Block.
  *
  * @Block(
  *   id = "garden_schedule_block",
  *   admin_label = @Translation("Garden Schedule"),
  *   category = @Translation("Garden Schedule_Category"),
  * )
  */
  class GardenScheduleBlock extends BlockBase {

   /**
    * {@inheritdoc}
   */
   public function build() {
     return array(
       '#theme' => 'gardentheme',
       '#description' => "description test"
       );
   }

  }

Thanks in advance for any tips.

1
I had the exact same issue today - working on a very similar functionality. Using Drupal 8.4.5 (Acquia Lightning). What seemed to help me (at least I haven't been able to break it yet) is running core/rebuild.php - make sure to enable it in your settings/local.settings file - $settings['rebuild_access'] = TRUE; Does this help you at all? I'm not sure how this differs from drush cr / manual cache rebuild in admin though. The docs state "Rebuilds all Drupal caches even when Drupal itself does not work." api.drupal.org/api/drupal/core%21rebuild.php/8.1.xuser2307706
hi @user2307706 , thanks for the comment but suprisingly I haven't had the problem again, didn't do anything special, but will have your solution as consideration if it happens again.VictorCL

1 Answers

0
votes
public function build() {
$renderable = [
  '#theme' => 'my_template',
  '#test_var' => 'test variable',
];

return $renderable;

}

try this