bmcclure / CakePHP-Menu-Plugin

A CakePHP 2.0 plugin designed to help build menus in the controller and display them in the view
MIT License
17 stars 9 forks source link

Menu Icon #9

Closed Fuhrmann closed 7 years ago

Fuhrmann commented 12 years ago

Ben, is it possible to add an option to add an icon for each menu item?

Something like:

// Define your menu
    $menu = array(
            'main-menu' => array(
                array(
                    'title' => 'Home',
                    'url' => array('controller' => 'pages', 'action' => 'home'),
                   'icon' => 'URL_TO_ICON'
                )
            ),
        ...
bmcclure commented 12 years ago

Sure, that sounds like a logical option to offer.

Would you expect this to be a part of the base MenuItem class (as an 'icon' property), or would it be better suited as a separate class of menu item, such as IconMenuItem or something?

It feels like a small enough change that I can add it into the default MenuItem class, and add functionality for rendering icons to the DefaultMenuItemRenderer class, without bloating things much.

Should a Menu contain settings for how the icons are rendered (size/position)?, or should that be customizable per menu item?

Thanks for the great suggestion! I should be able to get this implemented soon.

Fuhrmann commented 12 years ago

Actually I made a simple modification to your plugin just to meet my needs until you release the new version. I've added the 'icon' as a property of the MenuItem class. I think this should be as simple as possible (maybe, depending on the needs of others).

In my case I dont need any options besides the icon itself to be rendered before the menu. My icons are uploaded in the right size...

So I can only speak for myself...

And thanks for taking time to reply to this idea!

bmcclure commented 12 years ago

That makes sense to me.

The only options I'm thinking about adding at the start are 'iconPosition' ('before' or 'after') and 'iconSize' to allow for optional standardization of image dimensions. Potentially also a way to turn on or off icon rendering at the menu level.

I'm not sure exactly what format to accept iconSize in. If all icons are assumed to be square, I could accept just a single size, otherwise I'd probably need to accept a width and height together.

In general, I agree that this should be implemented as simply as possible. I'm toying with the idea of creating an IconMenuItemRenderer to avoid adding potentially unused features to the DefaultMenuItemRenderer. I think that would end up just adding more complexity in managing an extra renderer, however, so I'm leaning toward implementing it within DefaultMenuItemRenderer and just skipping over that section if no icon is defined.

Fuhrmann commented 12 years ago

I agree with you.

I think the 'iconPosition', 'iconSize' and something to turn on or off are important, yes. I would not need to use the width and height option because all my icons are the same size, without the need to resize them, but I think you could set an option to width and height of the icon.

ruant commented 11 years ago

Why not just add two new options? $before and $after and add those options before and after the title when the item is being generated. Then people can add what ever they want before and after the title, not just a icon. Just my two cents on the matter. I've already done it, but haven't tested it to much, but it works OK for me now at least.

bmcclure commented 11 years ago

Just saw your comment @ruant and I think you're right about adding 'before' and 'after' options to menu items.

I also feel like at a higher level there should be some standardized way that icons can be injected into one of those positions, but maybe that's too specific of a use case and it should just be left completely open.

Thanks for chiming in!