-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f8bafe
commit afb36a2
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |