Skip to content

Commit

Permalink
Merge pull request #34 from wri/rendering-bug-fix
Browse files Browse the repository at this point in the history
Rendering bug fix
  • Loading branch information
mariacha authored Dec 8, 2021
2 parents 189a25a + 6bfc9c8 commit f2a94f1
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 179 deletions.
121 changes: 0 additions & 121 deletions modules/wri_article/components/wri_article_columns.sfc

This file was deleted.

78 changes: 78 additions & 0 deletions modules/wri_article/templates/wri-article-columns.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{% if content %}
<div class="article">
{% if content.hero %}
<div {{ region_attributes.hero.addClass('layout__region', 'layout__region--hero') }}>
{{ content.hero }}
</div>
{% endif %}
<div{{ attributes.addClass('grid','article__title', 'margin-bottom-sm') }}>
{% if content.title %}
<div {{ region_attributes.title.addClass('layout__region', 'layout__region--title', 'full-width') }}>
{{ content.title }}
</div>
{% endif %}

{% if content.byline %}
<div {{ region_attributes.byline.addClass('layout__region', 'layout__region--byline', 'full-width') }}>
{{ content.byline }}
</div>
{% endif %}
</div>

{% if content.bundle or content.category or content.share %}
<div class="article__meta grid">
{% if content.bundle %}
<div {{ region_attributes.bundle.addClass('layout__region', 'layout__region--bundle', 'left-sidebar') }}>
{{ content.bundle }}
</div>
{% endif %}

{% if content.category %}
<div {{ region_attributes.category.addClass('layout__region', 'layout__region--category') }}>
{{ content.category }}
</div>
{% endif %}

{% if content.share %}
<div {{ region_attributes.share.addClass('layout__region', 'layout__region--share', 'right-sidebar') }}>
{{ content.share }}

