Adding a Toolbar Button

Permalink
Hi, Has anyone worked out adding a Toolbar Button in 5.7? I think I am getting stuck on the elements/header_menu controller, probably needs to be namespaces 5.6 controller looked like this

<?php       
defined('C5_EXECUTE') or die("Access Denied.");
class SitemapConcreteInterfaceMenuItemController extends ConcreteInterfaceMenuItemController {
   public function displayItem() {
      // button is always enabled
      return true;
   }
}
?>

pvernaglia
 
andrew replied on at Permalink Reply
andrew
This currently doesn't work in 5.7.0.1. It is fixed in github now and will be released in master, with some docs on how to add these buttons in 5.7 coming soon. It's mostly the same with some different method names (since I did a bit of cleanup on the classes.)
pvernaglia replied on at Permalink Reply
pvernaglia
Hi, is this working in 5.7.0.3?
andrew replied on at Permalink Reply
andrew
Yep! You might have to tweak the syntax a bit. Since docs are lacking reading the source is the best option. The relevant method is found in src/Application/Service/UserInterface/Menu.php, in addPageHeaderMenuItem.
pvernaglia replied on at Permalink Reply
pvernaglia
EDIT Nevermind,
pvernaglia replied on at Permalink Reply
pvernaglia
OK, Here's the real question:

in 5.6 if I were going to add a button called 'Jobs' to the header toolbar we had a controller in directory called package_directory/elements/header_menu/jobs/controller.php

<?php       
defined('C5_EXECUTE') or die("Access Denied.");
class JobsConcreteInterfaceMenuItemController extends ConcreteInterfaceMenuItemController {
   public function displayItem() {
      // button is always enabled
      return true;
   }
}
?>


Now it looks like that controller has moved to package_directory/menu_items/jobs. How does that controller need to be name spaced to work?

I think I have everything up to this point working because I am getting an error from the old controller "Class 'ConcreteInterfaceMenuItemController' not found"

Someone have this figured out yet? A little love from the C5 guys?

Thanks
Peter
andrew replied on at Permalink Reply
andrew
Try this. If your package is "your_package":

namespace Concrete\Package\YourPackage\MenuItem\Jobs;
use Concrete\Core\Application\UserInterface\Menu\Item\Controller as MenuItemController;
class Controller extends MenuItemController {
}
pvernaglia replied on at Permalink Reply
pvernaglia
Thanks Andrew, that works.

in 5.6 we had package_name/elements/header_menu/jobs/view.css to apply style to the button, in 5.7 package_name/menu_items/jobs/view.css does not appear to pull any styles in. I did add a class with the 'linkattributes' and that shows up on the link but no styling.

What is the correct way to style buttons?

Thanks
Peter
andrew replied on at Permalink Reply
andrew
For most buttons, the built-in HTML should be sufficient. But if you need more stuff you can override the getMenuItemLinkElement(), which returns an HTMLObject object that you can manipulate (more easily than working with strings of HTML). And for custom HTML it might be easiest to just create an asset for it and then require that asset using your package's on_start() method.

Once 5.7.1 is out and we do our documentation push the assets system will be getting a lot of that explanatory attention.
pvernaglia replied on at Permalink Reply
pvernaglia
It is fine if you are using Font Awesome Icons, but what if you want a text label? Is there a way to have buttons you add display the label and not the icon?