diff --git a/templates/paragraphs/paragraph--uw-para-options-block.html.twig b/templates/paragraphs/paragraph--uw-para-options-block.html.twig index 472a5d12bc15365dd06c8a3854eb6ee793a7905e..986149bc1295e86da76e9a81594122856b7a0a39 100644 --- a/templates/paragraphs/paragraph--uw-para-options-block.html.twig +++ b/templates/paragraphs/paragraph--uw-para-options-block.html.twig @@ -1,12 +1,3 @@ {% include '@organisms/single-page/options-block/options-block.twig' with { - 'display_title': display_title, - 'title': content.field_uw_block_title|field_value, - 'link_description': link_description, - 'link_uri': link_uri, - 'link_title': link_title, - 'link_colouring': link_colouring, - 'sources': sources, - 'output_image_tag': output_image_tag, - 'img_element': img_element['#uri'], - 'alt': alt + 'options': options }%} \ No newline at end of file diff --git a/uw_fdsu_theme_resp.theme b/uw_fdsu_theme_resp.theme index af280405edf24e8381d5e2befbcc9ea1a0fc0b1c..58e217da5308c72737c0bb25b54c6c73648387d8 100644 --- a/uw_fdsu_theme_resp.theme +++ b/uw_fdsu_theme_resp.theme @@ -128,12 +128,26 @@ function uw_fdsu_theme_resp_preprocess_paragraph(&$variables) { foreach ($field_values as $field_value) { - // Get paragraph entity of field_uw_options field from the target_id. - $p = \Drupal\paragraphs\Entity\Paragraph::load($field_value['target_id']); + // Get paragraph entity of field_uw_options field from the target_id. + $p = \Drupal\paragraphs\Entity\Paragraph::load($field_value['target_id']); - // Get the field entity from the paragraph. - $field = $p->field_uw_option_image->first(); + // Get link description and add to the variable array. + $link_description = $p->field_uw_link_description->first()->getValue(); + $options2[$i]['link_description'] = $link_description['value']; + // Get colouring value and add to the variable array. + $link_colouring = $p->field_uw_option_colouring->first()->getValue(); + $options[$i]['link_colouring'] = $link_colouring['value']; + + // Get link uri and title and add to the variable array. + $link = $p->field_uw_option_link->first()->getValue(); + $options[$i]['link_url'] = $link['uri']; + $options[$i]['link_title'] = $link['title']; + + // Get the field entity from the paragraph. + $field = $p->field_uw_option_image->first(); + + if (isset($field)) { // Set the alt tag from the field entity. $variables['alt'] = $field->get('alt')->getValue(); @@ -142,41 +156,28 @@ function uw_fdsu_theme_resp_preprocess_paragraph(&$variables) { // If there is a file present, set responsive image variables. if ($file) { + // Set uri and image style id. $variables['uri'] = $file->getFileUri(); $variables['responsive_image_style_id'] = 'uw_resp_is_sph_header_image'; + // Call template function from responsive image core module. // It sets variables for srcset, media, type and img_element // for the responsive image style. template_preprocess_responsive_image($variables); // Add all variables to an array. - $options2[$i]['alt'] = $variables['alt']; - $options2[$i]['uri'] = $variables['uri']; - $options2[$i]['responsive_image_style_id'] = $variables['responsive_image_style_id']; - $options2[$i]['sources'] = $variables['sources']; - $options2[$i]['output_image_tag'] = $variables['output_image_tag']; - $options2[$i]['img_element'] = $variables['img_element']; + $options[$i]['img_element'] = $variables['img_element']['#uri']; + $options[$i]['sources'] = $variables['sources'][$i]; + $options[$i]['alt'] = $variables['alt']; + $options[$i]['url'] = $variables['uri']; + $options[$i]['responsive_image_style_id'] = $variables['responsive_image_style_id']; + //$options[$i]['output_image_tag'] = $variables['output_image_tag']; } - - // Get colouring value and add to the variable array. - $link_colouring = $p->field_uw_option_colouring->first()->getValue(); - $options2[$i]['link_colouring'] = $link_colouring['value']; - - // Get link description and add to the variable array. - $link_description = $p->field_uw_link_description->first()->getValue(); - $options2[$i]['link_description'] = $link_description['value']; - - // Get link uri and title and add to the variable array. - $link = $p->field_uw_option_link->first()->getValue(); - $options2[$i]['link_uri'] = $link['uri']; - $options2[$i]['link_title'] = $link['title']; - - $i++; + } + $i++; } - - $variables['options2'] = $options2; - vardumper($options2); + $variables['options'] = $options; break; } }