mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
Link animal birthdate field to birth log, if available.
This commit is contained in:
parent
92cef7f8f8
commit
d81c417ff5
1 changed files with 24 additions and 0 deletions
|
@ -40,6 +40,30 @@ function farm_birth_log_view_alter(array &$build, EntityInterface $entity, Entit
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ENTITY_TYPE_view_alter().
|
||||
*/
|
||||
function farm_birth_asset_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
|
||||
|
||||
// Only alter animal assets.
|
||||
if ($entity->bundle() != 'animal') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add a link to the asset's birth log.
|
||||
if (!empty($build['birthdate'])) {
|
||||
$log_storage = \Drupal::service('entity_type.manager')->getStorage('log');
|
||||
$query = $log_storage->getQuery();
|
||||
$ids = $query->condition('type', 'birth')
|
||||
->condition('asset', $entity->id())
|
||||
->execute();
|
||||
if (!empty($ids)) {
|
||||
$log = $log_storage->load(reset($ids));
|
||||
$build['birthdate'][0]['#markup'] = '<a href="' . $log->toUrl()->toString() . '">' . $build['birthdate'][0]['#markup'] . '</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_base_field_info_alter().
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue