3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00

Reformat farm_location_views_data_alter() to make it easier to extend.

This commit is contained in:
Michael Stenta 2021-05-31 13:14:11 -04:00
parent 34706f92c5
commit bab926b199

View file

@ -49,29 +49,26 @@ function farm_location_entity_base_field_info(EntityTypeInterface $entity_type)
*/ */
function farm_location_views_data_alter(array &$data) { function farm_location_views_data_alter(array &$data) {
// Define the asset computed fields. // Add computed fields to assets.
$asset_computed_fields = [ if (isset($data['asset'])) {
'geometry' => [
// Computed geometry.
$data['asset']['geometry'] = [
'title' => t('Geometry'), 'title' => t('Geometry'),
'field' => [ 'field' => [
'id' => 'asset_geometry', 'id' => 'asset_geometry',
'field_name' => 'geometry', 'field_name' => 'geometry',
], ],
], ];
'location' => [
// Computed location.
$data['asset']['location'] = [
'title' => t('Current location'), 'title' => t('Current location'),
'field' => [ 'field' => [
'id' => 'asset_location', 'id' => 'asset_location',
'field_name' => 'location', 'field_name' => 'location',
], ],
], ];
];
// Add asset computed fields.
if (isset($data['asset'])) {
foreach ($asset_computed_fields as $field_id => $field_data) {
$data['asset'][$field_id] = $field_data;
}
} }
} }