Skip to content
Snippets Groups Projects
Commit 622d2e38 authored by Liam Morland's avatar Liam Morland
Browse files

ISTWCMS-2452: Create _uw_fdsu_theme_resp_get_image_info()

parent 86963b36
No related branches found
No related tags found
No related merge requests found
......@@ -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(),
];
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment