Merge pull request #14594 from marcusmoore/bug/sc-25314/multiple-label-fields-on-one-row
Fixed label fields only showing first option
This commit is contained in:
commit
a8d48b758e
1 changed files with 26 additions and 1 deletions
|
@ -142,7 +142,32 @@ class Label implements View
|
||||||
// Remove Duplicates
|
// Remove Duplicates
|
||||||
$toAdd = $field
|
$toAdd = $field
|
||||||
->filter(fn($o) => !$myFields->contains('dataSource', $o['dataSource']))
|
->filter(fn($o) => !$myFields->contains('dataSource', $o['dataSource']))
|
||||||
->first();
|
// For fields that have multiple options, we need to combine them
|
||||||
|
// into a single field so all values are displayed.
|
||||||
|
->reduce(function ($previous, $current) {
|
||||||
|
// On the first iteration we simply return the item.
|
||||||
|
// If there is only one item to be processed for the row
|
||||||
|
// then this effectively skips everything below this if block.
|
||||||
|
if (is_null($previous)) {
|
||||||
|
return $current;
|
||||||
|
}
|
||||||
|
|
||||||
|
// At this point we are dealing with a row with multiple items being displayed.
|
||||||
|
// We need to combine the label and value of the current item with the previous item.
|
||||||
|
|
||||||
|
// The end result of this will be in this format:
|
||||||
|
// {labelOne} {valueOne} | {labelTwo} {valueTwo} | {labelThree} {valueThree}
|
||||||
|
$previous['value'] = trim(implode(' | ', [
|
||||||
|
implode(' ', [$previous['label'], $previous['value']]),
|
||||||
|
implode(' ', [$current['label'], $current['value']]),
|
||||||
|
]));
|
||||||
|
|
||||||
|
// We'll set the label to an empty string since we
|
||||||
|
// injected the label into the value field above.
|
||||||
|
$previous['label'] = '';
|
||||||
|
|
||||||
|
return $previous;
|
||||||
|
});
|
||||||
|
|
||||||
return $toAdd ? $myFields->push($toAdd) : $myFields;
|
return $toAdd ? $myFields->push($toAdd) : $myFields;
|
||||||
}, new Collection());
|
}, new Collection());
|
||||||
|
|
Loading…
Add table
Reference in a new issue