Skip to content

Commit

Permalink
feat: add current locale on submit to display preview in right version
Browse files Browse the repository at this point in the history
  • Loading branch information
delyriand committed Jan 21, 2025
1 parent 9bc3f81 commit cf8269f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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>

0 comments on commit cf8269f

Please sign in to comment.