View source
<?php
function commerce_product_ui_types_overview() {
drupal_add_css(drupal_get_path('module', 'commerce_product') . '/theme/commerce_product.admin.css');
$header = array(
t('Name'),
t('Operations'),
);
$rows = array();
foreach (commerce_product_types() as $type => $product_type) {
$links = menu_contextual_links('commerce-product-type', 'admin/commerce/products/types', array(
strtr($type, array(
'_' => '-',
)),
));
$rows[] = array(
theme('product_type_admin_overview', array(
'product_type' => $product_type,
)),
theme('links', array(
'links' => $links,
'attributes' => array(
'class' => 'links inline operations',
),
)),
);
}
if (empty($rows)) {
$rows[] = array(
array(
'data' => t('There are no product types yet. <a href="@link">Add product type</a>.', array(
'@link' => url('admin/commerce/products/types/add'),
)),
'colspan' => 2,
),
);
}
return theme('table', array(
'header' => $header,
'rows' => $rows,
));
}
function theme_product_type_admin_overview($variables) {
$product_type = $variables['product_type'];
$output = check_plain($product_type['name']);
$output .= ' <small>' . t('(Machine name: @type)', array(
'@type' => $product_type['type'],
)) . '</small>';
$output .= '<div class="description">' . filter_xss_admin($product_type['description']) . '</div>';
return $output;
}
function commerce_product_ui_product_type_form_wrapper($type) {
if (is_array($type)) {
$product_type = $type;
}
else {
$product_type = commerce_product_type_load($type);
}
if (!empty($product_type['type']) && $product_type['module'] != 'commerce_product_ui') {
return t('This product type cannot be edited, because it is not defined by the Product UI module.');
}
module_load_include('inc', 'commerce_product_ui', 'includes/commerce_product_ui.forms');
return drupal_get_form('commerce_product_ui_product_type_form', $product_type);
}
function commerce_product_ui_product_type_delete_form_wrapper($type) {
if (is_array($type)) {
$product_type = $type;
}
else {
$product_type = commerce_product_type_load($type);
}
if ($product_type['module'] != 'commerce_product_ui') {
return t('This product type cannot be deleted, because it is not defined by the Product UI module.');
}
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'commerce_product', '=')
->entityCondition('bundle', $product_type['type'], '=')
->count();
$count = $query
->execute();
if ($count > 0) {
drupal_set_title(t('Cannot delete the %name product type', array(
'%name' => $product_type['name'],
)), PASS_THROUGH);
return format_plural($count, 'There is 1 product of this type. It cannot be deleted.', 'There are @count products of this type. It cannot be deleted.');
}
module_load_include('inc', 'commerce_product_ui', 'includes/commerce_product_ui.forms');
return drupal_get_form('commerce_product_ui_product_type_delete_form', $product_type);
}