protected function RangeFormatterBase::viewElementCombined in Range 8
Helper method. Returns the combined value renderable array.
FROM and TO might have different prefixes/suffixes. Code below decides which one to use, based on the following: 1. If COMBINED is disabled and both FROM/TO are disabled - show naked value. 2. If COMBINED is enabled - show it. 3. If COMBINED is disabled and either FROM or TO are enabled - show prefix/suffix of the enabled one. 4. If COMBINED is disabled and both FROM/TO are enabled, show prefix from FROM and suffix from TO.
Parameters
\Drupal\range\RangeItemInterface $item: Range field item.
string $value: Field combined value.
Return value
array Field value renderable array.
1 call to RangeFormatterBase::viewElementCombined()
- RangeFormatterBase::viewElements in src/
Plugin/ Field/ FieldFormatter/ RangeFormatterBase.php - Builds a renderable array for a field value.
File
- src/
Plugin/ Field/ FieldFormatter/ RangeFormatterBase.php, line 167
Class
- RangeFormatterBase
- Parent plugin for decimal and integer range formatters.
Namespace
Drupal\range\Plugin\Field\FieldFormatterCode
protected function viewElementCombined(RangeItemInterface $item, $value) {
$from_prefix_suffix = !empty($this
->getSetting('from_prefix_suffix'));
$to_prefix_suffix = !empty($this
->getSetting('to_prefix_suffix'));
$combined_prefix_suffix = !empty($this
->getSetting('combined_prefix_suffix'));
// Option #1: COMBINED is disabled and both FROM/TO are disabled.
$output = [
'#theme' => 'range_formatter_range_combined',
'#item' => $item,
'#value' => $value,
];
// Option #2: COMBINED is enabled.
if ($combined_prefix_suffix) {
$output['#value_prefix'] = FieldFilteredMarkup::create($this
->getFieldSetting('combined')['prefix']);
$output['#value_suffix'] = FieldFilteredMarkup::create($this
->getFieldSetting('combined')['suffix']);
}
elseif ($from_prefix_suffix && !$to_prefix_suffix) {
$output['#value_prefix'] = FieldFilteredMarkup::create($this
->getFieldSetting('from')['prefix']);
$output['#value_suffix'] = FieldFilteredMarkup::create($this
->getFieldSetting('from')['suffix']);
}
elseif (!$from_prefix_suffix && $to_prefix_suffix) {
$output['#value_prefix'] = FieldFilteredMarkup::create($this
->getFieldSetting('to')['prefix']);
$output['#value_suffix'] = FieldFilteredMarkup::create($this
->getFieldSetting('to')['suffix']);
}
elseif ($from_prefix_suffix && $to_prefix_suffix) {
$output['#value_prefix'] = FieldFilteredMarkup::create($this
->getFieldSetting('from')['prefix']);
$output['#value_suffix'] = FieldFilteredMarkup::create($this
->getFieldSetting('to')['suffix']);
}
return $output;
}