Skip to content

Commit 5c39ec7

Browse files
author
Magnar Eivind Martinsen
committed
Updated landing_page
1 parent d653304 commit 5c39ec7

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

metsis/metsis_lib/src/Controller/DynamicLandingPagesController.php

+21-24
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@
88
use Drupal\Core\Session\AccountInterface;
99
use Drupal\Core\Url;
1010
use Drupal\search_api\Entity\Index;
11-
use Drupal\Core\Cache\CacheBackendInterface;
1211
use Symfony\Component\HttpFoundation\Request;
1312
use Symfony\Component\HttpFoundation\Response;
14-
use Drupal\Core\Cache\CacheFactoryInterface;
15-
use Drupal\Core\Render\RendererInterface;
16-
use Drupal\Core\Render\RenderContext;
17-
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
18-
13+
use Drupal\Core\Cache\CacheBackendInterface;
1914
use Drupal\Core\Cache\Cache;
2015
use Symfony\Component\DependencyInjection\ContainerInterface;
2116
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -111,47 +106,47 @@ class DynamicLandingPagesController extends ControllerBase {
111106
public const LICENCES = [
112107
'CC0-1.0' => [
113108
'url' => 'https://spdx.org/licenses/CC0-1.0',
114-
'img' => '/modules/metsis/metsis_search/icons/CC0.png',
109+
'img' => '/modules/metsis/metsis_search/icons/CC0.webp',
115110
],
116111
'CC-BY-3.0' => [
117112
'url' => 'https://spdx.org/licenses/CC-BY-3.0',
118-
'img' => '/modules/metsis/metsis_search/icons/CCBY.png',
113+
'img' => '/modules/metsis/metsis_search/icons/CCBY.webp',
119114
],
120115
'CC-BY-4.0' => [
121116
'url' => 'https://spdx.org/licenses/CC-BY-4.0',
122-
'img' => '/modules/metsis/metsis_search/icons/CCBY.png',
117+
'img' => '/modules/metsis/metsis_search/icons/CCBY.webp',
123118
],
124119
'CC-BY/NLOD' => [
125120
'url' => 'https://spdx.org/licenses/CC-BY-4.0',
126-
'img' => '"/modules/metsis/metsis_search/icons/CCBY.png',
121+
'img' => '"/modules/metsis/metsis_search/icons/CCBY.webp',
127122
],
128123
'CC BY/NLOD' => [
129124
'url' => 'https://spdx.org/licenses/CC-BY-4.0',
130-
'img' => '/modules/metsis/metsis_search/icons/CCBY.png',
125+
'img' => '/modules/metsis/metsis_search/icons/CCBY.webp',
131126
],
132127
'CC-BY-SA-4.0' => [
133128
'url' => 'https://spdx.org/licenses/CC-BY-SA-4.0',
134-
'img' => '/modules/metsis/metsis_search/icons/CCBYSA.png',
129+
'img' => '/modules/metsis/metsis_search/icons/CCBYSA.webp',
135130
],
136131
'CC-BY-NC-4.0' => [
137132
'url' => 'https://spdx.org/licenses/CC-BY-NC-4.0',
138-
'img' => '/modules/metsis/metsis_search/icons/CCBYNC.png',
133+
'img' => '/modules/metsis/metsis_search/icons/CCBYNC.webp',
139134
],
140135
'CC-BY-NC' => [
141136
'url' => 'https://spdx.org/licenses/CC-BY-NC-4.0',
142-
'img' => '/modules/metsis/metsis_search/icons/CCBYNC.png',
137+
'img' => '/modules/metsis/metsis_search/icons/CCBYNC.webp',
143138
],
144139
'CC-BY-NC-SA-4.0' => [
145140
'url' => 'https://spdx.org/licenses/CC-BY-NC-SA-4.0',
146-
'img' => '/modules/metsis/metsis_search/icons/CCBYNCSA.png',
141+
'img' => '/modules/metsis/metsis_search/icons/CCBYNCSA.webp',
147142
],
148143
'CC-BY-ND-4.0' => [
149144
'url' => 'https://spdx.org/licenses/CC-BY-ND-4.0',
150-
'img' => '/modules/metsis/metsis_search/icons/CCBYND.png',
145+
'img' => '/modules/metsis/metsis_search/icons/CCBYND.webp',
151146
],
152147
'CC-BY-NC-ND-4.0' => [
153148
'url' => 'https://spdx.org/licenses/CC-BY-NC-ND-4.0',
154-
'img' => '/modules/metsis/metsis_search/icons/CCBYNCND.png',
149+
'img' => '/modules/metsis/metsis_search/icons/CCBYNCND.webp',
155150
],
156151
'Not provided' => NULL,
157152
];
@@ -212,7 +207,7 @@ public function getLandingPage(string $id, Request $request) {
212207

213208
$this->getLogger('dynamic_landing_page')->notice("Cache MISS: " . $cid);
214209
// Cache the rendered HTML.
215-
$this->cache->set($cid, $renderArray, [$cid]);
210+
$this->cache->set($cid, $renderArray, CacheBackendInterface::CACHE_PERMANENT, [$cid]);
216211
}
217212
// Handle metadata export.
218213
if (NULL != $request->query->get('export_type')) {
@@ -242,14 +237,15 @@ public function getLandingPage(string $id, Request $request) {
242237
$current_last_modified = strtotime($current_data['timestamp']);
243238

244239
if ($current_last_modified > $last_modified) {
240+
$this->getLogger('dynamic_landing_page')->notice("Landingpage have been updated. Updating cache for: " . $cid);
245241
// Update the cache if the data has changed.
246242
$current_result = $this->generateLandingPage($main_config, $host, $fullhost, $id, $id_prefix, $dataset_id, $export_list);
247243
// Check if the data has changed.
248244
$current_last_modified = $current_result['timestamp'];
249245
$renderArray = $current_result['renderArray'];
250246
$this->cacheInvalidator->invalidateTags([$cid]);
251247

252-
$this->cache->set($cid, $renderArray, [$cid]);
248+
$this->cache->set($cid, $renderArray, CacheBackendInterface::CACHE_PERMANENT, [$cid]);
253249
}
254250

255251
return $renderArray;
@@ -563,13 +559,12 @@ protected function generateLandingPage($main_config, $host, $fullhost, $id, $id_
563559
];
564560
}
565561
if (isset($fields['use_constraint_identifier'])) {
562+
566563
if (NULL != self::LICENCES[$fields['use_constraint_identifier']]) {
567564
$renderArray['constraints_and_info']['constraints']['licence_img'] = [
568565
'#type' => 'markup',
569-
// '#prefix' => '<p>',.
570-
'#markup' => '<a rel="license" class="w3-text-blue" href="' . self::LICENCES[$fields['use_constraint_identifier']]['url'] . '"><img class="w3-image" loading="lazy" width="100" height="35" src="' . self::LICENCES[$fields['use_constraint_identifier']]['img'] . '"/></a>',
571-
// '#suffix' => '</p>',.
572-
'#allowed_tags' => ['img'],
566+
'#markup' => '<a rel="license" class="w3-text-blue" title="Link to license information" href="' . self::LICENCES[$fields['use_constraint_identifier']]['url'] . '"><img loading="lazy" width="100px" height="35px" alt="Use constraint icon for licence ' . $fields['use_constraint_identifier'] . '" ' . 'src = "' . self::LICENCES[$fields['use_constraint_identifier']]['img'] . '" /> </a> ',
567+
'#allowed_tags' => ['a', 'img'],
573568
];
574569
}
575570
else {
@@ -777,12 +772,14 @@ protected function generateLandingPage($main_config, $host, $fullhost, $id, $id_
777772
];
778773
$renderArray['related_information']['collection_image'] = [
779774
'#theme' => 'image',
780-
'#uri' => '/modules/metsis/metsis_search/images/collection.png',
775+
'#uri' => '/modules/metsis/metsis_search/images/collection.webp',
781776
// '#style_name' => 'your_image_style',
782777
'#alt' => 'Collection icon',
783778
// '#title' => $image['ImageTitle'],
784779
'#attributes' => [
785780
'class' => 'align-right',
781+
'width' => '96px',
782+
'height' => '34px',
786783
],
787784
];
788785
}

0 commit comments

Comments
 (0)