Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use channel default locale for preview from grid + add menu for local for show in shop #60

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@

namespace MonsieurBiz\SyliusCmsPagePlugin\Controller;

use MonsieurBiz\SyliusRichEditorPlugin\Switcher\SwitchAdminLocaleInterface;
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
use Sylius\Component\Resource\ResourceActions;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class PageController extends ResourceController
{
public function previewAction(Request $request): Response
public function previewAction(Request $request, SwitchAdminLocaleInterface $switchAdminLocale): Response
{
// Switch the locale of the preview to the default locale of the channel to not take the locale of the admin
if ($locale = $request->getDefaultLocale()) {
$switchAdminLocale->switchLocale($locale);
}
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request);

$this->isGrantedOr403($configuration, ResourceActions::SHOW);
Expand Down
27 changes: 21 additions & 6 deletions src/Resources/views/Admin/Page/_showInShopButton.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,27 @@
</div>
</div>
{% else %}
{% for channel in enabledChannels %}
{% 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}) %}
<a class="ui labeled icon button" href="{{ url|raw }}" target="_blank">
<i class="angle right icon"></i>
<div class="ui floating dropdown labeled icon button">
<i class="share alternate icon"></i>
<span class="text">
{{ 'monsieurbiz_cms_page.ui.show_page_in_shop_page'|trans }}
</a>
{% endfor %}
</span>
<div class="menu">
<div class="scrolling menu">
{% for channel in enabledChannels %}
{% for locale in channel.locales %}
{% set localeCode = locale.code %}
{% set translationResource = resource.getTranslation(localeCode)|default(resource) %}
{% 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}) %}
<a href="{{ url|raw }}" class="item" target="_blank">
<i class="angle right icon"></i>
{{ 'monsieurbiz_cms_page.ui.show_in'|trans }}
{{ channel.name }} ({{ channel.code }}) ({{ localeCode }})
</a>
{% endfor %}
{% endfor %}
</div>
</div>
</div>
{% endif %}
{% endif %}
Loading