function commerce_sdf_field_formatter_view in Commerce Stock 7.2
Implements hook_field_formatter_view().
File
- modules/
commerce_sdf/ commerce_sdf.module, line 131 - Provide a Decimal formater for converting stock levels into text messages.
Code
function commerce_sdf_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
// Get the settings.
$settings = $display['settings'];
// Initialize the var.
$element = array();
$stock = round($items[0]['value']);
$anc_seuil = -9999999;
foreach ($settings['display'] as $row => $seuilstr) {
$seuil = $seuilstr['seuil'];
if (is_numeric($seuil)) {
if ($stock > $anc_seuil && $stock <= $seuil) {
if (isset($seuilstr['classname'])) {
// @codingStandardsIgnoreLine
$element[0]['#markup'] = "<span class='" . $seuilstr['classname'] . "'>" . t($settings['display'][$row]['message'], array(
"@stock" => $stock,
)) . "</span>";
}
else {
// @codingStandardsIgnoreLine
$element[0]['#markup'] = "<span>" . t($settings['display'][$row]['message'], array(
"@stock" => $stock,
)) . "</span>";
}
break;
}
$anc_seuil = $seuil;
}
}
return $element;
}