18.10.2016 Views

Drupal 7 Module Development

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Working with Content<br />

Summary<br />

This has been quite a chapter. Not only have we learned how to create our own<br />

entities in <strong>Drupal</strong>, we have expanded our knowledge of many of <strong>Drupal</strong>'s<br />

key systems.<br />

• We've seen how to define new entities and encapsulate their loading and<br />

saving routines into a controller class.<br />

• We've seen how to integrate our entity with the Field API, providing<br />

site administrators with enormous flexibility and power to build custom<br />

data models.<br />

• We've learned how to define new tables in <strong>Drupal</strong>'s database in a<br />

database-agnostic fashion.<br />

• We've learned about database transactions, a simple way to ensure that<br />

a complex database operation succeeds completely or fails completely<br />

to avoid data corruption.<br />

• We've learned about how to avoid stale data issues when using<br />

master/slave replication.<br />

• We've seen how to display confirmation forms to users to ensure they didn't<br />

click a button by accident.<br />

• We've learned how to have dynamically named forms which are built using<br />

the same process.<br />

• We've seen how to leverage <strong>Drupal</strong>'s autoloading capability for classes<br />

to help keep code size down.<br />

As noted at the start of the chapter, in many cases a custom entity will not need the<br />

full life cycle of creation, editing, and deletion. Some may not even interact with<br />

<strong>Drupal</strong>'s local database at all, relying on a load() method that calls out to a ReST<br />

service or SOAP server. We may need to define a complex set of permission controls<br />

for our custom entity, or in some cases there may not even be a way for users to view<br />

an entity directly.<br />

By looking at a complete example, however, we have got a feel for most of the pieces<br />

we could implement if we needed to. Since our artwork example closely parallels the<br />

node entity type, although in a simplified form, it helps to provide a context for how<br />

the all-important node system works in <strong>Drupal</strong>.<br />

[ 182 ]

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

Saved successfully!

Ooh no, something went wrong!