function uc_product_get_models in Ubercart 8.4
Same name and namespace in other branches
- 6.2 uc_product/uc_product.module \uc_product_get_models()
- 7.3 uc_product/uc_product.module \uc_product_get_models()
Gets all models of a product (node).
Gathers any modules' models on this node, then add the node's SKU and the optional 'Any' option.
Parameters
int $nid: The node ID of the product.
string $add_blank: String to use for the initial blank entry. If not desired, set to NULL or FALSE. Make sure to localize the string first. Defaults to '- Any -'.
Return value
array An associative array of model numbers. The key for '- Any -' is the empty string.
5 calls to uc_product_get_models()
- FileFeatureForm::buildForm in uc_file/
src/ Form/ FileFeatureForm.php - Form constructor.
- OrderHasProductsCondition::hasProductsOptions in uc_order/
src/ Plugin/ Condition/ OrderHasProductsCondition.php - Options callback.
- RoleFeatureForm::buildForm in uc_role/
src/ Form/ RoleFeatureForm.php - Form constructor.
- StockEditForm::buildForm in uc_stock/
src/ Form/ StockEditForm.php - Form constructor.
- uc_order_condition_has_products_options in uc_order/
uc_order.rules.inc - Options callback.
File
- uc_product/
uc_product.module, line 764 - The product module for Ubercart.
Code
function uc_product_get_models($nid, $add_blank = TRUE) {
// Get any modules' SKUs on this node.
$models = \Drupal::moduleHandler()
->invokeAll('uc_product_models', [
$nid,
]);
// Add the base SKU of the node.
$connection = \Drupal::database();
$models[] = $connection
->query('SELECT model FROM {uc_products} WHERE nid = :nid', [
':nid' => $nid,
])
->fetchField();
// Now we map the SKUs to the keys, for form handling, etc.
$models = array_combine($models, $models);
// Sort the SKUs.
asort($models);
// And finally, we prepend 'Any' so it's the first option.
if (!empty($add_blank) || $add_blank === '') {
if ($add_blank === TRUE) {
$add_blank = t('- Any -');
}
return [
'' => $add_blank,
] + $models;
}
return $models;
}