-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add support for a custom entity? #47
Comments
You can use entity_load(), entity_save() and entity_delete() with jDrupal and it should do most of it for you. For any custom entity, you do need to tell jDrupal about the primary key though. For example, to support Commerce Orders, I needed to add this function:
That should be it. Then I typically make a wrapper function, for example:
Then callers can more easily use it:
I'll also make wrappers for save/delete following the same guidelines. |
Thanks. I have tried this, but I get an error when loading an entity:
Do I have to add my custom entity to |
@luxio It looks like we'll need some type of hook to allow people to declare an entity type: https://github.com/easystreet3/jDrupal/blob/7.x-1.x/src/entity.js#L547 Right now it's hard coded in for core entity types. I'd love it if it was dynamic and automatically knew what was on the Drupal site. Thoughts? |
What about just redefining // redefine entity_types()
var core_enity_types = entity_types;
entity_types = function() {
return core_entity_types().concat('my_entity_type');
}
// load wrapper.
function my_entity_type_load(order_id, options) {
entity_load('my_entity_type', my_entity_id, options);
} |
@kentr excellent, very clever. That'll work. |
Cleaner version, based on this example // Decorate entity_types().
entity_types = (function() {
var core_types = entity_types;
return function() {
return core_types.apply(this, arguments).concat('my_entity_type');
}
})();
// load() wrapper.
function my_entity_type_load(order_id, options) {
entity_load('my_entity_type', my_entity_id, options);
} |
FYI, jDrupal can now utilize Services Entity to support all entity types (core and custom): #60 |
Is there a way (hooks) to add support for a custom entity type in jDurpal?
The text was updated successfully, but these errors were encountered: