From 622d2e38c8c92620d6b6aae7d0acdacc35279c6d Mon Sep 17 00:00:00 2001 From: lkmorlan <lkmorlan@uwaterloo.ca> Date: Thu, 14 Jun 2018 11:35:09 -0400 Subject: [PATCH] ISTWCMS-2452: Create _uw_fdsu_theme_resp_get_image_info() --- uw_fdsu_theme_resp.theme | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/uw_fdsu_theme_resp.theme b/uw_fdsu_theme_resp.theme index 185179f9..50ed7642 100644 --- a/uw_fdsu_theme_resp.theme +++ b/uw_fdsu_theme_resp.theme @@ -319,3 +319,26 @@ function _uw_fdsu_theme_resp_add_responsive_image_variables(array &$variables, $ return $new_sources; } } + +/** + * Get image properties from an image field. + * + * @param object $field + * The image field. + * + * @return array|null + * An array of image properties or NULL if $field does not contain the + * required information. + */ +function _uw_fdsu_theme_resp_get_image_info(Drupal\file\Plugin\Field\FieldType\FileFieldItemList $field) { + // If there is an image, process it. + if ($img_entity = $field->first()) { + // If we can load a file, grab the info about the file. + if ($file_entity = $img_entity->get('entity')->getTarget()) { + return [ + 'src' => file_create_url($file_entity->get('uri')->getString()), + 'alt' => $img_entity->get('alt')->getString(), + ]; + } + } +} -- GitLab