Skip to content

Commit

Permalink
#983102 by rszrama: only show edit and delete links for product types…
Browse files Browse the repository at this point in the history
… governed by Product UI.
  • Loading branch information
rszrama committed Dec 23, 2010
1 parent c89ec9e commit 380a881
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
18 changes: 16 additions & 2 deletions modules/product/commerce_product_ui.module
Expand Up @@ -91,14 +91,17 @@ function commerce_product_ui_menu() {
);
$items['admin/commerce/products/types/%commerce_product_type/edit'] = array(
'title' => 'Edit',
'access callback' => 'commerce_product_ui_product_type_update_access',
'access arguments' => array(4),
'type' => MENU_DEFAULT_LOCAL_TASK,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
);
$items['admin/commerce/products/types/%commerce_product_type/delete'] = array(
'title' => 'Delete',
'page callback' => 'commerce_product_ui_product_type_delete_form_wrapper',
'page arguments' => array(4),
'access arguments' => array('administer product types'),
'access callback' => 'commerce_product_ui_product_type_update_access',
'access arguments' => array(4),
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_INLINE,
'weight' => 10,
Expand All @@ -121,7 +124,7 @@ function commerce_product_ui_product_title($product) {
}

/**
* Access callback: determine if the user can create any type of product.
* Access callback: determines if the user can create any type of product.
*/
function commerce_product_ui_product_add_any_access() {
// Grant automatic access to users with administer products permission.
Expand All @@ -139,6 +142,17 @@ function commerce_product_ui_product_add_any_access() {
return FALSE;
}

/**
* Access callback: determines if the user can edit or delete a product type.
*/
function commerce_product_ui_product_type_update_access($product_type) {
if ($product_type->module == 'commerce_product_ui') {
return user_access('administer product types');
}

return FALSE;
}

/**
* Implements hook_menu_alter().
*/
Expand Down
10 changes: 10 additions & 0 deletions modules/product/includes/commerce_product_ui.types.inc
Expand Up @@ -76,6 +76,11 @@ function commerce_product_ui_product_type_form_wrapper($product_type) {
// Add the breadcrumb for the form's location.
commerce_product_ui_set_breadcrumb(TRUE);

// Return a message if the product type is not governed by Product UI.
if ($product_type->module != 'commerce_product_ui') {
return t('This product type cannot be edited, because it is not defined by the Product UI module.');
}

// Include the forms file from the Product module.
module_load_include('inc', 'commerce_product_ui', 'includes/commerce_product_ui.forms');

Expand All @@ -94,6 +99,11 @@ function commerce_product_ui_product_type_delete_form_wrapper($product_type) {
// Add the breadcrumb for the form's location.
commerce_product_ui_set_breadcrumb(TRUE);

// Return a message if the product type is not governed by Product UI.
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.');
}

// Don't allow deletion of product types that have products already.
if (($count = db_query("SELECT product_id FROM {commerce_product} WHERE type = :product_type", array(':product_type' => $product_type->type))->rowCount()) > 0) {
drupal_set_title(t('Cannot delete the %name product type', array('%name' => $product_type->name)), PASS_THROUGH);
Expand Down

0 comments on commit 380a881

Please sign in to comment.