12

The Entity API module extends the entity API defined in Drupal. In which cases should a module use the API provided from that module? Are modules that implement new entities easier to be written if they depend on the Entity API module?

By "easier to be written" I mean that modules using Entity API would require less code to be written compared to a module that doesn't use Entity API.

I read the project page, but I still don't completely understand the reason to prefer creating a module that depends on the Entity API module, rather than a module depending only from Drupal core code. I understand that a module extending rules and implementing an entity should use the Entity API module; in the first case, the reason is also that the Rules module depends on the Entity API module.

2
  • 1
    The project page you linked provides a fairly specific overview of what the module does. Do you have specific questions about why a module would depend on it other than what they lay out there?
    – jhedstrom
    Mar 31, 2011 at 4:19
  • If you don't use Entity API module, you end up writing a module like this sandbox project. Note that this sandbox project has no tests and only one contributor, whereas Entity API has many of both.
    – paul-m
    Jan 25, 2012 at 2:44

3 Answers 3

15

Not complete, but here are some advantages that I know of:

  • Drupal core only provides an EntityController for loading entities. For save, update and delete, you either need to write it yourself or use Entity API.
  • You you can expose the base properties of your entities wit hook_entity_property_info(), see privatemsg_entity_property_info() for an example. The advantage of this is that rules.module knows your entity properties and you read and write them with rules. And you also get token integration for free.
  • It can also automatically provide you with an administrative UI for your entities
3
  • What do you mean by an admin ui? Some of this is handled by core.
    – googletorp
    Apr 1, 2011 at 0:06
  • 2
    Core provides an UI to configure fields and attach them to entities, entity API provides an UI to create and manage entities for custom entities, core does nothing like that.
    – Berdir
    Apr 1, 2011 at 9:02
  • 1
    not to forget the great metadata_wrapper drupalcontrib.org/api/drupal/… that allows you to easily access the field's values in code
    – mojzis
    May 8, 2012 at 22:11
7

Automatic Views integration, admin UI, exportable entities (all of this is optional). Plus a lot of syntax sugar things that didn't make it into D7 and you need them (generic entity_save(), entity_create(), putting your custom logic in "entity classes"...)

Plus, modules (efq_views, rules) do really cool things with properties.

-1

i do believe, the entity api (module) was basically removed from drupal 7 core prior to release because it was considered incomplete.. Only the basic entity api CRUD functions where left in drupal core for its GM release .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.