diff --git a/uw_cfg_common.module b/uw_cfg_common.module index 9fd18f21d61e4f068768921b9c45eaa53eda7059..ea20eef898f2c0b3d0719913754d02db67866c39 100644 --- a/uw_cfg_common.module +++ b/uw_cfg_common.module @@ -107,19 +107,11 @@ function uw_cfg_common_entity_presave(EntityInterface $entity) { // images will not work. if ($entity->getEntityTypeId() == 'node') { - // If there is a hero image, continue to process. - if ($image = $entity->field_uw_hero_image) { + // If there is a hero image (media), continue to process. + if ($media = $entity->field_uw_hero_image->entity) { - // Get the value of the image field. - $image = $entity->field_uw_hero_image->getValue(); - - // Ensure that there actually is an image to process. - if ($image) { - - // Load the file from the hero image. - $file = \Drupal::entityTypeManager() - ->getStorage('file') - ->load($image[0]['target_id']); + // Hero media exists, get file entity from media. + if ($file = $media->field_media_image->entity) { // Load the image styles that are needed for the hero. $uw_styles = \Drupal::service('uw_cfg_common.uw_service')->uwGetResponsiveImageStyles();