function uc_product_get_picture in Ubercart 7.3
Same name and namespace in other branches
- 8.4 uc_product/uc_product.module \uc_product_get_picture()
- 5 uc_product/uc_product.module \uc_product_get_picture()
- 6.2 uc_product/uc_product.module \uc_product_get_picture()
Returns a product node's first attached image.
Parameters
$node_id: The node's id.
$style: The image style used to format the image. 'uc_product' by default.
Return value
A renderable array of the first product image, linked to the product node, or an empty array if no image is available.
1 call to uc_product_get_picture()
- uc_cart_view_form in uc_cart/
uc_cart.module - Displays the contents of the customer's cart.
File
- uc_product/
uc_product.module, line 1397 - The product module for Ubercart.
Code
function uc_product_get_picture($nid, $style = 'uc_product') {
$product = node_load($nid);
if (!$product) {
return array();
}
$field_name = variable_get('uc_image_' . $product->type, 'uc_product_image');
$output = array();
if ($field_name && isset($product->{$field_name})) {
$elements = field_view_field('node', $product, $field_name, array(
'label' => 'hidden',
'type' => 'image',
'settings' => array(
'image_link' => 'content',
'image_style' => $style,
),
));
// Extract the part of the render array we need.
$output = isset($elements[0]) ? $elements[0] : array();
if (isset($elements['#access'])) {
$output['#access'] = $elements['#access'];
}
}
return $output;
}