Skip to content

Commit

Permalink
fixed multilingual category editing problem (#3834)
Browse files Browse the repository at this point in the history
* fixed multilingual category editing problem

* updated changelog entry
  • Loading branch information
Guite committed Oct 25, 2017
1 parent 39d9ebe commit a4428eb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-1.5.md
Expand Up @@ -10,6 +10,7 @@ CHANGELOG - ZIKULA 1.5.x
- Added missing action icons to admin menu sub entries and admin panel module links.
- Fixed locale determination in legacy url creation.
- Fixed admin category creation issues (#3826, #3827).
- Fixed multilingual category editing problem.

- Vendor updates:
- composer/ca-bundle updated from 1.0.7 to 1.0.8
Expand Down
7 changes: 4 additions & 3 deletions src/system/CategoriesModule/Controller/NodeController.php
Expand Up @@ -62,8 +62,9 @@ public function contextMenuAction(Request $request, $action = 'edit', CategoryEn
$category = $newCategory;
// intentionally no break here
case 'edit':
$localeApi = $this->get('zikula_settings_module.locale_api');
if (!isset($category)) {
$category = new CategoryEntity($this->get('zikula_settings_module.locale_api')->getSupportedLocales());
$category = new CategoryEntity($localeApi->getSupportedLocales());
$parentId = $request->request->get('parent');
$mode = 'new';
if (!empty($parentId)) {
Expand All @@ -78,7 +79,7 @@ public function contextMenuAction(Request $request, $action = 'edit', CategoryEn
}
$form = $this->createForm(CategoryType::class, $category, [
'translator' => $this->get('translator.default'),
'locales' => $this->get('zikula_settings_module.locale_api')->getSupportedLocales(),
'locales' => $localeApi->getSupportedLocales(),
]);
$form->get('after')->setData($request->request->get('after', null));
if ($form->handleRequest($request)->isValid()) {
Expand All @@ -99,7 +100,7 @@ public function contextMenuAction(Request $request, $action = 'edit', CategoryEn
}
$response = [
'result' => $this->renderView('@ZikulaCategoriesModule/Category/edit.html.twig', [
'locales' => $this->get('zikula_settings_module.locale_api')->getSupportedLocaleNames(null, $request->getLocale()),
'locales' => $localeApi->getSupportedLocaleNames(null, $request->getLocale()),
'form' => $form->createView()
]),
'action' => $action,
Expand Down
27 changes: 27 additions & 0 deletions src/system/CategoriesModule/Form/Type/CategoryType.php
Expand Up @@ -91,18 +91,45 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'mapped' => false,
'required' => false
])
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) {
// ensure all display name and description exist for all locales
/** @var CategoryEntity $category */
$category = $event->getData();

$name = $category->getName();

$displayName = $category->getDisplay_name();
$displayDesc = $category->getDisplay_desc();

foreach ($options['locales'] as $code) {
if (!isset($displayName[$code]) || !$displayName[$code]) {
$displayName[$code] = $options['translator']->__(/** @Ignore */$name, 'zikula', $code);
}
if (!isset($displayDesc[$code])) {
$displayDesc[$code] = '';
}
}

$category->setDisplay_name($displayName);
$category->setDisplay_desc($displayDesc);

$event->setData($category);
})
->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) use ($options) {
// ensure all locales have a display name
/** @var CategoryEntity $category */
$category = $event->getData();

$name = $category->getName();
$displayName = $category->getDisplay_name();

foreach ($options['locales'] as $code) {
if (!isset($displayName[$code]) || !$displayName[$code]) {
$displayName[$code] = $options['translator']->__(/** @Ignore */$name, 'zikula', $code);
}
}
$category->setDisplay_name($displayName);

$event->setData($category);
})
;
Expand Down
Expand Up @@ -25,8 +25,8 @@
<div class="tab-content">
{% for name, code in locales %}
<div role="tabpanel" class="tab-pane{% if code == app.request.locale %} active{% endif %}" id="{{ code }}">
{{ form_row(form.display_name[code], {'label': form.display_name.vars.label ~ ' (' ~ code ~ ')' }) }}
{{ form_row(form.display_desc[code], {'label': form.display_desc.vars.label ~ ' (' ~ code ~ ')' }) }}
{{ form_row(form.display_name[code], {label: form.display_name.vars.label ~ ' (' ~ code ~ ')' }) }}
{{ form_row(form.display_desc[code], {label: form.display_desc.vars.label ~ ' (' ~ code ~ ')' }) }}
</div>
{% endfor %}
</div>
Expand Down

0 comments on commit a4428eb

Please sign in to comment.