Skip to content
Snippets Groups Projects
Commit e3933679 authored by Maria Fisher's avatar Maria Fisher Committed by Viktor Holovachek
Browse files

Issue #3208787: Use the toUrl to create the link (compatibility with Forum module)

parent 2bcff71c
Branches
Tags
1 merge request!1Issue #3208787: Use the toUrl to create the link (compatibility with Forum module)
......@@ -7,7 +7,6 @@
use Drupal\Component\Utility\Html;
use Drupal\Core\Link;
use Drupal\Core\Url;
/**
* Prepares term objects for Twig template.
......@@ -18,29 +17,31 @@ use Drupal\Core\Url;
*/
function template_preprocess_hierarchical_term_formatter(array &$variables) {
$terms = [];
/** @var \Drupal\taxonomy\TermInterface $term */
foreach ($variables['terms'] as $term) {
if ($variables['link']) {
$url = new Url('entity.taxonomy_term.canonical', ['taxonomy_term' => $term->id()]);
$link = Link::fromTextAndUrl($term->getName(), $url);
$link = $link->toRenderable();
$url = $term->toUrl();
$link = Link::fromTextAndUrl($term->label(), $url)->toRenderable();
$terms[] = \Drupal::service('renderer')->render($link);
}
else {
$terms[] = $term->getName();
$terms[] = $term->label();
}
}
if ($variables['wrapper'] != 'none') {
$count = 0;
foreach ($terms as &$term) {
$count++;
$term = [
'#type' => 'html_tag',
'#tag' => (in_array($variables['wrapper'], ['ol', 'ul'])) ? 'li' : $variables['wrapper'],
'#tag' => in_array($variables['wrapper'], ['ol', 'ul']) ? 'li' : $variables['wrapper'],
'#value' => $term,
'#attributes' => [
'class' => [
Html::cleanCssIdentifier('taxonomy-term'),
Html::cleanCssIdentifier("count $count"),
Html::cleanCssIdentifier("count {$count}"),
],
],
];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment