Skip to content

Commit

Permalink
Merge pull request #38 from wri/hero-sfc-fix
Browse files Browse the repository at this point in the history
Fixes missing hero on translated pages - #341
  • Loading branch information
mariacha authored Dec 19, 2021
2 parents 019cba6 + aeebe32 commit 1c3e557
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 82 deletions.
82 changes: 0 additions & 82 deletions modules/wri_node/components/wri_page_hero.sfc

This file was deleted.

35 changes: 35 additions & 0 deletions modules/wri_node/templates/wri-page-hero.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<div {{ attributes.addClass('ds-1col', 'clearfix') }}>

{{ title_suffix.contextual_links }}
<div class="landing-page__hero {{ ((content.hero_image|render) ? 'has-image' : '') }}">
{% if content.hero_image %}
<div class="hero__image">
{{ content.hero_image }}
</div>
{% endif %}

<div class="hero__text">
<div class="grid">
<div class="hero__text--inner padding-vertical">
<div class="margin-top-xl"></div>
<h1 class="h1 {{ ((content.hero_image|render) ? 'xl white' : '') }}">{{ content.title }}</h1>
<div class="intro">{{ content.intro }}</div>
{% if content.content|render|striptags|trim is not empty %}
<div class="landing-page__hero__content">
{{ content.content }}
</div>
{% endif %}
</div>
</div>
</div>

{% if content.hero_image|render %}
<div class="dark-overlay"></div>
{% endif %}
</div>
</div>
{% if content.content|render|striptags|trim is not empty %}
<div class="landing-page__hero__field-listing__mobile container content-side-padding padding-vertical white">
{{ content.content }}
</div>
{% endif %}
10 changes: 10 additions & 0 deletions modules/wri_node/wri_node.layouts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,13 @@ layout_impact-block:
label: Title
content:
label: Content

single_file_component_layout:wri_page_hero:
label: "Page hero"
template: templates/wri-page-hero
regions:
content:
label: Content
icon_map:
- [content]
default_section: content
40 changes: 40 additions & 0 deletions modules/wri_node/wri_node.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* @file Wri Node module code.
*/

/**
* Implements hook_preprocess_hook().
*/
function wri_node_preprocess_wri_page_hero(&$context) {
$node = \Drupal::routeMatch()->getParameter('node');
if (!$node) {
$node_route = \Drupal::routeMatch()->getRawParameter('section_storage');
$node_id = str_replace('node.', '', $node_route);
$node = \Drupal\node\Entity\Node::load($node_id);
}
if ($node instanceof \Drupal\node\NodeInterface) {
if (isset($node->field_main_image->entity->field_media_image->entity->uri->value)) {
$uri = $node->field_main_image->entity->field_media_image->entity->uri->value;
$settings = [
'uri' => $uri,
'lazy' => 'blazy',
'responsive_image_style_id' => 'landing_page_hero',
];

$build = [
'#theme' => 'blazy',
'#settings' => $settings,
'#attached' => ['library' => ['blazy/load']],
];
$context['content']['hero_image'] = $build;
\Drupal\wri_node\General::$htmlClasses[] = 'transparent-header white';
}
else {
$context['content']['hero_image'] = [];
}
$context['content']['title']['#markup'] = isset($node->field_long_title->value) ? check_markup($node->field_long_title->value, 'basic_html') : $node->getTitle();
$context['content']['intro']['#markup'] = isset($node->field_intro->value) ? check_markup($node->field_intro->value, 'basic_html') : '';
}
}

0 comments on commit 1c3e557

Please sign in to comment.