function media_expire_media_build_defaults_alter in Media Expire 8
Same name and namespace in other branches
- 8.2 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, EntityInterface $entity, $view_mode) {
/** @var \Drupal\media_entity\MediaBundleInterface $bundle */
$bundle = \Drupal::entityTypeManager()
->getStorage('media_bundle')
->load($entity
->bundle());
if ($bundle
->getThirdPartySetting('media_expire', 'enable_expiring') && !$entity->status->value) {
$fallbackMedia = $bundle
->getThirdPartySetting('media_expire', 'fallback_media');
if ($fallbackMedia && ($media = \Drupal::service('entity.repository')
->loadEntityByUuid('media', $fallbackMedia))) {
$renderController = \Drupal::entityTypeManager()
->getViewBuilder('media');
$build = $renderController
->view($media, $view_mode);
}
else {
$build = [];
}
}
}