Skip to content

Commit fc99d03

Browse files
author
Ben Thomson
authored
Pass menu item data as JSON object (#439)
Instead of using normal post data, this translates the menu item data to a JSON string and sends through the data as a single data blob. This should circumvent issues with large menus and the PHP "max_input_vars" limit. Fixes #422
1 parent 989816d commit fc99d03

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

assets/js/pages-page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@
550550
return result
551551
}
552552

553-
data.options.data['itemData'] = iterator($items)
553+
data.options.data['itemData'] = JSON.stringify(iterator($items))
554554
}
555555

556556
/*

controllers/Index.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,19 @@ public function __construct()
5959
new PageList($this, 'pageList');
6060
$this->vars['activeWidgets'][] = 'pageList';
6161
}
62-
62+
6363
if ($this->user->hasAccess('rainlab.pages.manage_menus')) {
6464
new MenuList($this, 'menuList');
6565
$this->vars['activeWidgets'][] = 'menuList';
6666
}
67-
67+
6868
if ($this->user->hasAccess('rainlab.pages.manage_content')) {
6969
new TemplateList($this, 'contentList', function() {
7070
return $this->getContentTemplateList();
7171
});
7272
$this->vars['activeWidgets'][] = 'contentList';
7373
}
74-
74+
7575
if ($this->user->hasAccess('rainlab.pages.access_snippets')) {
7676
new SnippetList($this, 'snippetList');
7777
$this->vars['activeWidgets'][] = 'snippetList';
@@ -748,6 +748,11 @@ protected function fillObjectFromPost($type)
748748
// If no item data is sent through POST, this means the menu is empty
749749
if (!isset($objectData['itemData'])) {
750750
$objectData['itemData'] = [];
751+
} else {
752+
$objectData['itemData'] = json_decode($objectData['itemData'], true);
753+
if (json_last_error() !== JSON_ERROR_NONE || !is_array($objectData['itemData'])) {
754+
$objectData['itemData'] = [];
755+
}
751756
}
752757
}
753758

0 commit comments

Comments
 (0)