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.

Chapter 6<br />

Most entity operations in <strong>Drupal</strong> assume multiple objects.<br />

Now that we have defined our entity and can load it, what can we do with it? Right<br />

now not much, since we have no way to create or edit entities. We still need to define<br />

the rest of the entity life cycle and expose a UI for it.<br />

Entity management<br />

In practice, different entity types will frequently need a different workflow for<br />

creating, editing, and deleting entities. Some may not even be editable through<br />

the UI. To keep things simple for now, though, we'll stick with the familiar node<br />

workflow and replicate that, more or less.<br />

Because there are several parts, we'll tackle them one at a time:<br />

1. Create an administrative workflow for managing artwork types.<br />

2. Create pages to add and edit artworks.<br />

3. Create a page to view artworks.<br />

4. Create a form for deleting artworks.<br />

Managing artwork types<br />

We'll start with a stub of an admin section for managing artwork types. Although<br />

we will not allow users to create new artwork types we still need to have at least a<br />

very minimal administrative section on which the Field system can hang its interface.<br />

We'll start with a fairly simple artwork_menu() hook:<br />

function artwork_menu() {<br />

$items['admin/structure/artworks'] = array(<br />

'title' => 'Manage artworks',<br />

'description' => 'Manage artworks.',<br />

'page callback' => 'artwork_overview_types',<br />

'access arguments' => array('administer artworks'),<br />

);<br />

$items['admin/structure/artworks/manage/%artwork_type'] = array(<br />

'title' => 'View artwork type',<br />

'title callback' => 'artwork_type_page_title',<br />

'title arguments' => array(4),<br />

'page callback' => 'artwork_information',<br />

'page arguments' => array(4),<br />

[ 163 ]

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

Saved successfully!

Ooh no, something went wrong!