Posts tagged: drupal

Drupal Entities – PHP Class per bundle

If you would like a bit more polymorphism in your drupal entities, this might cheer you up 😀

I was looking for a way to have a class hierarchy that matched the bundle “hierarchy” of entities in drupal. Yes, they are all “subclasses” of ONE parent, but it is still useful to be able to have a class per bundle.

The entity bundle plugin does a good job of providing a plugin framework to instantiate classes per bundle type. There is also an example of how to use this. However, this was a bit of overkill for me. I did however borrow the idea (and some code) to implement it in a simpler fashion.

Read more »

hook_theme doesn’t get called

I was developing a new module in drupal and it needed a theme function to be implemented.

As per the instructions, it was implemented as follows (to use a template)

/**
 * Implementation of hook_theme().
 */
function my_module_results_theme($existing, $type, $theme, $path) {
 
	return array(
    	'my_block' => array(
    		'template' => 'my_block',
	 		'arguments' => array(
				'var1' => NULL
			)
		)
	);
}

However, when trying to apply the theme, it didn’t work. I tried various things and identified that the hook above was just not being called. A little bit of digging helped me discover that themes are cached. This happens even in the dev mode. To resolve this, go to

Administer  -> Performance -> Clear Cached Data (right at the bottom of the page)

and et voila my theme was now being utilised.

WordPress Themes