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 />

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

);<br />

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

array(<br />

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

'type' => MENU_DEFAULT_LOCAL_TASK,<br />

);<br />

}<br />

return $items;<br />

Once again, while <strong>Drupal</strong>'s big arrays look like a lot of code it is all fairly<br />

straightforward. The first item sets up our artwork type landing page at admin/<br />

structure/artworks (which deliberately parallels the admin/structure/content<br />

path for managing nodes). The second sets up a callback for viewing and editing<br />

each artwork type (bundle), although we won't do anything with it except show<br />

some static information. The third menu item creates a menu tab (or in <strong>Drupal</strong><br />

parlance, "local task") called View, that is the default and will pass-through to the<br />

parent artwork-type-manage page.<br />

The tab definition is important. Recall from the last section that our<br />

artwork_entity_info() function told the Field UI system that it should add its<br />

own administrative pages at admin/structure/artworks/manage/%artwork_type.<br />

When the Field UI module is enabled, therefore, it will add additional pages as<br />

tabs next to our View tab. If we don't declare our page as a tab, it will get lost when<br />

someone views the Field UI pages.<br />

There are a few new functions we need here to support these pages, all of them<br />

very short.<br />

function artwork_overview_types() {<br />

foreach (artwork_types() as $type => $info) {<br />

$type_url_str = str_replace('_', '-', $type);<br />

$label = t('View @type', array('@type' => $info->name));<br />

$items[] = l($label, 'admin/structure/artworks/manage/' .<br />

$type_url_str);<br />

}<br />

return theme('item_list', array('items' => $items));<br />

}<br />

[ 164 ]

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

Saved successfully!

Ooh no, something went wrong!