-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add terms_link twig function to output terms links
- Loading branch information
Showing
9 changed files
with
119 additions
and
3 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
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
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,18 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<services> | ||
<service id="setono_sylius_terms.twig.terms_extension" class="Setono\SyliusTermsPlugin\Twig\TermsExtension"> | ||
<tag name="twig.extension"/> | ||
</service> | ||
|
||
<service id="setono_sylius_terms.twig.terms_runtime" class="Setono\SyliusTermsPlugin\Twig\TermsRuntime"> | ||
<argument type="service" id="sylius.context.channel"/> | ||
<argument type="service" id="sylius.context.locale"/> | ||
<argument type="service" id="setono_sylius_terms.repository.terms"/> | ||
|
||
<tag name="twig.runtime"/> | ||
</service> | ||
</services> | ||
</container> |
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,2 @@ | ||
{# @var terms \Setono\SyliusTermsPlugin\Model\TermsInterface #} | ||
<a href="{{ path('setono_sylius_terms_shop_show_terms', {'slug': terms.slug}) }}">{{ terms.name }}</a> |
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusTermsPlugin\Twig; | ||
|
||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFunction; | ||
|
||
final class TermsExtension extends AbstractExtension | ||
{ | ||
/** | ||
* @return list<TwigFunction> | ||
*/ | ||
public function getFunctions(): array | ||
{ | ||
return [ | ||
new TwigFunction('terms_link', [TermsRuntime::class, 'link'], ['needs_environment' => true, 'is_safe' => ['html']]), | ||
]; | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusTermsPlugin\Twig; | ||
|
||
use Setono\SyliusTermsPlugin\Repository\TermsRepositoryInterface; | ||
use Sylius\Component\Channel\Context\ChannelContextInterface; | ||
use Sylius\Component\Locale\Context\LocaleContextInterface; | ||
use Twig\Environment; | ||
use Twig\Extension\RuntimeExtensionInterface; | ||
|
||
final class TermsRuntime implements RuntimeExtensionInterface | ||
{ | ||
public function __construct( | ||
private readonly ChannelContextInterface $channelContext, | ||
private readonly LocaleContextInterface $localeContext, | ||
private readonly TermsRepositoryInterface $termsRepository, | ||
) { | ||
} | ||
|
||
/** | ||
* Returns a <a href="...">...</a> link to the terms if the given terms code exists | ||
* else it returns an empty string | ||
*/ | ||
public function link(Environment $env, string $code, string $template = null): string | ||
{ | ||
$terms = $this->termsRepository->findOneByChannelAndLocaleAndCode( | ||
$this->channelContext->getChannel(), | ||
$this->localeContext->getLocaleCode(), | ||
$code, | ||
); | ||
|
||
$template ??= '@SetonoSyliusTermsPlugin/shop/terms/link.html.twig'; | ||
|
||
return $env->render($template, [ | ||
'terms' => $terms, | ||
]); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...s/Application/templates/bundles/SyliusShopBundle/Layout/Footer/Grid/_your_store.html.twig
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 @@ | ||
<div class="four wide column"> | ||
<h4 class="ui inverted header">{{ 'sylius.ui.your_store'|trans }}</h4> | ||
<div class="ui inverted link list"> | ||
<a href="#" class="item">{{ 'sylius.ui.about'|trans }}</a> | ||
{{ terms_link('terms_and_conditions') }} | ||
<a href="#" class="item">{{ 'sylius.ui.privacy_policy'|trans }}</a> | ||
<a href="{{ path('sylius_shop_contact_request') }}" class="item">{{ 'sylius.ui.contact_us'|trans }}</a> | ||
</div> | ||
</div> |