Skip to content

Commit 829ce3f

Browse files
authored
Merge pull request #571 from UN-OCHA/develop
Deploy 31/01/2022 IASC-725
2 parents 30825fc + c9464ef commit 829ce3f

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

html/themes/custom/iasc_common_design/iasc_common_design.theme

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
use Drupal\Core\Form\FormStateInterface;
9+
use Drupal\media\Entity\Media;
910

1011
/**
1112
* Implements template_preprocess_field().
@@ -125,6 +126,17 @@ function iasc_common_design_preprocess_node(&$variables) {
125126
$variables['event_time']['output'] = $variables['event_time']['start'] . ' — ' . $variables['event_time']['end'] . ' (' . $variables['event_time']['timezone'] . ')';
126127
}
127128
}
129+
130+
$bundle = $node->bundle();
131+
132+
if ($bundle == 'oa_wiki_page' && ($variables['elements']['#view_mode'] == 'teaser' || $variables['elements']['#view_mode'] == 'title')) {
133+
$document_file = $node->get('field_media_files')->getValue();
134+
135+
if (!empty($document_file)) {
136+
$entity = Media::load($document_file[0]['target_id']);
137+
$variables['document_file'] = $entity->field_media_file->entity->createFileUrl();
138+
}
139+
}
128140
}
129141

130142
/**

html/themes/custom/iasc_common_design/templates/node/node--oa-wiki-page--teaser.html.twig

+1-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
%}
8484
{{ attach_library('common_design/cd-teaser') }}
8585

86-
{% set fileUrl = node.field_media_files.0.entity.uri.value ? file_url(node.field_media_files.0.entity.uri.value) : url %}
8786
{% set showPage = node.field_oa_wiki_page_no_redirect.0.value %}
8887

8988
<article{{ attributes.addClass(classes) }}>
@@ -101,7 +100,7 @@
101100
{% if showPage %}
102101
<a href="{{ url }}" rel="bookmark">{{ label }}</a>
103102
{% else %}
104-
<a href="{{ fileUrl }}" title="Download">{{ label }}</a>
103+
<a href="{{ document_file }}" title="Download">{{ label }}</a>
105104
{% endif %}
106105
</h3>
107106
{% endif %}

html/themes/custom/iasc_common_design/templates/node/node--oa-wiki-page--title.html.twig

+8-9
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,16 @@
7272
#}
7373
{%
7474
set classes = [
75-
'node',
76-
'node--type-' ~ node.bundle|clean_class,
77-
node.isPromoted() ? 'node--promoted',
78-
node.isSticky() ? 'node--sticky',
79-
not node.isPublished() ? 'node--unpublished',
80-
view_mode ? 'node--view-mode-' ~ view_mode|clean_class
81-
]
75+
'node',
76+
'node--type-' ~ node.bundle|clean_class,
77+
node.isPromoted() ? 'node--promoted',
78+
node.isSticky() ? 'node--sticky',
79+
not node.isPublished() ? 'node--unpublished',
80+
view_mode ? 'node--view-mode-' ~ view_mode|clean_class
81+
]
8282
%}
8383
{{ attach_library('common_design/cd-bullet-list') }}
8484

85-
{% set fileUrl = node.field_media_files.0.entity.uri.value ? file_url(node.field_media_files.0.entity.uri.value) : url %}
8685
{% set showPage = node.field_oa_wiki_page_no_redirect.0.value %}
8786

8887
<article{{ attributes.addClass(classes) }}>
@@ -91,7 +90,7 @@
9190
{% if showPage %}
9291
<a href="{{ url }}" rel="bookmark">
9392
{% else %}
94-
<a href="{{ fileUrl }}" title="Download">
93+
<a href="{{ document_file }}" title="Download">
9594
{% endif %}
9695
{{ label }}
9796
</a>

0 commit comments

Comments
 (0)