[PR #4403] [MERGED] Closes #4401: Simplify registration process for pluin menu items #12836

Closed
opened 2025-12-29 22:23:53 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/4403
Author: @jeremystretch
Created: 3/25/2020
Status: Merged
Merged: 3/25/2020
Merged by: @jeremystretch

Base: 3351-pluginsHead: 4401-plugins-navlinks


📝 Commits (3)

  • c1f2ad9 Simplify the mechanism for plugins to register navigation menu items
  • 9ea30c0 Replace get_menu_items() with static attribute
  • d0edd9d Update documentation for #4401

📊 Changes

5 files changed (+71 additions, -72 deletions)

View changed files

📝 docs/plugins/development.md (+28 -15)
📝 netbox/extras/plugins/__init__.py (+39 -43)
📝 netbox/extras/plugins/context_processors.py (+2 -4)
📝 netbox/extras/plugins/signals.py (+0 -8)
📝 netbox/templates/inc/plugin_nav_menu_items.html (+2 -2)

📄 Description

Closes: #4401

  • Automatically import menu_items from a plugin's navigation.py (if it exists)
  • Declare get_menu_items() on PluginConfig to allow a plugin author to override the default behavior
  • Require instantiating PluginNavMenuLink to create menu items to enforce requires attributes

An example navigation.py within a plugin looks like this:

from extras.plugins import PluginNavMenuButton, PluginNavMenuLink
from utilities.choices import ButtonColorChoices

menu_items = (
    PluginNavMenuLink(
        link='plugins:plugin_name:view_a',
        link_text='Link 1',
        buttons=(
            PluginNavMenuButton('view_foo', 'Button A', 'fa-info', ButtonColorChoices.BLUE),
            PluginNavMenuButton('view_bar', 'Button B', 'fa-warning', ButtonColorChoices.GREEN),
        )
    ),
    PluginNavMenuLink(
        link='plugins:plugin_name:view_b',
        link_text='Link 2'
    ),
)

Edit: Will also update the docs accordingly if this is agreed upon.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/4403 **Author:** [@jeremystretch](https://github.com/jeremystretch) **Created:** 3/25/2020 **Status:** ✅ Merged **Merged:** 3/25/2020 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `3351-plugins` ← **Head:** `4401-plugins-navlinks` --- ### 📝 Commits (3) - [`c1f2ad9`](https://github.com/netbox-community/netbox/commit/c1f2ad90efa0756a6f871c80fb340a83c3944944) Simplify the mechanism for plugins to register navigation menu items - [`9ea30c0`](https://github.com/netbox-community/netbox/commit/9ea30c057fc8488abe200fd1d0a824cf9c173cf6) Replace get_menu_items() with static attribute - [`d0edd9d`](https://github.com/netbox-community/netbox/commit/d0edd9d5c1f436386daf6bb658f09f7015c3bc1f) Update documentation for #4401 ### 📊 Changes **5 files changed** (+71 additions, -72 deletions) <details> <summary>View changed files</summary> 📝 `docs/plugins/development.md` (+28 -15) 📝 `netbox/extras/plugins/__init__.py` (+39 -43) 📝 `netbox/extras/plugins/context_processors.py` (+2 -4) 📝 `netbox/extras/plugins/signals.py` (+0 -8) 📝 `netbox/templates/inc/plugin_nav_menu_items.html` (+2 -2) </details> ### 📄 Description ### Closes: #4401 - Automatically import `menu_items` from a plugin's `navigation.py` (if it exists) - Declare `get_menu_items()` on PluginConfig to allow a plugin author to override the default behavior - Require instantiating PluginNavMenuLink to create menu items to enforce requires attributes An example `navigation.py` within a plugin looks like this: ```python from extras.plugins import PluginNavMenuButton, PluginNavMenuLink from utilities.choices import ButtonColorChoices menu_items = ( PluginNavMenuLink( link='plugins:plugin_name:view_a', link_text='Link 1', buttons=( PluginNavMenuButton('view_foo', 'Button A', 'fa-info', ButtonColorChoices.BLUE), PluginNavMenuButton('view_bar', 'Button B', 'fa-warning', ButtonColorChoices.GREEN), ) ), PluginNavMenuLink( link='plugins:plugin_name:view_b', link_text='Link 2' ), ) ``` Edit: Will also update the docs accordingly if this is agreed upon. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 22:23:53 +01:00
adam closed this issue 2025-12-29 22:23:54 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#12836