All Projects → optimistdigital → Nova Menu Builder

optimistdigital / Nova Menu Builder

Licence: mit
This Laravel Nova package allows you to create and manage menus and menu items.

Labels

Projects that are alternatives of or similar to Nova Menu Builder

Nova Renderer
Nova Renderer, a custom cross platform render engine written in C++
Stars: ✭ 619 (+452.68%)
Mutual labels:  nova
Nova Custom Email Sender
A Laravel Nova tool that sends ad-hoc email messages from the dashboard.
Stars: ✭ 62 (-44.64%)
Mutual labels:  nova
Nova Map Marker Field
Provides an visual interface for editing latitude and longitude coordinates.
Stars: ✭ 96 (-14.29%)
Mutual labels:  nova
Nova Laravel Update Card
Check if you're running the latest Laravel version right from your Nova dashboard.
Stars: ✭ 34 (-69.64%)
Mutual labels:  nova
Nova Route Viewer
Route viewer tool for Laravel Nova
Stars: ✭ 54 (-51.79%)
Mutual labels:  nova
Nova Stripe Theme
A Laravel Nova theme closely resembling Stripe.
Stars: ✭ 71 (-36.61%)
Mutual labels:  nova
Menu
Html menu generator
Stars: ✭ 539 (+381.25%)
Mutual labels:  menus
Nova Tail Tool
A Laravel Nova tool to display the application log
Stars: ✭ 110 (-1.79%)
Mutual labels:  nova
Laravel Nova Permission
A Laravel Nova tool for the Spatie Permission package
Stars: ✭ 59 (-47.32%)
Mutual labels:  nova
Awesome Nova
🎉 A curated list of awesome things related to Laravel Nova
Stars: ✭ 92 (-17.86%)
Mutual labels:  nova
Flyoutmenus
Simple material-style flyout menus for Android. There are many flyout type menus for Android, but this one is mine.
Stars: ✭ 995 (+788.39%)
Mutual labels:  menus
Nova Mega Filter
Allows you to control the columns and filters shown on any Nova resource index
Stars: ✭ 49 (-56.25%)
Mutual labels:  nova
Tty Prompt
A beautiful and powerful interactive command line prompt
Stars: ✭ 1,210 (+980.36%)
Mutual labels:  menus
Nova Key Value
Nova Key Value Field
Stars: ✭ 18 (-83.93%)
Mutual labels:  nova
Collapsible Resource Manager
A custom sidebar menu with collapsible groups
Stars: ✭ 100 (-10.71%)
Mutual labels:  nova
Sidemenu
Simple side/slide menu control for iOS, no code necessary! Lots of customization. Add it to your project in 5 minutes or less.
Stars: ✭ 5,267 (+4602.68%)
Mutual labels:  menus
Nova Advanced Image Field
🌄📐 A Laravel Nova advanced image field with cropping and resizing using Cropper.js and Intervention Image
Stars: ✭ 67 (-40.18%)
Mutual labels:  nova
Nova
NOVA is a tool for annotating and analyzing behaviours in social interactions. It supports Annotators using Machine Learning already during the coding process. Further it features both, discrete labels and continuous scores and a visuzalization of streams recorded with the SSI Framework.
Stars: ✭ 110 (-1.79%)
Mutual labels:  nova
Nova Indicator Field
A colour-coded indicator field for Laravel Nova
Stars: ✭ 108 (-3.57%)
Mutual labels:  nova
Uinavigation
A UE4 plugin designed to help easily make UMG menus navigable by mouse, keyboard and gamepad
Stars: ✭ 88 (-21.43%)
Mutual labels:  menus

Nova Menu Builder

Latest Version on Packagist Total Downloads

This Laravel Nova package allows you to create and manage menus and menu items.

Requirements

  • php: >=7.2
  • laravel/nova: ^3.0

Features

  • Menu management
  • Menu items management
    • Simple drag-and-drop nesting and re-ordering
  • Custom menu item types support
    • Ability to easily add select types
    • Ability to add custom fields
    • Use menubuilder:type command to easily create new types
  • Fully localizable

Screenshots

Menu Detail View

Menu Item Edit

Installation and Setup

Installing the package

Install the package in a Laravel Nova project via Composer, edit the configuration file and run migrations.

# Install the package
composer require optimistdigital/nova-menu-builder

# Publish the configuration file and edit it to your preference
# NB! If you want custom table names, configure them before running the migrations.
php artisan vendor:publish --tag=nova-menu-builder-config

Register the tool with Nova in the tools() method of the NovaServiceProvider:

// in app/Providers/NovaServiceProvider.php

public function tools()
{
    return [
        // ...
        new \OptimistDigital\MenuBuilder\MenuBuilder,
    ];
}

Setting up

After publishing the configuration file, you have to make some required changes in the config:

