From bab926b199cff13b5c0fbbf5960123f3de73fa9b Mon Sep 17 00:00:00 2001 From: Michael Stenta Date: Mon, 31 May 2021 13:14:11 -0400 Subject: [PATCH] Reformat farm_location_views_data_alter() to make it easier to extend. --- modules/core/location/farm_location.module | 23 ++++++++++------------ 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/modules/core/location/farm_location.module b/modules/core/location/farm_location.module index 4f5480ff..8e87e7f9 100644 --- a/modules/core/location/farm_location.module +++ b/modules/core/location/farm_location.module @@ -49,29 +49,26 @@ function farm_location_entity_base_field_info(EntityTypeInterface $entity_type) */ function farm_location_views_data_alter(array &$data) { - // Define the asset computed fields. - $asset_computed_fields = [ - 'geometry' => [ + // Add computed fields to assets. + if (isset($data['asset'])) { + + // Computed geometry. + $data['asset']['geometry'] = [ 'title' => t('Geometry'), 'field' => [ 'id' => 'asset_geometry', 'field_name' => 'geometry', ], - ], - 'location' => [ + ]; + + // Computed location. + $data['asset']['location'] = [ 'title' => t('Current location'), 'field' => [ 'id' => 'asset_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; - } + ]; } }