View source
<?php
class PartyActivityUIController extends EntityDefaultUIController {
public function hook_menu() {
$items = array();
$id_count = count(explode('/', $this->path));
$wildcard = isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%' . $this->entityType;
$items[$this->path] = array(
'title' => 'Activities',
'description' => 'Add edit and update activities.',
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array(
'access administration pages',
),
'file path' => drupal_get_path('module', 'system'),
'file' => 'system.admin.inc',
);
$items[$this->path]['type'] = MENU_LOCAL_TASK;
$items[$this->path . '/add'] = array(
'title' => 'Add an activity',
'description' => 'Add a new activity',
'page callback' => 'party_activity_add_page',
'access callback' => 'party_activity_access',
'access arguments' => array(
'edit',
),
'type' => MENU_NORMAL_ITEM,
'weight' => 20,
'file' => 'party_activity.admin.inc',
'file path' => drupal_get_path('module', $this->entityInfo['module']),
);
foreach (party_activity_get_types() as $type) {
$items[$this->path . '/add/' . $type->type] = array(
'title' => 'Add ' . $type->label,
'page callback' => 'party_activity_form_wrapper',
'page arguments' => array(
party_activity_create(array(
'type' => $type->type,
)),
),
'access callback' => 'party_activity_access',
'access arguments' => array(
'edit',
'edit ' . $type->type,
),
'file' => 'party_activity.admin.inc',
'file path' => drupal_get_path('module', $this->entityInfo['module']),
);
}
$items[$this->path . '/activity/' . $wildcard] = array(
'title callback' => 'party_activity_page_title',
'title arguments' => array(
$id_count + 1,
'edit',
),
'page callback' => 'party_activity_form_wrapper',
'page arguments' => array(
$id_count + 1,
),
'access callback' => 'party_activity_access',
'access arguments' => array(
'edit',
$id_count + 1,
),
'weight' => 0,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'file' => 'party_activity.admin.inc',
'file path' => drupal_get_path('module', $this->entityInfo['module']),
);
$items[$this->path . '/activity/' . $wildcard . '/edit'] = array(
'title' => 'Edit',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
);
$items[$this->path . '/activity/' . $wildcard . '/delete'] = array(
'title' => 'Delete',
'page callback' => 'party_activity_delete_form_wrapper',
'page arguments' => array(
$id_count + 1,
),
'access callback' => 'party_activity_access',
'access arguments' => array(
'edit',
$id_count + 1,
),
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_INLINE,
'weight' => 10,
'file' => 'party_activity.admin.inc',
'file path' => drupal_get_path('module', $this->entityInfo['module']),
);
$items['activity/' . $wildcard] = array(
'title callback' => 'party_activity_page_title',
'title arguments' => array(
1,
),
'page callback' => 'party_activity_page_view',
'page arguments' => array(
1,
),
'access callback' => 'party_activity_access',
'access arguments' => array(
'view',
1,
),
'type' => MENU_CALLBACK,
);
return $items;
}
public function addPage() {
$item = menu_get_item();
$content = system_admin_menu_block($item);
if (count($content) == 1) {
$item = array_shift($content);
drupal_goto($item['href']);
}
return theme('party_activity_add_list', array(
'content' => $content,
));
}
}
function party_activity_form_wrapper($activity) {
party_activity_set_breadcrumb();
if (!empty($activity->is_new) && $activity->is_new) {
$assignee = !empty($_GET['assignee']) ? $_GET['assignee'] : NULL;
$participants = !empty($_GET['participants']) ? explode(',', $_GET['participants']) : array();
if (!empty($assignee)) {
$activity->activity_assigned_to['und'][]['target_id'] = $assignee;
}
foreach ($participants as $participant_id) {
$activity->activity_participants['und'][]['target_id'] = $participant_id;
}
}
return drupal_get_form('party_activity_edit_form', $activity);
}
function party_activity_delete_form_wrapper($activity) {
return drupal_get_form('party_activity_delete_form', $activity);
}
function party_activity_edit_form($form, &$form_state, $activity) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => isset($activity->title) ? $activity->title : '',
'#maxlength' => 255,
'#required' => TRUE,
'#weight' => -5,
);
$form_state['party_activity'] = $activity;
field_attach_form('party_activity', $activity, $form, $form_state);
$form['actions'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'form-actions',
),
),
'#weight' => 400,
);
$submit = array();
if (!empty($form['#submit'])) {
$submit += $form['#submit'];
}
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#submit' => $submit + array(
'party_activity_edit_form_submit',
),
);
if (!empty($activity->party_activity_id)) {
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#suffix' => l(t('Cancel'), 'admin/community/activities'),
'#submit' => $submit + array(
'party_activity_form_submit_delete',
),
'#weight' => 45,
);
}
$form['#validate'][] = 'party_activity_edit_form_validate';
return $form;
}
function party_activity_edit_form_validate(&$form, &$form_state) {
$activity = $form_state['party_activity'];
field_attach_form_validate('party_activity', $activity, $form, $form_state);
}
function party_activity_edit_form_submit(&$form, &$form_state) {
$activity = entity_ui_controller('party_activity')
->entityFormSubmitBuildEntity($form, $form_state);
if ($activity->is_new = isset($activity->is_new) ? $activity->is_new : 0) {
$activity->created = time();
}
$activity->modified = time();
$activity
->save();
$form_state['redirect'] = 'admin/community/activities';
}
function party_activity_form_submit_delete(&$form, &$form_state) {
$form_state['redirect'] = 'admin/community/activitiess/activity/' . $form_state['activity']->party_activity_id . '/delete';
}
function party_activity_delete_form($form, &$form_state, $activity) {
$form_state['activity'] = $activity;
$form['#submit'][] = 'party_activity_delete_form_submit';
$form = confirm_form($form, t('Are you sure you want to delete activity %title?', array(
'%title' => $activity->title,
)), 'admin/community/activities/activity', '<p>' . t('This action cannot be undone.') . '</p>', t('Delete'), t('Cancel'), 'confirm');
return $form;
}
function party_activity_delete_form_submit($form, &$form_state) {
$activity = $form_state['activity'];
party_activity_delete($activity);
drupal_set_message(t('The activity %title has been deleted.', array(
'%title' => $activity->title,
)));
watchdog('activity', 'Deleted activity %title.', array(
'%title' => $activity->title,
));
$form_state['redirect'] = 'admin/community/activities';
}
function party_activity_add_page() {
$controller = entity_ui_controller('party_activity');
return $controller
->addPage();
}
function theme_party_activity_add_list($variables) {
$content = $variables['content'];
$output = '';
if ($content) {
$output = '<dl class="party-activity-type-list">';
foreach ($content as $item) {
$output .= '<dt>' . l($item['title'], $item['href']) . '</dt>';
$output .= '<dd>' . filter_xss_admin($item['description']) . '</dd>';
}
$output .= '</dl>';
}
else {
if (user_access('administer party activity types')) {
$output = '<p>' . t('Party Activity Entities cannot be added because you have not created any party activity types yet. Go to the <a href="@create-activity-type">activity type creation page</a> to add a new activity type.', array(
'@create-activity-type' => url('admin/structure/party_activity_types/add'),
)) . '</p>';
}
else {
$output = '<p>' . t('No activity types have been created yet for you to use.') . '</p>';
}
}
return $output;
}
function party_activity_set_breadcrumb() {
$breadcrumb = array(
l(t('Home'), '<front>'),
l(t('Administration'), 'admin'),
l(t('Community'), 'admin/community'),
l(t('Activities'), 'admin/community/activities'),
);
drupal_set_breadcrumb($breadcrumb);
}