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\EntityInterface;
|
||||||
use Drupal\Core\Entity\EntityTypeInterface;
|
use Drupal\Core\Entity\EntityTypeInterface;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
use Drupal\Core\Url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_form_BASE_FORM_ID_alter().
|
* 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])) {
|
if (!empty($build['birthdate'][0])) {
|
||||||
/** @var \Drupal\Core\Entity\EntityStorageInterface $log_storage */
|
/** @var \Drupal\Core\Entity\EntityStorageInterface $log_storage */
|
||||||
$log_storage = \Drupal::service('entity_type.manager')->getStorage('log');
|
$log_storage = \Drupal::service('entity_type.manager')->getStorage('log');
|
||||||
|
$log_ids = $log_storage->getQuery()
|
||||||
/** @var \Drupal\Core\Entity\Query\QueryInterface $query */
|
|
||||||
$query = $log_storage->getQuery()
|
|
||||||
->accessCheck(TRUE)
|
->accessCheck(TRUE)
|
||||||
->condition('type', 'birth')
|
->condition('type', 'birth')
|
||||||
->condition('asset', $entity->id());
|
->condition('asset', $entity->id())
|
||||||
|
->execute();
|
||||||
|
|
||||||
$ids = $query->execute();
|
// Render a link to the log with a title of the timestamp field value.
|
||||||
if (!empty($ids)) {
|
if (!empty($log_ids)) {
|
||||||
$log = $log_storage->load(reset($ids));
|
|
||||||
|
|
||||||
// Render a link to the log with a title of the timestamp field value.
|
|
||||||
$title = $build['birthdate'][0];
|
$title = $build['birthdate'][0];
|
||||||
$build['birthdate'][0] = [
|
$build['birthdate'][0] = [
|
||||||
'#type' => 'link',
|
'#type' => 'link',
|
||||||
'#title' => $title,
|
'#title' => $title,
|
||||||
'#url' => $log->toUrl(),
|
'#url' => Url::fromRoute('entity.log.canonical', ['log' => reset($log_ids)]),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue