Skip to content

Commit e06e0b6

Browse files
authored
Merge pull request #1288 from UN-OCHA/aessid/HPC-10017
HPC-10017: Visual bug in related article element that don't have images.
2 parents f3b3aae + 309da1f commit e06e0b6

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

html/modules/custom/ghi_blocks/src/Plugin/Block/Generic/Links.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,15 @@ public function buildContent() {
6262
$item_type = $this->getItemTypePluginForColumn($item, $context);
6363
$rendered[] = $item_type->getRenderArray();
6464
}
65+
66+
$rendered = array_filter($rendered);
67+
if (empty($rendered)) {
68+
return NULL;
69+
}
70+
6571
$build = [
6672
'#theme' => 'item_list',
67-
'#items' => array_filter($rendered),
73+
'#items' => $rendered,
6874
'#attributes' => [
6975
'class' => ['links'],
7076
],

html/modules/custom/ghi_blocks/src/Plugin/ConfigurationContainerItem/Link.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public function getRenderArray() {
304304
'#link' => $link->toRenderable(),
305305
];
306306
$file = $this->loadFile();
307-
if ($file) {
307+
if ($file && file_exists($file->getFileUri())) {
308308
$image_style = 'card_hero';
309309
if ($this->config['image']['crop_type'] == 'paper_size') {
310310
$image_style = 'paper_size';
@@ -432,4 +432,15 @@ private function loadFile($file_id = NULL) {
432432
return $file_id ? $this->entityTypeManager->getStorage('file')->load($file_id) : NULL;
433433
}
434434

435+
/**
436+
* {@inheritdoc}
437+
*/
438+
public function getConfigurationErrors() {
439+
$errors = [];
440+
if (!$this->getRenderArray()) {
441+
$errors[] = $this->t('The link cannot be rendered. Verify that the target page is publicly available.');
442+
}
443+
return $errors;
444+
}
445+
435446
}

html/themes/custom/common_design_subtheme/css/styles.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

html/themes/custom/common_design_subtheme/sass/component-overrides/_gho-related-articles.scss

+9
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,14 @@
1515
/* The 2.25rem are for the padding of the text */
1616
width: calc(40% - 2.25rem);
1717
min-width: 320px;
18+
19+
[dir="ltr"] .gho-related-article .field--name-field-image {
20+
padding-right: 2.25rem;
21+
padding-left: 0;
22+
}
23+
[dir="rtl"] .gho-related-article .field--name-field-image {
24+
padding-right: 0;
25+
padding-left: 2.25rem;
26+
}
1827
}
1928
}

html/themes/custom/common_design_subtheme/sass/ghi/blocks/_links.scss

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
}
88

99
div.link-box {
10-
gap: 1rem;
1110
padding: 0 !important;
1211
border: 1px solid var(--ghi-default-border-color) !important;
1312

0 commit comments

Comments
 (0)