Skip to content
Snippets Groups Projects
Commit b05fb1ce authored by Eric Bremner's avatar Eric Bremner
Browse files

Fixing getting responsive image variables to any field

parent a8b5913f
No related branches found
No related tags found
No related merge requests found
...@@ -167,22 +167,13 @@ function _uw_fdsu_theme_resp_get_field_value_from_paragraph($paragraph, $field) ...@@ -167,22 +167,13 @@ function _uw_fdsu_theme_resp_get_field_value_from_paragraph($paragraph, $field)
* Set the variables required for a responsive image. * Set the variables required for a responsive image.
* *
* @param $variables * @param $variables
* @param $field_name * @param $field
* @param $responsive_image_style * @param $responsive_image_style
*/ */
function _uw_fdsu_theme_resp_add_responsive_image_variables(&$variables, $field_name, $responsive_image_style, $use_separate_variable = FALSE) { function _uw_fdsu_theme_resp_add_responsive_image_variables(&$variables, $field, $responsive_image_style) {
// 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;
// If there is a file present, set responsive image variables. // If there is a file present, set responsive image variables.
if ($file) { if ($file = $field->entity) {
// Set uri and image style id. // Set uri and image style id.
$variables['uri'] = $file->getFileUri(); $variables['uri'] = $file->getFileUri();
...@@ -193,30 +184,31 @@ function _uw_fdsu_theme_resp_add_responsive_image_variables(&$variables, $field_ ...@@ -193,30 +184,31 @@ function _uw_fdsu_theme_resp_add_responsive_image_variables(&$variables, $field_
// for the responsive image style. // for the responsive image style.
template_preprocess_responsive_image($variables); 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']; $old_sources = $variables['sources'];
// Unset the sources variable. // Step through each source and get string values.
unset($variables['sources']); foreach ($old_sources as $source) {
// Step through each source and only get value. // Set new_sources to the string values.
// This is need so that a render doesn't happen $new_sources[] = array (
// and HTML escapes are put in place.
foreach($old_sources as $source) {
$sources[] = array (
'srcset' => $source['srcset']->value(), 'srcset' => $source['srcset']->value(),
'media' => $source['media']->value(), 'media' => $source['media']->value(),
'type' => $source['type']->value(), 'type' => $source['type']->value(),
); );
} }
// If not to set sources in variables, return sources. // Set the alt tag for the picture.
// Otherwise set the sources in variables. $new_sources['alt'] = $field->get('alt')->getValue();
if ($use_separate_variable) {
return $sources; // Unset the old sources.
} unset($variables['sources']);
else {
$variables['sources'] = $sources; // Return the new sources.
} return $new_sources;
} }
} }
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