View source
<?php
function commerce_customer_ui_menu() {
$items = array();
$items['admin/commerce/customer-profiles/add'] = array(
'title' => 'Add a customer profile',
'description' => 'Add a new customer profile.',
'page callback' => 'commerce_customer_ui_customer_profile_add_page',
'access callback' => 'commerce_customer_ui_customer_profile_add_any_access',
'weight' => 10,
'file' => 'includes/commerce_customer_ui.profiles.inc',
);
foreach (commerce_customer_profile_types() as $type => $profile_type) {
$items['admin/commerce/customer-profiles/add/' . strtr($type, array(
'_' => '-',
))] = array(
'title' => 'Create @name',
'title arguments' => array(
'@name' => $profile_type['name'],
),
'description' => $profile_type['description'],
'page callback' => 'commerce_customer_ui_customer_profile_form_wrapper',
'page arguments' => array(
commerce_customer_profile_new($type),
),
'access callback' => 'commerce_customer_profile_access',
'access arguments' => array(
'create',
commerce_customer_profile_new($type),
),
'file' => 'includes/commerce_customer_ui.profiles.inc',
);
}
$items['admin/commerce/customer-profiles/%commerce_customer_profile'] = array(
'title callback' => 'commerce_customer_ui_customer_profile_title',
'title arguments' => array(
3,
),
'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,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'file' => 'includes/commerce_customer_ui.profiles.inc',
);
$items['admin/commerce/customer-profiles/%commerce_customer_profile/edit'] = array(
'title' => 'Edit',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
);
$items['admin/commerce/customer-profiles/%commerce_customer_profile/delete'] = array(
'title' => 'Delete a customer profile',
'page callback' => 'commerce_customer_ui_customer_profile_delete_form_wrapper',
'page arguments' => array(
3,
),
'access callback' => 'commerce_customer_profile_access',
'access arguments' => array(
'delete',
3,
),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
'context' => MENU_CONTEXT_INLINE,
'file' => 'includes/commerce_customer_ui.profiles.inc',
);
$items['admin/commerce/customer-profiles/types'] = array(
'title' => 'Profile types',
'description' => 'Manage customer profile types for your store.',
'page callback' => 'commerce_customer_ui_customer_profile_types_overview',
'access arguments' => array(
'administer customer profile types',
),
'type' => MENU_LOCAL_TASK,
'weight' => 0,
'file' => 'includes/commerce_customer_ui.profile_types.inc',
);
foreach (commerce_customer_profile_types() as $type => $profile_type) {
$type_arg = strtr($type, '_', '-');
$items['admin/commerce/customer-profiles/types/' . $type_arg] = array(
'title' => $profile_type['name'],
'page callback' => 'commerce_customer_ui_profile_type_redirect',
'page arguments' => array(
$type,
),
'access arguments' => array(
'administer customer profile types',
),
);
}
return $items;
}
function commerce_customer_ui_customer_profile_title($profile) {
return t('Customer profile @profile_id', array(
'@profile_id' => $profile->profile_id,
));
}
function commerce_customer_ui_customer_profile_add_any_access() {
if (user_access('administer commerce_customer_profile entities')) {
return TRUE;
}
foreach (commerce_customer_profile_types() as $type => $profile_type) {
if (commerce_customer_profile_access('create', commerce_customer_profile_new($type))) {
return TRUE;
}
}
return FALSE;
}
function commerce_customer_ui_profile_type_redirect($type) {
drupal_goto('admin/commerce/customer-profiles/types/' . strtr($type, '_', '-') . '/fields');
}
function commerce_customer_ui_menu_alter(&$items) {
foreach (commerce_customer_profile_types() as $type => $profile_type) {
$type_arg = strtr($type, '_', '-');
$items['admin/commerce/customer-profiles/types/' . $type_arg . '/fields']['context'] = MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE;
$items['admin/commerce/customer-profiles/types/' . $type_arg . '/display']['context'] = MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE;
}
}
function commerce_customer_ui_menu_local_tasks_alter(&$data, $router_item, $root_path) {
if ($root_path == 'admin/commerce/customer-profiles') {
$item = menu_get_item('admin/commerce/customer-profiles/add');
if ($item['access']) {
$data['actions']['output'][] = array(
'#theme' => 'menu_local_action',
'#link' => $item,
);
}
}
}
function commerce_customer_ui_admin_menu_map() {
$map['admin/commerce/customer-profiles/types/%'] = array(
'parent' => 'admin/commerce/customer-profiles/types',
'arguments' => array(
array(
'%' => array_keys(commerce_customer_profile_types()),
),
),
);
return $map;
}
function commerce_customer_ui_help($path, $arg) {
switch ($path) {
case 'admin/commerce/customer-profiles/types/add':
return '<p>' . t('Individual customer profile types can have different fields assigned to them.') . '</p>';
}
if ($arg[1] == 'commerce' && $arg[2] == 'customer-profiles' && $arg[3] == 'add' && $arg[4]) {
$profile_type = commerce_customer_profile_type_load($arg[4]);
return !empty($profile_type['help']) ? '<p>' . filter_xss_admin($profile_type['help']) . '</p>' : '';
}
}
function commerce_customer_ui_theme() {
return array(
'customer_profile_add_list' => array(
'variables' => array(
'content' => array(),
),
'file' => 'includes/commerce_customer_ui.profiles.inc',
),
'customer_profile_type_admin_overview' => array(
'variables' => array(
'type' => NULL,
),
'file' => 'includes/commerce_customer_ui.profile_types.inc',
),
'commerce_customer_profile_status' => array(
'variables' => array(
'status' => NULL,
'label' => NULL,
'profile' => NULL,
),
'path' => drupal_get_path('module', 'commerce_customer_ui') . '/theme',
'template' => 'commerce-customer-profile-status',
),
);
}
function commerce_customer_ui_entity_info_alter(&$entity_info) {
$entity_info['commerce_customer_profile']['uri callback'] = 'commerce_customer_ui_customer_profile_uri';
foreach ($entity_info['commerce_customer_profile']['bundles'] as $type => &$bundle) {
$bundle['admin'] = array(
'path' => 'admin/commerce/customer-profiles/types/' . strtr($type, '_', '-'),
'real path' => 'admin/commerce/customer-profiles/types/' . strtr($type, '_', '-'),
'access arguments' => array(
'administer customer profile types',
),
);
}
}
function commerce_customer_ui_customer_profile_uri($profile) {
$uri = commerce_customer_profile_uri($profile);
if (!empty($uri)) {
return $uri;
}
if (commerce_customer_profile_access('view', $profile)) {
return array(
'path' => 'admin/commerce/customer-profiles/' . $profile->profile_id,
);
}
return NULL;
}
function commerce_customer_ui_forms($form_id, $args) {
$forms = array();
$forms['commerce_customer_ui_customer_profile_form'] = array(
'callback' => 'commerce_customer_customer_profile_form',
);
$forms['commerce_customer_ui_customer_profile_delete_form'] = array(
'callback' => 'commerce_customer_customer_profile_delete_form',
);
return $forms;
}
function commerce_customer_ui_form_alter(&$form, &$form_state, $form_id) {
if (in_array($form_id, array(
'field_ui_field_overview_form',
'field_ui_display_overview_form',
))) {
if ($form['#entity_type'] == 'commerce_customer_profile') {
$profile_type = commerce_customer_profile_type_load($form['#bundle']);
drupal_set_title($profile_type['name']);
}
}
}
function commerce_customer_ui_form_commerce_customer_ui_customer_profile_form_alter(&$form, &$form_state) {
$form['actions']['submit']['#submit'][] = 'commerce_customer_ui_customer_profile_form_submit';
if (empty($form_state['customer_profile']->profile_id)) {
$form['actions']['save_continue'] = array(
'#type' => 'submit',
'#value' => t('Save and add another'),
'#submit' => $form['actions']['submit']['#submit'],
'#suffix' => l(t('Cancel'), 'admin/commerce/customer-profiles'),
'#weight' => 45,
);
}
else {
$form['actions']['submit']['#suffix'] = l(t('Cancel'), 'admin/commerce/customer-profiles');
}
}
function commerce_customer_ui_customer_profile_form_submit($form, &$form_state) {
if ($form_state['triggering_element']['#parents'][0] == 'save_continue') {
$form_state['redirect'] = 'admin/commerce/customer-profiles/add/' . strtr($form_state['customer_profile']->type, array(
'_' => '-',
));
}
elseif (arg(2) == 'customer-profiles' && arg(3) == 'add') {
$form_state['redirect'] = 'admin/commerce/customer-profiles';
}
}
function commerce_customer_ui_form_commerce_customer_ui_customer_profile_delete_form_alter(&$form, &$form_state) {
$form['actions']['cancel']['#href'] = 'admin/commerce/customer-profiles';
$form['#submit'][] = 'commerce_customer_ui_customer_profile_delete_form_submit';
}
function commerce_customer_ui_customer_profile_delete_form_submit($form, &$form_state) {
$form_state['redirect'] = 'admin/commerce/customer-profiles';
}
function commerce_customer_ui_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'commerce_customer_ui') . '/includes/views',
);
}
function commerce_customer_ui_set_breadcrumb($profile_types = FALSE) {
}
function commerce_customer_ui_form_entity_translation_admin_form_alter(&$form, &$form_state, $form_id) {
unset($form['entity_translation_entity_types']['#options']['commerce_customer_profile']);
}