From 7ec99e10f2e9c56ba7edb1ba9107b93393741eb8 Mon Sep 17 00:00:00 2001 From: paul121 Date: Fri, 4 Jun 2021 12:14:28 -0700 Subject: [PATCH] Add link to view logs from the asset popup. --- modules/ui/map/farm_ui_map.module | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/modules/ui/map/farm_ui_map.module b/modules/ui/map/farm_ui_map.module index 44f7b2e1..9009f675 100644 --- a/modules/ui/map/farm_ui_map.module +++ b/modules/ui/map/farm_ui_map.module @@ -5,6 +5,10 @@ * The farmOS UI Map module. */ +use Drupal\Core\Entity\Display\EntityViewDisplayInterface; +use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Url; + /** * Implements hook_theme(). */ @@ -41,3 +45,26 @@ function farm_ui_map_module_implements_alter(&$implementations, $hook) { $implementations = array_merge([$module => $group], $implementations); } } + +/** + * Implements hook_ENTITY_TYPE_view(). + */ +function farm_ui_map_asset_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) { + /** @var \Drupal\farm_entity\Plugin\Asset\AssetType\AssetTypeInterface $entity */ + + // Bail if not the map_popup view mode. + if ($view_mode !== 'map_popup') { + return $build; + } + + // Build link to view logs referencing the asset. + $url = Url::fromRoute('view.farm_log.page_asset', ['asset' => $entity->id(), 'log_type' => 'all']); + $build['logs_links'] = [ + '#type' => 'link', + '#title' => t('View logs'), + '#url' => $url, + '#weight' => -100, + ]; + + return $build; +}