View source
<?php
function merci_reservation_menu_local_tasks_alter(&$data, $router_item, $root_path) {
if ($root_path == 'merci/reservations') {
$item = menu_get_item('merci_reservation/add');
if ($item['access']) {
$data['actions']['output'][] = array(
'#theme' => 'menu_local_action',
'#link' => $item,
);
}
}
}
function merci_reservation_add_page($entity_type) {
$merci_reservation_types = merci_reservation_types();
if (count($merci_reservation_types) == 1) {
$info = entity_get_info($entity_type);
$type = reset($merci_reservation_types);
drupal_goto($info['admin ui']['path'] . '/add/' . $type->type);
}
return entity_ui_bundle_add_page($entity_type);
}
function merci_reservation_get_action_title($op, $entity_type, $bundle_name = NULL) {
$info = entity_get_info($entity_type);
$merci_reservation_types = merci_reservation_types();
if (count($merci_reservation_types) == 1) {
$info = entity_get_info($entity_type);
$type = reset($merci_reservation_types);
$bundle_name = isset($bundle_name) ? $bundle_name : $type->type;
switch ($op) {
case 'add':
if (isset($bundle_name) && $bundle_name != $entity_type) {
return t('Add @bundle_name', array(
'@bundle_name' => drupal_strtolower($info['bundles'][$bundle_name]['label']),
));
}
else {
return t('Add @entity_type', array(
'@entity_type' => drupal_strtolower($info['label']),
));
}
case 'import':
return t('Import @entity_type', array(
'@entity_type' => drupal_strtolower($info['label']),
));
}
}
return entity_ui_get_action_title($op, $entity_type, $bundle_name);
}
function merci_reservation_menu_alter(&$items) {
$items['admin/commerce/customer-profiles/%commerce_customer_profile/edit'] = array(
'title' => 'Edit',
'page callback' => 'commerce_customer_ui_customer_profile_form_wrapper',
'page arguments' => array(
3,
),
'access callback' => 'commerce_customer_profile_access',
'access arguments' => array(
'update',
3,
),
'weight' => 0,
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'file' => drupal_get_path('module', 'commerce_customer_ui') . '/includes/commerce_customer_ui.profiles.inc',
);
$items['admin/commerce/customer-profiles/%commerce_customer_profile']['page callback'] = 'merci_reservation_customer_profile_form_wrapper';
$items['admin/commerce/customer-profiles/%commerce_customer_profile/view'] = array(
'title' => 'View',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
);
}
function merci_reservation_customer_profile_form_wrapper($profile) {
$entities = array(
$profile,
);
return entity_view('commerce_customer_profile', $entities);
}
function merci_reservation_rules_event_info() {
$defaults = array(
'group' => t('MERCI'),
'module' => 'merci_core',
);
return array(
'merci_reservation_validate' => $defaults + array(
'label' => t('When validating a new MERCI reservation'),
'variables' => array(
'reservation' => array(
'type' => 'entity',
'label' => t('Reservation entity'),
),
'errors' => array(
'type' => 'struct',
'label' => t('errors'),
),
),
),
);
}
function merci_reservation_type_redirect($type) {
drupal_goto('admin/merci/merci_line_item/add/' . $type);
}
function merci_reservation_entity_info() {
$entities['merci_reservation'] = array(
'label' => t('Merci reservation'),
'plural label' => t('Merci reservations'),
'base table' => 'merci_reservation',
'fieldable' => TRUE,
'entity class' => 'MerciReservation',
'controller class' => 'MerciReservationController',
'access callback' => 'merci_reservation_access',
'label callback' => 'entity_class_label',
'uri callback' => 'entity_class_uri',
'module' => 'merci_reservation',
'load hook' => 'merci_reservation_load',
'entity keys' => array(
'id' => 'id',
'bundle' => 'type',
),
'bundle keys' => array(
'bundle' => 'type',
),
'admin ui' => array(
'path' => 'merci_reservation',
'file' => 'merci_reservation.pages.inc',
'controller class' => 'ReservationUIController',
),
'bundles' => array(),
'view modes' => array(
'display' => array(
'label' => t('Display'),
'custom settings' => FALSE,
),
),
);
$entities['merci_reservation_type'] = array(
'label' => t('Merci Reservation Type'),
'entity class' => 'MerciReservationType',
'controller class' => 'MerciReservationTypeController',
'base table' => 'merci_reservation_type',
'fieldable' => FALSE,
'bundle of' => 'merci_reservation',
'exportable' => TRUE,
'entity keys' => array(
'id' => 'id',
'name' => 'type',
'label' => 'label',
),
'access callback' => 'merci_reservation_type_access',
'module' => 'merci_reservation',
'admin ui' => array(
'path' => 'admin/merci/merci-reservation-types',
'file' => 'merci_reservation.admin.inc',
'controller class' => 'ReservationTypeUIController',
'menu_wildcard' => '%merci_reservation_type',
),
);
return $entities;
}
function merci_reservation_entity_info_alter(&$entity_info) {
foreach (merci_reservation_types() as $type => $info) {
$entity_info['merci_reservation']['bundles'][$type] = array(
'label' => $info->label,
'admin' => array(
'path' => 'admin/merci/merci-reservation-types/manage/%merci_reservation_type',
'real path' => 'admin/merci/merci-reservation-types/manage/' . $type,
'bundle argument' => 4,
'access arguments' => array(
'administer merci_reservation types',
),
),
);
}
}
function merci_reservation_entity_property_info() {
$info = array();
$properties =& $info['merci_reservation']['properties'];
$properties['id'] = array(
'label' => t('Merci Reservation ID'),
'description' => t('The internal numeric ID of the merci reservation.'),
'type' => 'integer',
'schema field' => 'id',
);
$properties['type'] = array(
'label' => t('Type'),
'description' => t('The human readable name of the merci reservation type.'),
'type' => 'token',
'setter callback' => 'entity_property_verbatim_set',
'options list' => 'merci_reservation_type_options_list',
'required' => TRUE,
'schema field' => 'type',
);
$properties['created'] = array(
'label' => t('Date created'),
'description' => t('The date the merci reservation was created.'),
'type' => 'date',
'setter callback' => 'entity_metadata_verbatim_set',
'setter permission' => 'create merci reservation',
'schema field' => 'created',
);
$properties['changed'] = array(
'label' => t('Date changed'),
'description' => t('The date the merci reservation was most recently updated.'),
'type' => 'date',
'schema field' => 'changed',
);
$properties['owner'] = array(
'label' => t('Owner'),
'description' => t('The owner of the reservation.'),
'type' => 'user',
'schema field' => 'uid',
);
return $info;
}
function merci_reservation_type_options_list() {
return merci_reservation_type_get_name();
}
function merci_reservation_type_get_name($type = NULL) {
$merci_reservation_types = merci_reservation_types();
if (!empty($type)) {
if (isset($merci_reservation_types[$type])) {
return $merci_reservation_types[$type]->label;
}
else {
return FALSE;
}
}
$merci_reservation_type_names = array();
foreach ((array) $merci_reservation_types as $key => $value) {
$merci_reservation_type_names[$key] = $value->label;
}
return $merci_reservation_type_names;
}
function merci_reservation_type_load($type) {
return merci_reservation_types($type);
}
function merci_reservation_types($type_name = NULL) {
$types = entity_load_multiple_by_name('merci_reservation_type', isset($type_name) ? array(
$type_name,
) : FALSE);
return isset($type_name) ? reset($types) : $types;
}
function merci_reservation_load($line_item_id) {
$line_items = merci_reservation_load_multiple(array(
$line_item_id,
), array());
return $line_items ? reset($line_items) : FALSE;
}
function merci_reservation_load_multiple($line_item_ids = array(), $conditions = array(), $reset = FALSE) {
return entity_load('merci_reservation', $line_item_ids, $conditions, $reset);
}
function merci_reservation_permission() {
$permissions = array(
'administer merci_reservation types' => array(
'title' => t('Administer merci reservation types'),
'description' => t('Allows users to configure task types and their fields.'),
'restrict access' => TRUE,
),
'create merci_reservation entities' => array(
'title' => t('Create merci reservations'),
'description' => t('Allows users to create merci reservations.'),
'restrict access' => TRUE,
),
'view merci_reservation entities' => array(
'title' => t('View merci reservations'),
'description' => t('Allows users to view merci reservations.'),
'restrict access' => TRUE,
),
'edit any merci_reservation entities' => array(
'title' => t('Edit any merci reservations'),
'description' => t('Allows users to edit any merci reservations.'),
'restrict access' => TRUE,
),
'edit own merci_reservation entities' => array(
'title' => t('Edit own merci reservations'),
'description' => t('Allows users to edit own merci reservations.'),
'restrict access' => TRUE,
),
);
return $permissions;
}
function merci_reservation_access($op, $merci_reservation, $account = NULL, $entity_type = NULL) {
global $user;
if (!isset($account)) {
$account = $user;
}
switch ($op) {
case 'delete':
return user_access('delete any merci_reservation entities') || user_access('delete own merci_reservation entities') && $merci_reservation->uid == $account->uid;
case 'create':
return user_access('create merci_reservation entities', $account);
case 'view':
return user_access('view merci_reservation entities', $account);
case 'edit':
return user_access('edit any merci_reservation entities') || user_access('edit own merci_reservation entities') && $merci_reservation->uid == $account->uid;
}
}
function merci_reservation_type_access($op, $type = NULL, $account = NULL) {
return user_access('administer merci_reservation types', $account);
}
function merci_reservation_merci_reservation_type_insert($entity) {
merci_core_create_field(MERCI_LINE_ITEM_REFERENCE, 'merci_reservation', $entity->type);
}
function merci_reservation_merci_reservation_type_delete($entity) {
}
function merci_reservation_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'merci_reservation') . '/includes/views',
);
}