I am working with drupal 7, and wanted to change the output of "number_float" value when it is "0.00". I have digged into field.api but has no clue what function to do.
To say it in plain English:
if the field type "number_float" and value is "0.00", print "empty value".
This开发者_运维百科 is also to consider before views output. Any hint or guidance would be very much appreciated.
Thanks
UPDATE: I used hook_field_attach_view_alter. It does as expected, however I wonder if this is the right thing.
function mymodule_field_attach_view_alter(&$output, $context) {
foreach (element_children($output) as $field_name) {
$element = &$output[$field_name];
if ($element['#field_type'] == 'number_float' && $element['#formatter'] == 'number_decimal') {
foreach ($element['#items'] as $delta => $item) {
if ($element[$delta]['#markup'] == '0.00' || $element[$delta]['#markup'] == '0,00') {
$element[$delta]['#markup'] = t('Empty value message');
}
}
}
}
}
Any suggestion or betterment will be the answer.
thanks
A more standard Drupal way would be to manipulate the value in a preprocessor function. You can use hook_preprocess_HOOK
for a theme function or template that's defined by another module. Inside of it, test for the 0.00 value and replace.
The update with hook_field_attach_view_alter is the way to go since nobody provides any other suggestion.
精彩评论