# Choose table names of your liking by editing the two key/values:
'menus_table_name' => 'nova_menu_menus',
'menu_items_table_name' => 'nova_menu_menu_items',

# Define the locales for your project:
# If your project doesn't have localization, you can just leave it as it is.
# When there's just one locale, anything related to localization isn't displayed.
'locales' => ['en_US' => 'English'],

# Define the list of possible menus (ie 'footer', 'header', 'main-menu'):
'menus' => [
    // 'header' => [
    //     'name' => 'Header',
    //     'unique' => true,
    //     'menu_item_types' => []
    // ]
],

# If you're just setting up, this is probably of no importance to you,
# but later on, when you want custom menu item types with custom fields
# , you can register them here:
'menu_item_types' => [],

Next, just run the migrations and you're set.

# Run the automatically loaded migrations
php artisan migrate

Optionally publish migrations

This is only useful if you want to overwrite migrations and models. If you wish to use the menu builder as it comes out of the box, you don't need them.

# Publish migrations to overwrite them (optional)
php artisan vendor:publish --tag=nova-menu-builder-migrations

Usage

Locales configuration

You can define the locales for the menus in the config file, as shown below.

// in config/nova-menu.php

return [
  // ...
  'locales' => [
    'en' => 'English',
    'et' => 'Estonian',
  ],

  // or using a closure (not cacheable):

  'locales' => function() {
    return nova_lang_get_locales();
  }

  // or if you want to use a function, but still be able to cache it:

  'locales' => '\App\Configuration\[email protected]',

  // or

  'locales' => 'nova_lang_get_locales',
  // ...
];

Custom menu item types

Menu builder allows you create custom menu item types with custom fields.

Create a class that extends the OptimistDigital\MenuBuilder\OptimistDigital\MenuBuilder\MenuItemTypes\BaseMenuItemType class and register it in the config file.

// in config/nova-menu.php

return [
  // ...
  'menu_item_types' => [
    \App\MenuItemTypes\CustomMenuItemType::class,
  ],
  // ...
];

In the created class, overwrite the following methods:

/**
 * Get the menu link identifier that can be used to tell different custom
 * links apart (ie 'page' or 'product').
 *
 * @return string
 **/
public static function getIdentifier(): string {
    // Example usecase
    // return 'page';
    return '';
}

/**
 * Get menu link name shown in  a dropdown in CMS when selecting link type
 * ie ('Product Link').
 *
 * @return string
 **/
public static function getName(): string {
    // Example usecase
    // return 'Page Link';
    return '';
}

/**
 * Get list of options shown in a select dropdown.
 *
 * Should be a map of [key => value, ...], where key is a unique identifier
 * and value is the displayed string.
 *
 * @return array
 **/
public static function getOptions($locale): array {
    // Example usecase
    // return Page::all()->pluck('name', 'id')->toArray();
    return [];
}

/**
 * Get the subtitle value shown in CMS menu items list.
 *
 * @param $value
 * @param $data The data from item fields.
 * @param $locale
 * @return string
 **/
public static function getDisplayValue($value, ?array $data, $locale) {
    // Example usecase
    // return 'Page: ' . Page::find($value)->name;
    return $value;
}

/**
 * Get the value of the link visible to the front-end.
 *
 * Can be anything. It is up to you how you will handle parsing it.
 *
 * This will only be called when using the nova_get_menu()
 * and nova_get_menus() helpers or when you call formatForAPI()
 * on the Menu model.
 *
 * @param $value The key from options list that was selected.
 * @param $data The data from item fields.
 * @param $locale
 * @return any
 */
public static function getValue($value, ?array $data, $locale)
{
    return $value;
}

/**
 * Get the fields displayed by the resource.
 *
 * @return array An array of fields.
 */
public static function getFields(): array
{
    return [];
}

/**
 * Get the rules for the resource.
 *
 * @return array A key-value map of attributes and rules.
 */
public static function getRules(): array
{
    return [];
}

/**
 * Get data of the link visible to the front-end.
 *
 * Can be anything. It is up to you how you will handle parsing it.
 *
 * This will only be called when using the nova_get_menu()
 * and nova_get_menus() helpers or when you call formatForAPI()
 * on the Menu model.
 *
 * @param null $data Field values
 * @return any
 */
public static function getData($data = null)
{
    return $data;
}

Returning the menus in a JSON API

nova_get_menus()

A helper function nova_get_menus is globally registered in this package which returns all the menus including their menu items in an API friendly format.

public function getMenus(Request $request) {
    $menusResponse = nova_get_menus();
    return response()->json($menusResponse);
}

nova_get_menu_by_slug($menuSlug, $locale = null)

To get a single menu, you can use the helper function nova_get_menu_by_slug('slug', 'en'). Returns null if no menu with the slug is found or returns the menu if it is found. If no locale is passed, the helper will automatically choose the first configured locale.

Credits

License

Nova Menu Builder is open-sourced software licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].