Skip to content

Commit 8fe293a

Browse files
authored
Merge pull request #60 from etienne-monsieurbiz/feature/preview-default-locale
Use channel default locale for preview from grid + add menu for local for show in shop
2 parents 5dbd82f + d22ee4f commit 8fe293a

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/Controller/PageController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313

1414
namespace MonsieurBiz\SyliusCmsPagePlugin\Controller;
1515

16+
use MonsieurBiz\SyliusRichEditorPlugin\Switcher\SwitchAdminLocaleInterface;
1617
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
1718
use Sylius\Component\Resource\ResourceActions;
1819
use Symfony\Component\HttpFoundation\Request;
1920
use Symfony\Component\HttpFoundation\Response;
2021

2122
class PageController extends ResourceController
2223
{
23-
public function previewAction(Request $request): Response
24+
public function previewAction(Request $request, SwitchAdminLocaleInterface $switchAdminLocale): Response
2425
{
26+
// Switch the locale of the preview to the default locale of the channel to not take the locale of the admin
27+
if ($locale = $request->getDefaultLocale()) {
28+
$switchAdminLocale->switchLocale($locale);
29+
}
2530
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
2631

2732
$this->isGrantedOr403($configuration, ResourceActions::SHOW);

src/Resources/views/Admin/Page/_showInShopButton.html.twig

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,27 @@
2626
</div>
2727
</div>
2828
{% else %}
29-
{% for channel in enabledChannels %}
30-
{% set url = channel.hostname is not null ? 'http://' ~ channel.hostname ~ path('monsieurbiz_cms_page_show', {'slug': resource.slug, '_locale': channel.defaultLocale.code}) : url('monsieurbiz_cms_page_show', {'slug': resource.slug, '_locale': channel.defaultLocale.code}) %}
31-
<a class="ui labeled icon button" href="{{ url|raw }}" target="_blank">
32-
<i class="angle right icon"></i>
29+
<div class="ui floating dropdown labeled icon button">
30+
<i class="share alternate icon"></i>
31+
<span class="text">
3332
{{ 'monsieurbiz_cms_page.ui.show_page_in_shop_page'|trans }}
34-
</a>
35-
{% endfor %}
33+
</span>
34+
<div class="menu">
35+
<div class="scrolling menu">
36+
{% for channel in enabledChannels %}
37+
{% for locale in channel.locales %}
38+
{% set localeCode = locale.code %}
39+
{% set translationResource = resource.getTranslation(localeCode)|default(resource) %}
40+
{% set url = channel.hostname is not null ? 'http://' ~ channel.hostname ~ path('monsieurbiz_cms_page_show', {'slug': translationResource.slug, '_locale': localeCode}) : url('monsieurbiz_cms_page_show', {'slug': translationResource.slug, '_locale': localeCode}) %}
41+
<a href="{{ url|raw }}" class="item" target="_blank">
42+
<i class="angle right icon"></i>
43+
{{ 'monsieurbiz_cms_page.ui.show_in'|trans }}
44+
{{ channel.name }} ({{ channel.code }}) ({{ localeCode }})
45+
</a>
46+
{% endfor %}
47+
{% endfor %}
48+
</div>
49+
</div>
50+
</div>
3651
{% endif %}
3752
{% endif %}

0 commit comments

Comments
 (0)