Skip to content

Commit

Permalink
Merge pull request #182 from openeuropa/OEL-2002
Browse files Browse the repository at this point in the history
OEL-2002: Preserve Drupal links.
  • Loading branch information
brummbar authored Oct 12, 2022
2 parents 13f8197 + 875ef6d commit cc1b850
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 28 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"drupal/daterange_compact": "^2.0",
"drupal/twig_field_value": "^2.0",
"openeuropa/composer-artifacts": "^1.0.0-alpha1",
"openeuropa/oe_bootstrap_theme": "^1.0.0-beta6"
"openeuropa/oe_bootstrap_theme": "0.1.202210121625"
},
"require-dev": {
"composer/installers": "^1.11",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
use Drupal\Core\Url;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
Expand Down Expand Up @@ -121,9 +120,6 @@ public function bclFooterLinks(array $context, array $links): array {
$altered_links = [];

foreach ($links as $link) {
if ($link['href'] instanceof Url) {
$link['href'] = $link['href']->toString();
}
$altered_link = [
'label' => $link['label'],
'path' => $link['href'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ function oe_whitelabel_multilingual_preprocess_links__oe_multilingual_content_la
$variables['languages'] = [];
foreach ($variables['links'] as $language_code => $link) {
/** @var \Drupal\Core\Url $url */
$url = $link['link']['#url'];
$href = $url
$url = $link['link']['#url']
->setOptions($link['link']['#options'])
->setAbsolute(TRUE)
->toString();
->setAbsolute(TRUE);

$variables['languages'][] = [
'path' => $href,
'path' => $url,
'hreflang' => $language_code,
'label' => $link['link']['#title'],
'current' => FALSE,
Expand All @@ -46,7 +44,7 @@ function oe_whitelabel_multilingual_preprocess_links__oe_multilingual_content_la
// saved, so we don't add it to the list.
if ($translation->language()->getId() !== 'und') {
$variables['languages'][] = [
'path' => $translation->toUrl()->setAbsolute(TRUE)->toString(),
'path' => $translation->toUrl()->setAbsolute(TRUE),
'hreflang' => $translation->language()->getId(),
'label' => $languages[$translation->language()->getId()]->getName(),
'current' => TRUE,
Expand Down Expand Up @@ -81,15 +79,13 @@ function oe_whitelabel_multilingual_preprocess_links__language_block(&$variables

foreach ($variables['links'] as $language_code => $link) {
/** @var \Drupal\Core\Url $url */
$url = $link['link']['#url'];
$href = $url
$url = $link['link']['#url']
->setOptions($link['link']['#options'])
->setAbsolute(TRUE)
->toString();
->setAbsolute(TRUE);
$label = $link['link']['#title'];

$link = [
'path' => $href,
'path' => $url,
'name' => $label,
'id' => 'link_' . $language_code,
'label' => $label,
Expand Down
16 changes: 8 additions & 8 deletions modules/oe_whitelabel_paragraphs/oe_whitelabel_paragraphs.module
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function oe_whitelabel_preprocess_paragraph__oe_links_block(array &$variables):
foreach (Element::children($variables['content']['field_oe_links']) as $index) {
$variables['links'][] = [
'label' => $variables['content']['field_oe_links'][$index]['#title'],
'path' => $variables['content']['field_oe_links'][$index]['#url']->toString(),
'path' => $variables['content']['field_oe_links'][$index]['#url'],
];
}
}
Expand All @@ -84,15 +84,15 @@ function oe_whitelabel_preprocess_paragraph__oe_social_media_follow(array &$vari
$variables['links'][$key]['icon']['path'] = $variables['bcl_icon_path'];
$variables['links'][$key]['icon']['name'] = $link['link_type'];
$variables['links'][$key]['label'] = $link['title'];
$variables['links'][$key]['path'] = Url::fromUri($link['uri'])->toString();
$variables['links'][$key]['path'] = Url::fromUri($link['uri']);
}
if (!$paragraph->get('field_oe_social_media_see_more')->isEmpty()) {
$other_link = $paragraph->get('field_oe_social_media_see_more')
->first()
->getValue();
$variables['links'][] = [
'label' => $other_link['title'],
'path' => Url::fromUri($other_link['uri'])->toString(),
'path' => Url::fromUri($other_link['uri']),
];
}
}
Expand Down Expand Up @@ -188,7 +188,7 @@ function oe_whitelabel_preprocess_paragraph__oe_text_feature_media(array &$varia
/** @var \Drupal\link\Plugin\Field\FieldType\LinkItem $link_item */
$link_item = $paragraph->get('field_oe_link')->first();
$variables['link'] = [
'path' => $link_item->getUrl()->toString(),
'path' => $link_item->getUrl(),
'label' => $link_item->get('title')->getValue(),
];
}
Expand Down Expand Up @@ -243,7 +243,7 @@ function oe_whitelabel_preprocess_paragraph__oe_list_item_block(array &$variable
/** @var \Drupal\link\Plugin\Field\FieldType\LinkItem $link_item */
$link_item = $paragraph->get('field_oe_link')->first();
$variables['link'] = $link_item ? [
'path' => $link_item->getUrl()->toString(),
'path' => $link_item->getUrl(),
'label' => $link_item->title,
'icon' => [
'path' => $variables['bcl_icon_path'],
Expand Down Expand Up @@ -435,7 +435,7 @@ function oe_whitelabel_preprocess_paragraph__oe_facts_figures(array &$variables)

if (!$paragraph->get('field_oe_link')->isEmpty()) {
$link_item = $paragraph->get('field_oe_link')->first();
$variables['link_more']['path'] = $link_item->getUrl()->toString();
$variables['link_more']['path'] = $link_item->getUrl();
$variables['link_more']['label'] = $link_item->get('title')->getValue();
}
$variables['items'] = [];
Expand Down Expand Up @@ -525,7 +525,7 @@ function oe_whitelabel_preprocess_paragraph__oe_carousel(array &$variables): voi
/** @var \Drupal\link\Plugin\Field\FieldType\LinkItem $link_item */
$link_item = $sub_paragraph->get('field_oe_link')->first();
$slide['link'] = [
'path' => $link_item->getUrl()->toString(),
'path' => $link_item->getUrl(),
'label' => $link_item->get('title')->getValue(),
];
}
Expand All @@ -550,7 +550,7 @@ function _oe_whitelabel_set_banner_link(Paragraph $paragraph, array &$variables)
}

$link = $paragraph->get('field_oe_link')->first();
$variables['url'] = $link->getUrl()->toString();
$variables['url'] = $link->getUrl();
$variables['label'] = $link->get('title')->getValue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ function _oe_whitelabel_starter_event_preprocess_links(array &$variables): void

$variables['links'] = [
[
'label' => 'Register',
'path' => $url->toString(),
'label' => t('Register'),
'path' => $url,
'icon_position' => 'before',
'icon' => [
'name' => 'calendar-check',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function _oe_whitelabel_starter_person_social_media_links(array &$variables): vo
'name' => $link['link_type'],
],
'label' => $link['title'],
'path' => Url::fromUri($link['uri'])->toString(),
'path' => Url::fromUri($link['uri']),
];
}

Expand Down
2 changes: 1 addition & 1 deletion templates/overrides/search/block--facets-form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{% set extra_attributes = create_attribute() %}
{% set reset = pattern('link', {
'label': content.actions['reset']['#title'],
'path': content.actions['reset']['#url'].toString(),
'path': content.actions['reset']['#url'],
'variant': 'secondary',
'attributes': extra_attributes.addClass(['ms-2', 'btn', 'btn-secondary'])
})
Expand Down

0 comments on commit cc1b850

Please sign in to comment.