Skip to content

Commit

Permalink
Make maxDepth configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarpsvo committed May 14, 2021
1 parent 89df672 commit 654144e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/nova-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
// 'header' => [
// 'name' => 'Header',
// 'unique' => true,
// 'max_depth' => 10,
// 'menu_item_types' => []
// ]
],
Expand Down
6 changes: 6 additions & 0 deletions resources/js/components/MenuBuilder.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<vue-nestable
:value="value"
:max-depth="maxDepth"
@input="val => $emit('input', val)"
@change="$emit('onMenuChange')"
class="px-3 menu-builder"
Expand Down Expand Up @@ -84,6 +85,11 @@ export default {
type: Array,
required: true,
},
maxDepth: {
type: Number,
required: false,
default: 10,
},
},
components: {
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/MenuBuilderField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@onMenuChange="updateMenu"
@removeMenu="removeMenu"
@saveMenuLocalState="saveMenuLocalState"
:max-depth="field.maxDepth"
v-model="menuItems"
/>

Expand Down
5 changes: 5 additions & 0 deletions src/MenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,9 @@ public static function getMenus()
{
return config('nova-menu.menus', []);
}

public static function getMenuConfig($slug)
{
return config("nova-menu.menus.{$slug}", []);
}
}
8 changes: 7 additions & 1 deletion src/Nova/Fields/MenuBuilderField.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ class MenuBuilderField extends Field
public function __construct($name, $attribute = null, callable $resolveCallback = null)
{
$this->withMeta([
'locales' => MenuBuilder::getLocales()
'locales' => MenuBuilder::getLocales(),
'maxDepth' => 10,
]);
}

public function maxDepth($maxDepth = 10)
{
return $this->withMeta(['maxDepth' => $maxDepth]);
}
}
4 changes: 4 additions & 0 deletions src/Nova/Resources/MenuResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function fields(Request $request)
})
->toArray();

$maxDepth = 10;
if ($this->slug) $maxDepth = MenuBuilder::getMenuConfig($this->slug)['max_depth'] ?? 10;

return [
Text::make(__('novaMenuBuilder.nameFieldName'), 'name')
->sortable()
Expand All @@ -73,6 +76,7 @@ public function fields(Request $request)
Panel::make(__('novaMenuBuilder.menuItemsPanelName'), [
MenuBuilderField::make('', 'menu_items')
->hideWhenCreating()
->maxDepth($maxDepth)
->readonly(),
])
];
Expand Down

0 comments on commit 654144e

Please sign in to comment.