1

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.

VictorCL
  • 49
  • 1
  • 4
  • 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." https://api.drupal.org/api/drupal/core%21rebuild.php/8.1.x – user2307706 Feb 24 '18 at 16:43
  • 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 Feb 27 '18 at 19:25

1 Answers1

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

return $renderable;

}

try this