Skip to content

Commit

Permalink
Add tags navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehuran committed Aug 23, 2024
1 parent 0f8bafe commit afb36a2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Resources/views/Shop/Article/_header.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
{% endif %}
</div>

{% include '@MonsieurBizSyliusBlogPlugin/Shop/Tag/list.html.twig' %}

<h1 class="ui monster section dividing header">{{ tag.name|default(('monsieurbiz_blog.ui.' ~ type)|trans) }}</h1>
9 changes: 9 additions & 0 deletions src/Resources/views/Shop/Tag/list.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% set tags = monsieurbiz_blog_tags() %}

{% if tags|length > 0 %}
<div class="ui labels">
{% for tag in tags %}
<a href="{{ path('monsieurbiz_' ~ type ~ '_tag_show', { 'slug': tag.slug }) }}" class="ui tag label">{{ tag.name }}</a>
{% endfor %}
</div>
{% endif %}
43 changes: 43 additions & 0 deletions src/Twig/BlogExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of Monsieur Biz's Blog plugin for Sylius.
* (c) Monsieur Biz <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace MonsieurBiz\SyliusBlogPlugin\Twig;

use MonsieurBiz\SyliusBlogPlugin\Entity\TagInterface;
use MonsieurBiz\SyliusBlogPlugin\Repository\TagRepositoryInterface;
use Sylius\Component\Locale\Context\LocaleContextInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

final class BlogExtension extends AbstractExtension
{
/** @phpstan-ignore-next-line */
public function __construct(
private TagRepositoryInterface $tagRepository,
private LocaleContextInterface $localeContext,
) {
}

public function getFunctions(): array
{
return [
new TwigFunction('monsieurbiz_blog_tags', [$this, 'getTags']),
];
}

/**
* @return TagInterface[]
*/
public function getTags(): array
{
return $this->tagRepository->createEnabledListQueryBuilder($this->localeContext->getLocaleCode())->getQuery()->getResult();
}
}

0 comments on commit afb36a2

Please sign in to comment.