commerce_shipping_ui.admin.inc
4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* @file
* Administrative page callbacks for the Shipping UI module.
*/
/**
* Displays all shipping methods or services defined for a method in a table.
*/
function commerce_shipping_ui_overview($type, $method = NULL) {
drupal_add_css(drupal_get_path('module', 'commerce_shipping_ui') . '/theme/commerce_shipping.admin.css');
// Load the items that will be represented in the overview table.
if ($type == 'methods') {
$items = commerce_shipping_methods();
}
else {
$items = commerce_shipping_services($method);
uasort($items, 'drupal_sort_weight');
}
$header = array(
t('Title'),
t('Operations'),
);
$rows = array();
// Loop through all of the items to include in the overview.
foreach ($items as $name => $item) {
if ($item['admin_list']) {
// Build the operation links for the current item.
$arg = ($type == 'methods') ? strtr($name, '_', '-') : strtr($method . '-' . $name, '_', '-');
$links = menu_contextual_links('commerce-shipping-' . $type, 'admin/commerce/config/shipping/' . $type, array($arg));
// Add the item's row to the table's rows array.
$rows[] = array(
($type == 'methods') ? theme('shipping_method_admin_overview', array('shipping_method' => $item)) : theme('shipping_service_admin_overview', array('shipping_service' => $item)),
theme('links', array('links' => $links, 'attributes' => array('class' => 'links inline operations'))),
);
}
}
// If no items are defined...
if (empty($rows)) {
// Add a standard empty row with a link to add a new item.
if ($type == 'methods' || $method == NULL) {
$empty_text = t('There are no shipping methods enabled.');
}
else {
$empty_text = t('There are no services defined for the %title shipping method.', array('%title' => commerce_shipping_method_get_title($method)));
}
$rows[] = array(
array(
'data' => $empty_text,
'colspan' => 2,
)
);
}
return theme('table', array('header' => $header, 'rows' => $rows));
}
/**
* Builds an overview of a shipping method for display to an administrator.
*
* @param $variables
* An array of variables used to generate the display; by default includes the
* shipping_method key with a value of the shipping method info array.
*
* @ingroup themeable
*/
function theme_shipping_method_admin_overview($variables) {
$shipping_method = $variables['shipping_method'];
// Build the actual output.
$output = check_plain($shipping_method['title']);
$output .= ' <small> (Machine name: ' . check_plain($shipping_method['name']) . ')</small>';
$output .= '<div class="description">' . filter_xss_admin($shipping_method['description']) . '</div>';
return $output;
}
/**
* Builds an overview of a shipping service for display to an administrator.
*
* @param $variables
* An array of variables used to generate the display; by default includes the
* shipping_service key with a value of the shipping service info array.
*
* @ingroup themeable
*/
function theme_shipping_service_admin_overview($variables) {
$shipping_service = $variables['shipping_service'];
$output = check_plain($shipping_service['title']);
$output .= ' <small> (' . t('Machine name: @name', array('@name' => check_plain($shipping_service['name']))) . ')</small>';
$output .= '<div class="description">' . filter_xss_admin($shipping_service['description']) . '</div>';
return $output;
}
/**
* Builds the shipping rate calculation Rules Overview page.
*/
function commerce_shipping_ui_rate_calculation_rules() {
RulesPluginUI::$basePath = 'admin/commerce/config/shipping/calculation-rules';
$options = array('show plugin' => FALSE);
$content['enabled']['title']['#markup'] = '<h3>' . t('Enabled shipping rate calculation rules') . '</h3>';
$conditions = array('event' => 'commerce_shipping_calculate_rate', 'plugin' => 'reaction rule', 'active' => TRUE);
$content['enabled']['rules'] = RulesPluginUI::overviewTable($conditions, $options);
$content['enabled']['rules']['#empty'] = t('There are no active shipping rate calculation rules.');
$content['disabled']['title']['#markup'] = '<h3>' . t('Disabled shipping rate calculation rules') . '</h3>';
$conditions['active'] = FALSE;
$content['disabled']['rules'] = RulesPluginUI::overviewTable($conditions, $options);
$content['disabled']['rules']['#empty'] = t('There are no disabled shipping rate calculation rules.');
return $content;
}