Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from City-of-Helsinki/UHF-X-change-link-template
Browse files Browse the repository at this point in the history
Use link template for link
  • Loading branch information
tuutti authored Nov 18, 2021
2 parents ba9adff + ec9e854 commit 183e053
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
12 changes: 12 additions & 0 deletions helfi_media_map.module
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,15 @@ function helfi_media_map_entity_bundle_field_info_alter(&$fields, EntityTypeInte
}
}
}

/**
* Implements hook_theme().
*/
function helfi_media_map_theme($existing, $type, $theme, $path) {
return [
'helfi_media_map' => [
'variables' => ['link' => NULL, 'iframe' => NULL],
'template' => 'helfi-media-map'
],
];
}
19 changes: 9 additions & 10 deletions src/Plugin/Field/FieldFormatter/MediaMapFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\helfi_media_map\UrlParserTrait;

/**
Expand Down Expand Up @@ -51,15 +52,16 @@ public function settingsForm(array $form, FormStateInterface $form_state) : arra
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
public function viewElements(FieldItemListInterface $items, $langcode) :array {
$element = [];

foreach ($items as $delta => $item) {
['uri' => $uri, 'title' => $title] = $item->getValue();
$link = $this->getMapUrl($uri);

$element[$delta] = [
'iframe' => [
'#theme' => 'helfi_media_map',
'#iframe' => [
'#type' => 'html_tag',
'#tag' => 'iframe',
'#value' => '',
Expand All @@ -72,14 +74,11 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
];

if ($link_title = $this->getSetting('link_title')) {
$element[$delta]['link'] = [
'#type' => 'html_tag',
'#tag' => 'a',
'#value' => $link_title,
'#attributes' => [
'href' => $link,
'target' => '_blank',
],
$element[$delta]['#link'] = [
'#type' => 'link',
'#title' => $link_title,
'#url' => Url::fromUri($link),
'#attributes' => ['target' => '_blank'],
];
}
}
Expand Down
2 changes: 2 additions & 0 deletions templates/helfi-media-map.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{ iframe }}
{{ link }}

0 comments on commit 183e053

Please sign in to comment.