Back port 4.0 implementation of numeric/assoc key merging for summary_fields

This commit is contained in:
Aaron Carlino 2018-02-27 16:42:44 +13:00
parent f69f35eead
commit e107512063

View File

@ -3709,13 +3709,18 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
* @return array
*/
public function summaryFields() {
$fields = $this->stat('summary_fields');
$rawFields = $this->stat('summary_fields');
// if fields were passed in numeric array,
// convert to an associative array
if($fields && array_key_exists(0, $fields)) {
$fields = array_combine(array_values($fields), array_values($fields));
}
$fields = [];
// Merge associative / numeric keys
if (is_array($rawFields)) {
foreach ($rawFields as $key => $value) {
if (is_int($key)) {
$key = $value;
}
$fields[$key] = $value;
}
}
if (!$fields) {
$fields = array();