Providing metadata for additional entity types

Last updated on
14 October 2016

In case your module is providing an additional entity type, but is not making use of the Entity CRUD API (as described previously) some additional work is necessary to obtain support by the entity API:

Use hook_entity_info() to annotate how your entity is created/updated/deleted and to specify access. That way the associated API functions like entity_save() work for your entity type too.

 * Implements hook_entity_info_alter().
function entity_entity_info_alter(&$entity_info) {
  // Set access callbacks.
  $entity_info['user']['access callback'] = 'entity_metadata_user_access';

  // CRUD function callbacks.
  $entity_info['user']['creation callback'] = 'entity_metadata_create_object';
  $entity_info['user']['save callback'] = 'entity_metadata_user_save';
  $entity_info['user']['deletion callback'] = 'user_delete';

You can find the doxygen docs for this callbacks at entity_hook_entity_info().