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

Add current locale on submit to display preview in right version #256

Merged
merged 1 commit into from
Jan 21, 2025
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
10 changes: 9 additions & 1 deletion src/Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ public function renderElementsAction(Request $request, SwitchAdminLocaleInterfac

/**
* Validate submitted data and return an UI Element JSON if everything is OK.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function submitAction(Request $request, FileUploaderInterface $fileUploader, string $code, bool $isEdition): Response
public function submitAction(Request $request, FileUploaderInterface $fileUploader, SwitchAdminLocaleInterface $switchAdminLocale, string $code, bool $isEdition): Response
{
// Find UI Element from type
try {
Expand All @@ -161,6 +163,12 @@ public function submitAction(Request $request, FileUploaderInterface $fileUpload
throw $this->createNotFoundException($exception->getMessage());
}

// if we have a locale value in the post data, we change the current
// admin locale to make the ui elements in the correct version.
if (($locale = $request->get('locale')) && \is_string($locale)) {
$switchAdminLocale->switchLocale($locale);
}

// Create and validate form
$form = $this->createForm($uiElement->getFormClass(), null, $this->getFormOptions($uiElement));
$form->handleRequest($request);
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/views/Admin/form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
</div>
</div>
<div class="uie-panels__inner ui segment form">
{{ form(form, {'action': url('monsieurbiz_richeditor_admin_form_submit', {'code': uiElement.code, 'isEdition': isEdition})}) }}
{% set locale = form.vars.attr['data-locale']|default(sylius.localeCode) %}
{{ form(form, {'action': url('monsieurbiz_richeditor_admin_form_submit', {'code': uiElement.code, 'isEdition': isEdition, 'locale': locale})}) }}
</div>
Loading