You are here

function uc_product_kit_form_alter in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_product_kit/uc_product_kit.module \uc_product_kit_form_alter()

Implements hook_form_alter().

File

uc_product_kit/uc_product_kit.module, line 61
The product kit module for Ubercart.

Code

function uc_product_kit_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'node_delete_confirm' && uc_product_is_product((int) $form['nid']['#value'])) {
    $kits = 0;
    $result = db_query("SELECT k.nid FROM {node} AS n JOIN {uc_product_kits} AS k ON n.vid = k.vid WHERE k.vid IN (SELECT DISTINCT vid FROM {uc_product_kits} WHERE product_id = %d) GROUP BY k.nid HAVING COUNT(product_id) = 1", $form['nid']['#value']);
    while ($k = db_fetch_object($result)) {
      $kits++;
    }
    if ($kits) {
      $description = $form['description']['#value'];
      $form['description']['#value'] = format_plural($kits, 'There is 1 product kit that consists of only this product. It will be deleted as well.', 'There are @count product kits that consist of only this products. They will be deleted as well.') . ' ' . $description;
    }
  }
}