18.10.2016 Views

Drupal 7 Module Development

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Working with Content<br />

<strong>Drupal</strong> 7 introduces major changes to the way <strong>Drupal</strong> handles content. In earlier<br />

versions, nearly all content was considered a "node". By making content a standard<br />

object with a common API, any module could add data to and manipulate that object<br />

to create complex data models and workflows.<br />

That worked extremely well, with the exception that <strong>Drupal</strong> had several other types<br />

of objects, such as users or comments, that were not really "content" per se but could<br />

still have benefited from the same rich API. For <strong>Drupal</strong> 7, therefore, most of those<br />

separate object types were merged into a single super-system known as "entities".<br />

Nodes, users, comments, and several other types of data objects are now particular<br />

instances of the generic Entity data object concept. That allows all types of data to<br />

have the same, or at least very similar, API and workflow, avoiding duplicate code<br />

and reducing the number of moving parts developers need to keep track of. Most<br />

importantly, it allows us to attach Fields, discrete structured pieces of information,<br />

to any type of entity rather than just to nodes.<br />

In this chapter, we'll look at how to define new entity types. There are a lot of<br />

moving parts, and while the entity system automates much of the process for us it<br />

does not automate everything. Along the way we'll touch on several new pieces of<br />

<strong>Drupal</strong> and reiterate what we've covered in previous chapters about page callbacks<br />

and form handling.<br />

Why create your own entities<br />

It's generally not necessary to create a new entity type. Nodes are still extremely<br />

flexible, and more often than not can handle whatever use case we need. However,<br />

there are cases where it is necessary to create separate entities rather than separate<br />

node types, like for instance:<br />

• We may need entities that have entirely different permission handling or<br />

workflow than nodes, such as products in an e-commerce system.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!