Build url from route instead of loading log entity
This commit is contained in:
parent
ee6a7fb57c
commit
51d943478d
|
@ -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)]),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue