You are here

function commerce_product_ui_product_type_delete_form_wrapper in Commerce Core 7

Form callback wrapper: confirmation form for deleting a product type.

Parameters

$type: The machine-name of the product type being created or edited by this form or a full product type array.

See also

commerce_product_product_type_delete_form()

1 string reference to 'commerce_product_ui_product_type_delete_form_wrapper'
commerce_product_ui_menu in modules/product/commerce_product_ui.module
Implements hook_menu().

File

modules/product/includes/commerce_product_ui.types.inc, line 103

Code

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);
  }

  // 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.
  $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.');
  }

  // Include the forms file from the Product module.
  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);
}