Learn Drupal 13h: hook_entity_property_info_alter
This screencast is a part of the epic learning series "Four weeks of Drupal", chapter "Writing a module". You can view the full series at dev.nodeone.se/en/four-weeks-of-drupal.
Please post any comments over there, or we won't see them. Sorry.
---
This screencast shows how you can add information (properties) to the entities known by the Entity API module; in this case by adding the word list to the globally available "site" entity (which is not *really* an entity). This is done by implementing a hook: hook_entity_property_info_alter.
There is also some general information about alter hooks in Drupal.
(I accidentally removed the wordlist_get_list() function at the end of the screencast. This is restored in the next screencast. Sorry.)
code added to wordlist.module
/**
* Fetches the list of words as defined by Word list module.
* @return
* An array of words, not sanitized.
*/
function wordlist_get_list() {
return variable_get('wordlist_words', array());
}
/**
* Implements hook_entity_property_info_alter().
*/
function wordlist_entity_property_info_alter(&$info) {
$info['site']['properties']['wordlist_words'] = array(
'label' => t('Word list'),
'description' => t('A list of words, as defined by the Word list module.'),
'getter callback' => 'wordlist_get_list',
'sanitize' => 'check_plain',
'type' => 'list',
);
}
---
This screencast is a part of the epic learning series "Four weeks of Drupal", chapter "Writing a module". You can view the full series at dev.nodeone.se/en/four-weeks-of-drupal.
Please post any comments over there, or we won't see them. Sorry.
0 comments
Be the first to comment on this!