kongondo / MenuBuilder

Easily create navigation lists/menus using drag and drop
GNU General Public License v2.0
21 stars 9 forks source link

Cannot add page when using german language (via Language Support module) #34

Closed digitalbricks closed 6 years ago

digitalbricks commented 7 years ago

First, let me say that i love MenuBuilder! It is a great piece of software and a delight to work with.

But currently working a german site, using Language Support module with german language pack, i encountered the following issue: When i set the language of a user to german, this user isn't able to add pages in MenuBuilder. The user can select a page in the dropdown but after clicking "Speichern" (save) he gets this error:

Der Prozess hat keinen Inhalt ausgegeben.

And therefore the selected page isn't added to the menu tree. When i set the user language back to "default" everything is working as expected.

Probably thats not an issue only related with the german language pack but with the Language Support module. BTW: The original english error message string is "The process returned no content." – maybe that helps for debugging.

digitalbricks commented 7 years ago

Just digging a little bit around in the module code, i think the issue may arise because the module checks for strings like "Save", "Save & Exit" and "Save Unpublished"? (Found in ProcessMenuBuilder.module

kongondo commented 7 years ago

@digitalbricks. Thanks for reporting this. You are probably right the issue is caused by the strings such as "Save". I've always wanted to change those due to issues like the one you've encountered but it always slips my mind! Are you able to please test for me? If you could change the values of those buttons to integers, 1, 2, 3, etc and see if the menu saves OK? Thanks. If that resolves the issue, I'll change the code to send integers rather than strings.

digitalbricks commented 7 years ago

@kongondo Yes of course I can test for you but i am not very informed how ProcessWire modules are working. But i have a suggestion:

I checked how Ryan handles the "Save", "Save & Exit" etc. events in his Hanna Code module and as it seems, he is NOT checking the actual value of the button but the presence of the buttons name-attribute in the HTTP Post:

if($input->post('hc_save') || $input->post('hc_save_exit') || $input->post('hc_save_test')) $this->save($form);

(See line 566 in ProcessHannaCode.module)

So, in case of MenuBuilder, you may just need to check for $input->post('menu_save'), $input->post('menu_save_exit') and so on?

digitalbricks commented 7 years ago

I think i fixed it:

Just replace that lines (1433 - 1442) ...

// save new menu(s)
if (($newUnpublishedBtn && $newUnpublishedBtn == 'Save Unpublished') || ($newPublishedBtn && $newPublishedBtn == 'Publish') ){
    $this->saveNewMenu($post);
}
// menus bulk actions: lock/unlock and trash/delete are controlled by permissions
elseif($actionsMenusBtn && $actionsMenusBtn == 'Apply') $this->bulkActionsMenu($post);
// save single specified menu
elseif($saveBtn == 'Save'|| $saveAndExitBtn == 'Save & Exit') $this->saveSingleMenu($menuID, $post);
// delete menu
elseif ($menuDelete) $this->menuDelete($menuDeleteConfirm);// end elseif delete menu

... with that ones:

$input = $this->input;
// save new menu(s)
if ($input->post('menu_new_unpublished_btn') || $input->post('menu_new_published_btn') ){
    $this->saveNewMenu($post);
}
// menus bulk actions: lock/unlock and trash/delete are controlled by permissions
elseif($input->post('menus_action_btn')) $this->bulkActionsMenu($post);
// save single specified menu
elseif($input->post('menu_save')|| $input->post('menu_save_exit')) $this->saveSingleMenu($menuID, $post);
// delete menu
elseif ($menuDelete) $this->menuDelete($menuDeleteConfirm);// end elseif delete menu

In my test scenario, using the german language pack, now editors are able to modify menus.

Because the buttons "Publish" and "Save unpublished" aren't translated for some reason, there is no urgent need to replace the check for that both strings with the check for the name attribute – but i did it anyway for convenience.

For sure, the code needs a litte bit more refactoring because now, using $input, some other variables became obsolete. But this quick fix worked for me and should solve similar problems using different languages.

Erbenos commented 7 years ago

I edited it like this:


// save new menu(s)
if (($newUnpublishedBtn && $newUnpublishedBtn == $this->_('Save Unpublished')) || ($newPublishedBtn && $newPublishedBtn == $this->_('Publish')) ){
    $this->saveNewMenu($post);
}
// menus bulk actions: lock/unlock and trash/delete are controlled by permissions
elseif($actionsMenusBtn && $actionsMenusBtn == $this->_('Apply')) $this->bulkActionsMenu($post);
// save single specified menu
elseif($saveBtn == $this->_('Save')|| $saveAndExitBtn == $this->_('Save & Exit')) $this->saveSingleMenu($menuID, $post);
// delete menu
elseif ($menuDelete) $this->menuDelete($menuDeleteConfirm);// end elseif delete menu

works with Czech

kongondo commented 6 years ago

Thanks @digitalbricks and @Erbenos. This has been resolved in the latest commit.