function theme_webform_display_productfield in Commerce Webform 8
Same name and namespace in other branches
- 7.2 productfield.inc \theme_webform_display_productfield()
- 7 productfield.inc \theme_webform_display_productfield()
Format the text output for this component.
1 theme call to theme_webform_display_productfield()
- _webform_display_productfield in ./
productfield.inc - Implements _webform_display_component().
File
- ./
productfield.inc, line 447
Code
function theme_webform_display_productfield($variables) {
$element = $variables['element'];
// Flatten the list of options so we can get values easily. These options
// may be translated by hook_webform_display_component_alter().
$options = $element['#options'];
$items = array();
foreach ($element['#value'] as $value) {
$value = json_decode($value);
// Administer provided values.
if (!empty($value->product_id)) {
if (isset($options[$value->product_id])) {
$paid_display_option = empty($value->paid) ? t('Unpaid') : t('Paid');
$paid_display_option = empty($value->order_id) ? $paid_display_option : l($paid_display_option, "admin/commerce/orders/{$value->order_id}/view");
$name = _webform_filter_xss($options[$value->product_id]);
$items[] = "{$value->quantity} x {$name} (<strong>{$paid_display_option}</strong>)";
}
else {
$items[] = check_plain($value->product_id);
}
}
}
if ($element['#format'] == 'html') {
$output = count($items) > 1 ? theme('item_list', array(
'items' => $items,
)) : (isset($items[0]) ? $items[0] : t('Not selected'));
}
else {
if (count($items) > 1) {
foreach ($items as $key => $item) {
$items[$key] = ' - ' . $item;
}
$output = implode("\n", $items);
}
else {
$output = isset($items[0]) ? $items[0] : t('Not selected');
}
}
return $output;
}