public function EntityExportCsvManager::sortNaturalFields in Entity Export CSV 8
Sort the fields given the fields configuration default value order.
Parameters
\Drupal\Core\Field\FieldDefinitionInterface[] $fields: An array of field definition keyed by the field name.
array $default_values: An array of field values configuration keyed by the field name.
Overrides EntityExportCsvManagerInterface::sortNaturalFields
File
- src/
EntityExportCsvManager.php, line 293
Class
- EntityExportCsvManager
- Class EntityExportCsvManager.
Namespace
Drupal\entity_export_csvCode
public function sortNaturalFields(array &$fields, array $default_values) {
$index = 0;
foreach ($fields as $field_name => &$item) {
$item = [
$index++,
$field_name,
$item,
];
}
uasort($fields, function ($a, $b) use ($default_values) {
if (isset($default_values[$a[1]]['order'], $default_values[$b[1]]['order'])) {
if ($default_values[$a[1]]['order'] != $default_values[$b[1]]['order']) {
return $default_values[$a[1]]['order'] < $default_values[$b[1]]['order'] ? -1 : 1;
}
else {
return $a[0] < $b[0] ? -1 : 1;
}
}
else {
return $a[0] < $b[0] ? -1 : 1;
}
});
foreach ($fields as &$item) {
$item = $item[2];
}
}