13

What are Drupal Entities in Drupal 7? I understand that Drupal Commerce built Products as an Entity. I know now there is a core Entity API and an contrib add on for Entity API.

I have a few projects this year where I would like to use Drupal 7, NoSQL and possibly the Entity API if it calls for it- but I am having trouble seeing where it would be needed.

Assuming you were building a job listing site- a job isn't necessarily like node content, could/would you make that an Entity?

Additionally, can you still get the ability to talk to modules with the Entity and how is that done? Like, a Job Posting entity getting aliased with Pathauto and exposed in Views as well as appear in XML Sitemap.

5 Answers 5

9

A entity is data structure defined by hook_entity_info() and can be fieldable, which means that you can add fields to them.

In Drupal 7 Core, Nodes, Users, Comments, Vocabularies and Terms are entities.

In Contrib, there are many more, for example private messages and commerce as like a dozen of them ;)

However, I think job postings are perfectly fine as nodes :) Entities don't automatically have Pathauto (Tokens), Views etc. integration.

9

Entities are a meta level above nodes, users, etc.

Essentially if you look at D6, there are a lot of duplicate modules, and functionality across these types of thing. For example there are modules to attach cck fields to users and to taxonomy terms.

In D7 a decision was made to treat these in the same way, architecturally, so if you have a module which does something to entities, it should work for nodes, terms and users.

In previous versions of Drupal, a module like Commerce would have had two options, to build a custom node type, or to go completely outside of Drupal's internal systems and define their own type of thing. With entities, it is possible to describe a Product as a type of thing, distinct from existing types, but still leverage features like fields in their makeup.

Assuming you were building a job listing site- a job isn't necessarily like node content, could/would you make that an Entity?

You could. I think you should be careful of making entities of things too quickly. Often custom node types will still do what you want. Is a job listing a different type of thing to a node, or is it a node with some special properties?

3

I've started using entities in a few of my projects for things that weren't really "content". We use them for things where we don't really care when it was published or who the author was.

The real benefits of defining entities are if you're developing your own custom modules. You get a nice table structure and a bunch of Drupal goodness (Fieldability, Views integration, ...) for free. No more creating your own custom table structures or retrofitting a node type to your needs. Also, I like how lightweight they are so performance-wise entities should be better. If you've done any queries in D6 with nodes you'll understand what I mean.

1

Nodes, users, taxonomies are examples of Drupal entities. The main feature of an entity is that it can be assigned to other entities: a user is associated with a node, and a taxonomy can be assigned to nodes, and users.

If what you describe as job can be assigned to a user, or a node, then I would make it an entity. If what you can "job" is just a content type, then I would not make it an entity.

1

If you want to say that in a really few word, you can say that en entity is just a piece of data that drupal is aware of, and it can be store anywhere.

Your Answer

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

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