Hello,

From UUID project page:

An API is provided for other modules to enable support for custom entities.

And how should we do that exactly?

I am using Entity API to create custom entities, using model as example.

UUID works fine for custom node content types, it would be nice to have it for custom specialized entities also...

CommentFileSizeAuthor
#6 uuid-documentation-2236497-6.patch543 bytesRoSk0
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mxh’s picture

Hi,

actually this module lacks in terms of a good documentation.
I've developed several entity types by myself and needed UUID integration for them.
I managed to do this with 2 steps:

1. In hook_schema(), where the base table for the entity type is being defined, a column for the UUID is required. If it is an entity type from a third party / contributed module, you may need to run a hook_schema_alter() or update hook to add this column to the base table of the entity type. Example for hook_schema():

<?php
/**
 * Implements hook_schema().
 */
function mymodule_schema() {
  $schema['myentity'] = array(
    'fields' => array(
      'uuid' => array(
        'type' => 'char',
        'length' => 36,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The Universally Unique Identifier.',
      ),
      // ... more fields.
    ),
    // ... description, primary keys etc.
  );
  return $schema;
}
?>

2. Mark your entity type in hook_entity_info() that it shall have UUIDs. If it's an entity type from a third party / contributed module, you will need to add the required info by implementing hook_entity_info_alter(). Example for hook_entity_info():

<?php
/**
 * Implements hook_entity_info().
 */
function mymodule_entity_info() {
  return array(
    'myentity' => array(
      // ...
      'uuid' => TRUE,
      'entity keys' => array(
        // ...
        'uuid' => 'uuid', // Assuming 'uuid' is the name of the column storing corresponding UUID.
      ),
    ),
  );
}
?>
Talkless’s picture

Thanks max-haupt, although I do not need this any more, it will help others searching for solution!

Talkless’s picture

Status: Active » Closed (fixed)
RoSk0’s picture

Version: 7.x-1.0-alpha5 » 7.x-1.x-dev
Priority: Normal » Major
Status: Closed (fixed) » Needs work

Don't agree that this is fixed.
We need to put this documentation in some better place like Drupal.org documentation or DEVELOPERS.txt file in module. I'm ready to do either, but need to know what is preferred way from maintainers, to avoid extra work.

mxh’s picture

Title: How to add UUID support for custom entity types? » Documentation: How to integrate UUID with third party entities
Category: Support request » Task
Priority: Major » Normal

Agree with it that it's not yet fixed, because documentation is needed. But it's not really a repercussion ;)
I'm used to read official online documentations on drupal.org, since these ones are more detailed and structured than plain text files. Furthermore it may be read and extended / corrected easily by any other community member, which is another plus for the online doc.

RoSk0’s picture

Status: Needs work » Needs review
FileSize
543 bytes

Created documentation page - https://www.drupal.org/node/2387671, and a patch to put the link to this page in the README.txt.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

RTBC.

  • skwashd committed f3746fa on 7.x-1.x authored by RoSk0
    Issue #2236497 by RoSk0: Documentation: Add link to integration docs
    
skwashd’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the patch. I've committed it.

  • skwashd committed 1251856 on 7.x-1.x
    Issue #2300301 #2236497 by skwashd: Fix formatting
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.