How to integrate UUID with third party entities
Last updated on
10 November 2016
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
When developing custom entity type and you need to integrate it with UUID module you need to do the following:
- Mark your entity type in hook_entity_info() that it shall have UUIDs:
/** * Implements hook_entity_info(). */ function mymodule_entity_info() { return array( 'myentity' => array( 'base table' => 'myentity', 'revision table' => 'myentity_revision', // ... 'uuid' => TRUE, 'entity keys' => array( // Value here('uuid' after the '=>' sign) is the name of the column that will be used to store corresponding UUID in the database. 'uuid' => 'uuid', // In case you creating revisionable entity type you should also put this line. 'revision uuid' => 'vuuid', ), ), ); } -
In your hook_schema definition you need to put the following:
if (module_exists('uuid')) { $field = uuid_schema_field_definition(); $schema['myentity']['fields']['uuid'] = $field; $schema['myentity']['indexes']['uuid'] = array('uuid'); // This is needed only for revisionable entities. $schema['myentity_revision']['fields']['vuuid'] = $field; $schema['myentity_revision']['indexes']['vuuid'] = array('vuuid'); }
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion