Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom fields in navigation menus #766

Open
lassemt opened this issue Oct 9, 2016 · 12 comments
Open

Add support for custom fields in navigation menus #766

lassemt opened this issue Oct 9, 2016 · 12 comments

Comments

@lassemt
Copy link

lassemt commented Oct 9, 2016

Feature request.
CMB2 works really well with users and terms, what about adding the same awesomeness to navigation menus?

@lassemt lassemt changed the title Add support for custom fields to navigation menus Add support for custom fields in navigation menus Oct 9, 2016
@tw2113
Copy link
Contributor

tw2113 commented Oct 20, 2018

Could someone enlighten me on some usecases for this type of thing? I won't say I'm going to close and outright reject the idea, but I could use some more context.

It has me wondering if maybe an options page would work for the storing of the values, and then simply providing some documentation on how to potentially hook into the navigation menu system.

@lassemt
Copy link
Author

lassemt commented Oct 21, 2018

@tw2113 It's a 2 year old feature request so I'm trying to recall why I created this feature request. I believe it was to have the ability to a add icon-picker to navigation items.

Other usecases it could be for creating a better user experience for creating navigations where users can customize colors, add extra text, etc. to navigation items without having to know which specific css classes to add in the existing "CSS-classes" field.

Looking at the existing navigation builder I can see it would 2 places where custom fields could be added. Custom fields to navigation items and new fields to the navigation settings.

With that said I don't think I've needed this functionality since I created this feature request, and by looking at others interest in this I think it's safe to say it's not something developers need to solve very often.

@lassemt
Copy link
Author

lassemt commented Feb 12, 2019

@tw2113 Funny enough I was in the same situation today. So I started looking into how I could implement custom fields into navigation menus based on this blog post.. While researching I found someone have already made an implementation using CMB2 in navigation items.. Out of the box I had problems with using this as a plugin, but after loading it into my theme using a PSR-4 autoloader I got it to work (the plugin is probably meant to be loaded with composer).

@marsjaninzmarsa I see you have liked my proposal, you will probably find this interesting.

@tw2113
Copy link
Contributor

tw2113 commented Feb 13, 2019

Definitely a more composer-focused version.

Not immediately sure where those CMB2 namespaces are coming from, unless I'm missing information/details.

However, if it works, more power to it all.

@marsjaninzmarsa
Copy link

Nah, it's saving data in options table, why? Menu items are just posts, we can use postmeta.

@marsjaninzmarsa
Copy link

Opened issue: nsrosenqvist/cmb2-nav-menus#1.

@scottsawyer
Copy link

Just $0.02 here, another use-case could be adding icons to nav menu items. There is already a contributed CMB2 field type for fontawesome icons. What I am not sure of yet is whether CMB2 Nav Menus works without composer. I'll try to give it a test run soon, but for my use-case, I'd need it to work without composer.

@fabianpimminger
Copy link

Is there still a need for this? Wordpress added aditional hooks in 5.4 that would make it much easier to integrate: https://make.wordpress.org/core/2020/02/25/wordpress-5-4-introduces-new-hooks-to-add-custom-fields-to-menu-items/

I often have the need to add icons or other additional data to menu items. As a proof of concept, I've now added nav_menu_item as an object_type to see if it was easily possible. It is.

Is this something we could include @jtsternberg? I could provide a PR with some additional work.

@jtsternberg
Copy link
Member

A PR sounds intriguing, and I'd definitely check it out, but I can't promise it's something I'd want to add to CMB2 core to support. I guess it depends on how much complexity is added vs the gain.

@cristovaov
Copy link

I just so happened to have a need for this. And I am a bit struggling tbh with this. @fabianpimminger can I maybe reach out to you for help?

@MihaiCraciun
Copy link

Hey! Just came across this. I really need to add an image field to menu items and can't find anything on the web on how do do it. Can someone post a gist with a basic example please? I think there are many people that would find it helpful.
I tried adding a simple text field to my cmb2_admin_init function where i added all the other fields for posts or pages:

$my_nav_menu_meta = new_cmb2_box(array(
        'id'           => 'menu_cf',
        'object_types' => array('nav_menu_item'),
    ));

    $my_nav_menu_meta->add_field(array(
        'name'       => __('Test Text', 'cmb2'),
        'id'         => $prefix.'menu_text',
        'type'       => 'text',
    ));

@besimdauti
Copy link

It is really important for CMB2 users to include also 'object_types' => array('nav_menu_item')

I am working in a custom project and client need for each item menu to add differnet icon image, so cmb2 is not supporting it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants