nova-menu-builder
nova-menu-builder copied to clipboard
Feature Request: add method to exclude menu item from list
I’m using a custom MenuItemType, where I’m connecting pages from a Page model to the menu items. When I’m deleting the related page and the "relation" breaks, the menu item is still displaying in Nova as well as in front-end via nova_get_menu_by_slug('my-menu').
Maybe to achieve this by writing return false
(or something similiar):
public static function getValue($value = null, array $data = null, $locale)
{
$page = \App\Page::find($value);
if (!empty($page))
return $page->slug; // success: include
return false; // error: exclude from list
}
inside getDisplayValue
it could be disabled in the list-view.
I have same problem.
Friends, tell me where and how to create a configuration file and how to display the menu in the new admin panel?
I may be a bit late however I hope this might help someone.
Here is how I fixed this issue:
public static function getDisplayValue($value, ?array $data, $locale) { // Example usecase if(!empty(Page::find($value)->name)) { return 'Page: ' . Page::find($value)->name; } else { return 'Page: (not found. This page is probably deleted.)'; } }
public static function getValue($value, ?array $data, $locale) { if(!empty(Page::find($value)->slug)) { return Page::find($value)->slug; } else { return ''; } }
I added the if conditions to both functions. Now if a page is deleted while a page menu item exists in any menu, instead of throwing an error it will simply display a message saying the page is deleted. So it will be easier to identify broken page links in the admin interface. The menu item will still show up in the frontend menu, but that can be fixed with a simple if condition within your menu loop in the frontend.
Added a new function, getEnabledValue
, that can be used to override the enabled value.
Hopefully this solves the issue :)
https://github.com/outl1ne/nova-menu-builder/releases/tag/7.1.0