function _range_field_formatter_view_combined_value in Range 7
Helper function. Returns field markup for combined value option.
FROM and TO might have different prefixes/suffixes. Code below decides which one to use, based on the following:
- If COMBINED is enabled - show it
- If COMBINED is disabled and both FROM/TO are disabled - show naked value
- If COMBINED is disabled and either FROM or TO are enabled - show prefix/suffix of the enabled one
- If COMBINED is disabled and both FROM/TO are enabled, show prefix from FROM and suffix from TO
Parameters
string $value: Field value.
array $settings: Display settings array.
array $instance_settings: Field instance settings array.
Return value
string Field markup.
2 calls to _range_field_formatter_view_combined_value()
- RangeUnitTestCase::testRangeFormatterViewCombinedValue in tests/
range.unit.test - Test combined value formatter.
- range_field_formatter_view in ./
range.module - Implements hook_field_formatter_view().
File
- ./
range.module, line 535 - Defines range field types.
Code
function _range_field_formatter_view_combined_value($value, array $settings, array $instance_settings) {
$from_prefix_suffix = !empty($settings['from_prefix_suffix']);
$to_prefix_suffix = !empty($settings['to_prefix_suffix']);
$combined_prefix_suffix = !empty($settings['combined_prefix_suffix']);
// Option #0: COMBINED is enabled.
if ($combined_prefix_suffix) {
return _range_field_formatter_view_prefix_suffix($value, TRUE, $instance_settings['combined']);
}
elseif (empty($from_prefix_suffix) && empty($to_prefix_suffix)) {
return $value;
}
elseif (!empty($from_prefix_suffix) && empty($to_prefix_suffix)) {
return _range_field_formatter_view_prefix_suffix($value, TRUE, $instance_settings['from']);
}
elseif (empty($from_prefix_suffix) && !empty($to_prefix_suffix)) {
return _range_field_formatter_view_prefix_suffix($value, TRUE, $instance_settings['to']);
}
else {
return _range_field_formatter_view_prefix_suffix($value, TRUE, array(
'prefix' => $instance_settings['from']['prefix'],
'suffix' => $instance_settings['to']['suffix'],
));
}
}