From 51d943478d4c4afce8b7be5ed4bb1953279a9a5e Mon Sep 17 00:00:00 2001 From: Paul Weidner Date: Thu, 2 Nov 2023 18:13:50 -0700 Subject: [PATCH] Build url from route instead of loading log entity --- modules/log/birth/farm_birth.module | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/modules/log/birth/farm_birth.module b/modules/log/birth/farm_birth.module index 68c5d4cf5..e4d2479d2 100644 --- a/modules/log/birth/farm_birth.module +++ b/modules/log/birth/farm_birth.module @@ -9,6 +9,7 @@ use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; /** * Implements hook_form_BASE_FORM_ID_alter(). @@ -54,23 +55,19 @@ function farm_birth_asset_view_alter(array &$build, EntityInterface $entity, Ent if (!empty($build['birthdate'][0])) { /** @var \Drupal\Core\Entity\EntityStorageInterface $log_storage */ $log_storage = \Drupal::service('entity_type.manager')->getStorage('log'); - - /** @var \Drupal\Core\Entity\Query\QueryInterface $query */ - $query = $log_storage->getQuery() + $log_ids = $log_storage->getQuery() ->accessCheck(TRUE) ->condition('type', 'birth') - ->condition('asset', $entity->id()); + ->condition('asset', $entity->id()) + ->execute(); - $ids = $query->execute(); - if (!empty($ids)) { - $log = $log_storage->load(reset($ids)); - - // Render a link to the log with a title of the timestamp field value. + // Render a link to the log with a title of the timestamp field value. + if (!empty($log_ids)) { $title = $build['birthdate'][0]; $build['birthdate'][0] = [ '#type' => 'link', '#title' => $title, - '#url' => $log->toUrl(), + '#url' => Url::fromRoute('entity.log.canonical', ['log' => reset($log_ids)]), ]; } }