View source
<?php
class CaseTrackerCaseUIController extends EntityDefaultUIController {
public function hook_menu() {
$items = array();
$wildcard = isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%' . $this->entityType;
$case_path = 'project/%/case';
$items[$case_path . '/add'] = array(
'title' => t('Add a case'),
'description' => t('Add a new case'),
'page callback' => 'casetracker_case_add_page',
'access callback' => 'casetracker_case_access',
'access arguments' => array(
'edit',
),
'type' => MENU_NORMAL_ITEM,
'weight' => 20,
'file' => 'casetracker_case.inc',
'file path' => drupal_get_path('module', $this->entityInfo['module']),
);
foreach (casetracker_case_get_types() as $type) {
$items[$case_path . '/add/' . $type->type] = array(
'title' => t('Add @bundle', array(
'@bundle' => $type->label,
)),
'page callback' => 'casetracker_case_form_wrapper',
'page arguments' => array(
casetracker_case_create(array(
'type' => $type->type,
)),
),
'access callback' => 'casetracker_case_access',
'access arguments' => array(
'edit',
'edit ' . $type->type,
),
'file' => 'casetracker_case.inc',
'file path' => drupal_get_path('module', $this->entityInfo['module']),
);
}
$items[$case_path . '/' . $wildcard . '/edit'] = array(
'title' => t('Edit'),
'page callback' => 'casetracker_case_form_wrapper',
'page arguments' => array(
3,
),
'access callback' => 'casetracker_case_access',
'access arguments' => array(
'edit',
3,
),
'type' => MENU_LOCAL_TASK,
'weight' => 0,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
);
$items[$case_path . '/' . $wildcard . '/delete'] = array(
'title' => t('Delete'),
'page callback' => 'casetracker_case_delete_form_wrapper',
'page arguments' => array(
3,
),
'access callback' => 'casetracker_case_access',
'access arguments' => array(
'edit',
3,
),
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_INLINE,
'weight' => 10,
'file' => 'casetracker_case.inc',
'file path' => drupal_get_path('module', $this->entityInfo['module']),
);
$items[$case_path . '/' . $wildcard] = array(
'page callback' => 'casetracker_case_page_view',
'page arguments' => array(
3,
),
'access callback' => 'casetracker_case_access',
'access arguments' => array(
'view',
3,
),
);
$items[$case_path . '/' . $wildcard . '/view'] = array(
'title' => t('View'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
return $items;
}
public function addPage() {
$item = menu_get_item();
$content = system_admin_menu_block($item);
if (count($content) == 0) {
drupal_set_message(t('There isn\'t any Case Type configured. To setup now, go to the <a href="@link">@link_text</a>.', array(
'@link' => base_path() . 'admin/structure/casetracker/case-types',
'@link_text' => 'administrative page',
)), 'error');
}
elseif (count($content) == 1) {
$item = array_shift($content);
$project_ref = arg(5);
if (is_numeric($project_ref)) {
drupal_goto($item['href'] . '/' . $project_ref);
}
else {
drupal_goto($item['href']);
}
}
return theme('casetracker_case_add_list', array(
'content' => $content,
));
}
}