diff --git a/uw_fdsu_theme_resp.theme b/uw_fdsu_theme_resp.theme index c045d694bca7f092bf9bc5ff00ee9cff1394a91a..d3a9f9294bcb755eeb99a49e74652965a547b3c0 100644 --- a/uw_fdsu_theme_resp.theme +++ b/uw_fdsu_theme_resp.theme @@ -167,22 +167,13 @@ function _uw_fdsu_theme_resp_get_field_value_from_paragraph($paragraph, $field) * Set the variables required for a responsive image. * * @param $variables - * @param $field_name + * @param $field * @param $responsive_image_style */ -function _uw_fdsu_theme_resp_add_responsive_image_variables(&$variables, $field_name, $responsive_image_style, $use_separate_variable = FALSE) { - - // Get the field entity from the paragraph. - $field = $variables['paragraph']->get($field_name)->first(); - - // Set the alt tag from the field entity. - $variables['alt'] = $field->get('alt')->getValue(); - - // Set the file entity based on the field name. - $file = $field->entity; +function _uw_fdsu_theme_resp_add_responsive_image_variables(&$variables, $field, $responsive_image_style) { // If there is a file present, set responsive image variables. - if ($file) { + if ($file = $field->entity) { // Set uri and image style id. $variables['uri'] = $file->getFileUri(); @@ -193,30 +184,31 @@ function _uw_fdsu_theme_resp_add_responsive_image_variables(&$variables, $field_ // for the responsive image style. template_preprocess_responsive_image($variables); - // Set the old_sources to the sources in variables. + // Start with clean arrays. + unset($old_sources); + unset($new_sources); + + // Set old_sources to the ones set in the template preprocess. $old_sources = $variables['sources']; - // Unset the sources variable. - unset($variables['sources']); + // Step through each source and get string values. + foreach ($old_sources as $source) { - // Step through each source and only get value. - // This is need so that a render doesn't happen - // and HTML escapes are put in place. - foreach($old_sources as $source) { - $sources[] = array ( + // Set new_sources to the string values. + $new_sources[] = array ( 'srcset' => $source['srcset']->value(), 'media' => $source['media']->value(), 'type' => $source['type']->value(), ); } - // If not to set sources in variables, return sources. - // Otherwise set the sources in variables. - if ($use_separate_variable) { - return $sources; - } - else { - $variables['sources'] = $sources; - } + // Set the alt tag for the picture. + $new_sources['alt'] = $field->get('alt')->getValue(); + + // Unset the old sources. + unset($variables['sources']); + + // Return the new sources. + return $new_sources; } }