{# Add mobile more items menu #}
{% if content.left_sidebar|render|striptags|trim is not empty %}
<div {{ region_attributes.left_sidebar.addClass('layout__region', 'layout__region--left_sidebar', 'left-sidebar', 'mobile', 'more-on') }}>
<div class="field-label"><a href="#">{{ "More on"|t }}</a></div>
<div class="more-on__items">
{{ content.left_sidebar }}
</div>
</div>
{% endif %}

</div>
{% endif %}
</div>
{% endif %}

<div class="article__main grid margin-top-md">
{% if content.left_sidebar|render|striptags|trim is not empty %}
<div {{ region_attributes.left_sidebar.addClass('layout__region', 'layout__region--left_sidebar', 'left-sidebar', 'more-on') }}>
<div class="field-label">{{ "More on"|t }}</div>
<div class="more-on__items">
{{ content.left_sidebar }}
</div>
</div>
{% endif %}

{% if content.main_content %}
<div {{ region_attributes.main_content.addClass('layout__region', 'layout__region--main_content', 'main-content', 'margin-bottom-xl') }}>
{{ content.main_content }}
</div>
{% endif %}

{% if content.right_sidebar %}
<div {{ region_attributes.right_sidebar.addClass('layout__region', 'layout__region--right_sidebar', 'right-sidebar') }}>
{{ content.right_sidebar }}
</div>
{% endif %}
</div>
</div>
{% endif %}
29 changes: 29 additions & 0 deletions modules/wri_article/wri_article.layouts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
single_file_component_layout:wri_article_columns:
label: "Article columns"
template: templates/wri-article-columns
regions:
hero:
label: Hero
title:
label: Title
byline:
label: Byline
bundle:
label: Bundle
category:
label: Category
share:
label: Share
left_sidebar:
label: "Left"
main_content :
label: "Main Content"
right_sidebar :
label: "Right"
icon_map:
- [hero]
- [title]
- [byline]
- [bundle,category,share]
- [left_sidebar,main_content,right_sidebar']
default_section: main_content
24 changes: 24 additions & 0 deletions modules/wri_article/wri_article.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* @file
* Publication module code.
*/

/**
* Implements hook_preprocess_hook().
*/
function wri_article_preprocess_wri_article_columns(&$context) {
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof \Drupal\node\NodeInterface) {
if (isset($node->field_main_image->entity)) {
$media = $node->field_main_image->entity;
if ($media->hasField('field_attribution') && ($attribution = $media->get('field_attribution')) && !$attribution->isEmpty()) {
$context['content']['byline']['attribution'] = [
'#markup' => '<span class="cover-attribution">' . t('Cover Image by: ') . $attribution->getString() . '</span>',
'#weight' => 10,
];
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<template>
{% if hero.content.field_toc %}
{{ attach_library('wri_toc/tocjs') }}
{% endif %}
Expand Down Expand Up @@ -134,62 +133,5 @@
</div>
</div>
{% endif %}
</template>

<?php

$definition['layout'] = [
'label' => 'Publications',
'regions' => [
'hero' => ['label' => 'Hero'],
'buttons' => ['label' => 'Buttons'],
'category' => ['label' => 'Category'],
'share' => ['label' => 'Share'],
'featured_image' => ['label' => 'Featured Image'],
'main_content' => ['label' => 'Main Content'],
'sidebar' => ['label' => 'Sidebar'],
],
'icon_map' => [
['hero'],
['buttons','featured_image'],
['category','share'],
['main_content','sidebar']
],
'default_section' => 'main_content'
];

$prepareContext = function (&$context) {

$node = \Drupal::routeMatch()->getParameter('node');
$context['show_narrative_taxonomy'] = TRUE;
if ($node instanceof \Drupal\node\NodeInterface) {
$cutOffDate = strtotime('01/01/2020');
$created = $node->getCreatedTime();
$context['display_type'] = 'simple';
$context['node_type'] = $node->getType();

switch ($node->getType()) {
case 'project_detail':
$context['display_type'] = 'robust';
break;

case 'publication':
if ($node->get('field_publication_display')->getString() == 'robust') {
$context['display_type'] = 'robust';
}

if ($cutOffDate > $created) {
$context['show_narrative_taxonomy'] = FALSE;
}
break;

case 'data':
if ($cutOffDate > $created) {
$context['show_narrative_taxonomy'] = FALSE;
}
break;
}
}
};


24 changes: 24 additions & 0 deletions modules/wri_publication/wri_publication.layouts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
single_file_component_layout:wri_publication_columns:
label: Publications
template: templates/wri-publication-columns
regions:
hero:
label: Hero
buttons:
label: Buttons
category:
label: Category
share:
label: Share
featured_image:
label: "Featured Image"
main_content :
label: "Main Content"
sidebar :
label: Sidebar
icon_map:
- [hero]
- [buttons,featured_image]
- [category,share]
- [main_content,sidebar]
default_section: main_content
45 changes: 45 additions & 0 deletions modules/wri_publication/wri_publication.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* @file
* Publication module code.
*/

use Drupal\node\NodeInterface;

/**
* Implements hook_preprocess_hook().
*/
function wri_publication_preprocess_wri_publication_columns(&$context) {

$node = \Drupal::routeMatch()->getParameter('node');
$context['show_narrative_taxonomy'] = TRUE;
if ($node instanceof NodeInterface) {
$cutOffDate = strtotime('01/01/2020');
$created = $node->getCreatedTime();
$context['display_type'] = 'simple';
$context['node_type'] = $node->getType();

switch ($node->getType()) {
case 'project_detail':
$context['display_type'] = 'robust';
break;

case 'publication':
if ($node->get('field_publication_display')->getString() == 'robust') {
$context['display_type'] = 'robust';
}

if ($cutOffDate > $created) {
$context['show_narrative_taxonomy'] = FALSE;
}
break;

case 'data':
if ($cutOffDate > $created) {
$context['show_narrative_taxonomy'] = FALSE;
}
break;
}
}
}

0 comments on commit f2a94f1

Please sign in to comment.