Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The project page for this module states:
“An API is provided for other modules to enable support for custom entities.”
But I have not been able to find any documentation for said API. Can you point me in the right direction?
Comments
Comment #1
ruplAnother end-user here. I have been attempting to use the UUID module's own implementations for core entities along with the uuid.api.php file. Haven't had much luck but I would absolutely contribute docs if I sort it out.
* http://cgit.drupalcode.org/uuid/tree/uuid.inc
* http://cgit.drupalcode.org/uuid/tree/uuid.entity.inc
* http://cgit.drupalcode.org/uuid/tree/uuid.core.inc
* http://cgit.drupalcode.org/uuid/tree/uuid.api.php
I see lots of explanations for the mechanics of various functions, but the comments unfortunately don't tell an unfamiliar user why each function is needed, or the order in which they need to be set up. My blanket approach of just copying all functions that begin with
node_entity_uuid_XXX
and attempting to customize them didn't get me any results yet.Comment #2
ruplAdditionally, the API file refers to functions that I can't seem to find. The only occurrence is the reference itself:
Comment #3
ruplOk, after a brutal journey of self-discovery and research, I have come back and learned a few things. Here's a list of functions that I implemented. They come from the files I listed above in comment #1:
my_module_uuid_info()
— defines your UUID generator. Basically takes a label and a callback, so that you can customize UUID generation._my_module_generate_uuid()
— the custom callback (if any) for yourhook_uuid_info()
implementation. You could use the UUID module'suuid_generate()
function here. Or you could supply additional logic as necessary using a custom callback.my_module_get_uuid_entity_info_alter()
— NOT YET EXISTING alterhook to specify the schema which needs to be altered during installation/update. See comment #4 for alter hook details.my_module_schema_alter()
— I manually copied this function fromuuid_schema_alter()
and made some minor adjustments to point toward the previous function regarding the schema alterations.my_module_uninstall()
— make module clean up after itself on uninstall. straight copy from uuid.install but I changed the loop to use myentity_info()
implementation.I'm still not 100% sure if I need these or if theuuid.entity.inc
file does some of this for me (there are functions that claim to do this for all UUID-enabled entities), but I'm including them nonetheless as possible requirements for implementation:my_module_entity_uuid_load()
— copy pasta fromuuid.core.inc
with minor modifications to match my table's schema.my_module_entity_uuid_presave()
— another copy pasta fromuuid.core.inc
with minor modifications to match my table's schema.Comment #4
ruplAdditionally, I created a new alter hook because I could not figure out how else to invoke the schema_alter(). We need direction from maintainers on how to avoid this hack, or perhaps I need to turn this into a legit patch for the module.
After all that was in place, I removed the following functions (everything UUID-related in the
.install
file) which are now taken care of by the UUID module's (hacked, for now) functions:my_module_schema_alter()
my_module_uninstall()
Comment #5
das-peter CreditAttribution: das-peter commentedWell, the latest dev version should provide: uuid_features/uuid_features.api.php
This is at least a small documentation.
Comment #6
ruplThis is a UUID issue, not a UUID Features issue. Thanks for the heads-up on the Features side of things, though! I will probably be in your queue tomorrow with a similar brain-dump ;)
Comment #7
candelas CreditAttribution: candelas commented@rupl thanks for documenting :)
Comment #8
MustangGB CreditAttribution: MustangGB commentedThis is all I've added to my custom entity to get uuid working. I am using Entity API, but I believe it should also work without it and rely instead on core entity and "UUID implementation of Entity API" built-in to uuid. I also have a dependancy on uuid.
sample.install
sample.module
P.S. "sample_uuid" could just be called "uuid" or anything else you wish.
Comment #9
candelas CreditAttribution: candelas commentedThanks very much @MustangGB
Comment #10
gumanoed CreditAttribution: gumanoed commentedIs any result with features_uuid and custom entities types export to feature code?
I would be very appriciate to get any information!
Comment #11
gnucifer CreditAttribution: gnucifer commentedI did now know work was being done on this in the uuid module. I have gotten uuid-entities export working decently in this module: https://github.com/gnucifer/uuid_entity_features
Perhaps functionality can be merged, I will have a look.
Comment #12
skwashd CreditAttribution: skwashd at Dave Hall Consulting for Dave Hall Consulting commentedThis was completed under #2236497: Documentation: How to integrate UUID with third party entities. If you have additional contributions, please add them to the existing documentation. Closing.