function media_expire_media_build_defaults_alter in Media Expire 8.2
Same name and namespace in other branches
- 8 media_expire.module \media_expire_media_build_defaults_alter()
Implements hook_ENTITY_TYPE_build_defaults_alter().
File
- ./
media_expire.module, line 112 - The Media Expires Drupal module.
Code
function media_expire_media_build_defaults_alter(array &$build, MediaInterface $entity, $view_mode) {
if ($entity
->isPublished()) {
return;
}
/** @var \Drupal\media_expire\MediaExpireService $service */
$service = \Drupal::service('media_expire.service');
$fallbackMedia = $service
->getFallbackMedia($entity);
if ($fallbackMedia) {
$renderController = \Drupal::entityTypeManager()
->getViewBuilder('media');
$build = $renderController
->view($fallbackMedia, $view_mode);
}
else {
$build = [];
}
}