Site Menus - Menu
Site Menus are designed to allow admins limited access to modify menus across the site, using the CMS.
Menus
The Enso install script includes a seeder for two default Menus, main-navigation and footer.
Users are able to name menus and change the slug of existing menu's that aren't protected in the controller.
By default, further settings are restricted to users who are either Superusers, or have the site-menu-create and site-menu-update permissions. Additional settings are:
- slug - Users with the correct permissions can alter the slugs of protected menus
- max_visible_items - Max number of items before the menu should be condensed into a burger menu
- max_items - Max number of items this menu can have
Menus, their crud and their controller are bound to contracts. If you need to alter their functionality, you can implement your own and bind to that. Until such time as Enso is able to use the class of a contract in it's config files, you will also need to update these with the concrete classes if updating.
Menu Items
Menu Items represent a link in a menu.
Admins are able to add, remove, edit and reorder these as a Flexible content field on the menu to be edited.
On saving, the URL field on menu items is parsed and where possible, local addresses are converted to links relative to the site. If your site is test.com, the url http://test.com/tests/to/make will be saved as just /tests/to/make. This happens for urls which begin with:
https://LOCAL_DOMAINhttp://LOCAL_DOMAIN//LOCAL_DOMAINLOCAL_DOMAIN
A preceeding forward slash is added to addresses which are not full urls (begins with https://, http:// or //) for the same reason. Thus, an empty url will become '/', and a url of 'about' will become '/about'. The onlt exception to this is urls with a prefix such as mailto: or tel: (any characters string followed by a colon), which are left as is.
If no target is provided it will be guessed at during saving. If, after parsing, the url is still a full url, it will default to opening in a new window. Otherwise, it is most likely an on-site link and will open in the same tab.
Accessing Menus
Get a menu from the database
use SiteMenu;
$menu = SiteMenu::get('main-navigation');
Output items in a view
@foreach
<a href="{{ $item->url }}" target="{{ $item->target }}" {{ $item->target === '_blank' ? 'rel="noopener noreferrer"' : '' }}>{{ $item->label }}</a>
@endforeach