You are here

function commerce_backoffice_product_variation_type_delete_form_wrapper in Commerce Backoffice 7

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

Parameters

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

See also

commerce_product_product_type_delete_form()

1 string reference to 'commerce_backoffice_product_variation_type_delete_form_wrapper'
commerce_backoffice_product_menu in ./commerce_backoffice_product.module
Implements hook_menu().

File

includes/commerce_backoffice_product.product_variation_types.inc, line 308
Product variation specific copy of commerce_product_ui/includes/commerce_product_ui.types.inc and commerce_product_ui/includes/commerce_product_ui.forms.inc.

Code

function commerce_backoffice_product_variation_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 variation type is not governed by Product UI.
  if ($product_type['module'] != 'commerce_product_ui') {
    return t('This product variation type cannot be deleted, because it is not defined by the Product UI module.');
  }

  // Don't allow deletion of product variation 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 variation type', array(
      '%name' => $product_type['name'],
    )), PASS_THROUGH);
    return format_plural($count, 'There is 1 product variation of this type. It cannot be deleted.', 'There are @count product variations of this type. It cannot be deleted.');
  }
  return drupal_get_form('commerce_backoffice_product_variation_type_delete_form', $product_type);
}