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
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
add/customize some of my own, but in general looking for the proper way to over ride core functions.
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...
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
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
Oops, forgot the part that actually gets the menu item to appear. In the on_start() handler of your package controller, add the following...
Hope it helps,
-Steve
$menuHelper = Core::make('helper/concrete/ui/menu'); $menuHelper->addPageHeaderMenuItem('my_menu_item','my_package_name');
Hope it helps,
-Steve
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?
So the original question stands, do we know the proper procedure for overriding files in the concrete/src directory?
> 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
> 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
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.
> 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
> 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
> 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
> 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
I wasn't thinking of it as doing the override in the individual button controller, but you are right, that will work. thanks
-Steve