nova-menu-builder icon indicating copy to clipboard operation
nova-menu-builder copied to clipboard

Feature Request: add method to exclude menu item from list

Open JonathanDoelan opened this issue 4 years ago • 3 comments

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.

JonathanDoelan avatar Nov 18 '20 17:11 JonathanDoelan

I have same problem.

EgoRoman avatar Oct 13 '21 14:10 EgoRoman

Friends, tell me where and how to create a configuration file and how to display the menu in the new admin panel?

arhitektorr avatar Jun 01 '22 08:06 arhitektorr

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.

samah5751 avatar Aug 27 '22 17:08 samah5751

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

KasparRosin avatar Oct 21 '22 12:10 KasparRosin