Overriding core functions

Permalink
What's the procedure to override a core function from a package, when you need to change something in one of the files located under concrete/src? Do we put an src directory in the package and copy the file there? Something has to be done with namespacing on the file?

Can someone give an example for the proper way to do this? I need to make some changes to concrete/src/Application/UserInterface/Menu/Controller.php

thanks

pvernaglia
 
Shotster replied on at Permalink Reply
Shotster
Are you trying to modify the built-in toolbar items or add/customize one of your own?

-Steve
pvernaglia replied on at Permalink Reply
pvernaglia
add/customize some of my own, but in general looking for the proper way to over ride core functions.
Shotster replied on at Permalink Reply
Shotster
Well, it appears there's a special way to deal with menu items...

At the root of your package, create a "menu_items" folder. Inside it, create a folder called "my_menu_item" (or whatever). In that folder, place your "controller.php" file as well as a "view.css" and/or "view.js" file (if needed).

The controller class should look something like...

<?php
namespace Concrete\Package\MyPackageName\MenuItem\MyMenuItem;
class Controller extends Concrete\Core\Application\UserInterface\Menu\Item\Controller
{
}

That should get a new button to appear in the toolbar.

I haven't messed with it much beyond that though.

EDIT: There appears to be a bug in 5.7.1 if you include assets. See here...

https://github.com/concrete5/concrete5-5.7.0/issues/1376...

-Steve
Shotster replied on at Permalink Reply
Shotster
Oops, forgot the part that actually gets the menu item to appear. In the on_start() handler of your package controller, add the following...

$menuHelper = Core::make('helper/concrete/ui/menu');
$menuHelper->addPageHeaderMenuItem('my_menu_item','my_package_name');

Hope it helps,

-Steve
pvernaglia replied on at Permalink Reply
pvernaglia
No, that is not quite how you do it in 5.7 the syntax is different now, and I don't think the view.css in menu_items get read in like they did in 5.6

So the original question stands, do we know the proper procedure for overriding files in the concrete/src directory?
Shotster replied on at Permalink Reply
Shotster
> No, that is not quite how you do it in 5.7 the syntax is different now, and
> I don't think the view.css in menu_items get read in like they did in 5.6

It does indeed work, as I tested it before posting my response. What's more, none of the code I used was marked "legacy", and it uses the new namespaces. Thus, it seems reasonable to assume it's an officially sanctioned means of adding toolbar items.

> So the original question stands, do we know the proper
> procedure for overriding files in the concrete/src directory?

I know how to do it at the site level (i.e. in the "application" directory), but I haven't yet had a need to do it from a package, so I can't help further at this time.

Hopefully, someone else can chime in.

-Steve
pvernaglia replied on at Permalink Reply
pvernaglia
You need to add an array with the options for the button to the addPageHeaderMenuItem statement to get a button that does something, and that syntax is different than in 5.6. I don't think though you can get a button with anything but font awesome icons, that is why I wanted to override the controller.
Shotster replied on at Permalink Reply
Shotster
> You need to add an array with the options for the button to the
> addPageHeaderMenuItem statement to get a button that does something,
> and that syntax is different than in 5.6.

Correct. I figured one could glean that by looking at the controller class you're extending, which (as I stated) is...

Concrete\Core\Application\UserInterface\Menu\Item\Controller


> I don't think though you can get a button with anything but font
> awesome icons, that is why I wanted to override the controller.


So extend the controller class as I described above, and re-implement the getMenuItemLinkElement() method.


-Steve
Shotster replied on at Permalink Reply
Shotster
> I figured one could glean that by looking at the controller
> class you're extending

My bad. That's actually in the service provider class, which is at...

concrete/src/Application/Service/UserInterface/Menu.php

However, you can still override the default menu item link as I stated; so you can put whatever you want in there - doesn't have to be a font awesome character.

-Steve
pvernaglia replied on at Permalink Reply
pvernaglia
I wasn't thinking of it as doing the override in the individual button controller, but you are right, that will work. thanks