I am building a new application. My strategy is to build the entire admin interface as a contentbox module.
However I am having trouble when it comes to layouts. I want to either have a completely separate layout from the admin layout or a sub layout wrapped in the admin layout.
I tried adding the following to moduleconfig.cfc but contentbox ignored it:
layoutSettings = {
defaultLayout = “layouts/custom.cfm”
};
Is there any way to achieve this?
Also one side question, I know you offer themes for the frontend but are there plans to offer admin themeing capabilities?
Thanks Andrew. I actually had just followed through your 2 blog posts before posting this. However I read over the one you referenced again and here is what I tried:
I added the following to configure() in the moduleconfig file:
layouts = [
{ name = “wizard”,
file = “wizard.cfm”,
folders = “^layouts,layouts”
},
{ name = “main”,
file = “Main.cfm”,
folders = “^layouts,layouts”
}
];
I then added the following to my parent handler that extends all sub handlers:
public void function preProcess(event, interceptData) eventPattern="^(contentbox-ui|mymodule)" {
super.preProcess(event, interceptData);
event.setLayout(name=“wizard”, module=“WebPanel”);
}
I didn’t get any errors or any indication that it did anything.
Actually I have now resorted to searching through google to find any examples of this from blogs to github, etc. The only example I found is in your example and I can’t get it to work. I did finally get errors to come through btw:
I simplified my handler while I’m testing down to just the following:
component extends=“contentbox-ui.interceptors.CBRequest” singleton {
public void function preProcess(event, interceptData) eventPattern="^(contentbox-ui|WebPanel)" { }
}
Error Messages: Error building: modules.contentbox.modules.WebPanel.handlers.Home -> The PROPERTIES parameter to the init function is required but was not passed in. with constructor arguments: {controller={[(Component=coldbox.system.web.Controller)]}}… etc, etc, etc…
Also the posts I provided show how to use modules in ContentBox that are not stored in the normal ContentBox location. Otherwise a module should just work.
I do have another few posts on modules in ContentBox, which should get you going. But it sounds like you have issues with your own code at the moment.
But it looks like you are trying to inject something into your handler that also requires an init argument. Have you nided this in the ModuleConfig or just DI’ed into the property, it looks like just the property.
This is where the error is occurring, in that file you have a DI’ed or Dpendency Injected object, that is requiring an init argument. Try reducing your handler down to bare bones and try again.
function onLoad(){
var menuService = controller.getWireBox().getInstance(“AdminMenuService@cb”);
menuService.addSubMenu(topMenu=menuService.MODULES,name=“WebPanel”,label=“Web Panel”,href="#menuService.buildModuleLink(‘WebPanel’,‘home’)#");
}
function onActivate(){
}
function onUnload(){
var menuService = controller.getWireBox().getInstance(“AdminMenuService@cb”);
menuService.removeSubMenu(topMenu=menuService.MODULES,name=“WebPanel”);
}
function onDeactivate(){}
}
Okay, I guess I need to read more about interceptors/wirebox/aop/di/etc. Looks like you really can’t get far with coldbox without a deep knowledge of these things.
There is more on my blog just go to the search on the right side and type in interceptors.
ContentBox has a full range of different interception points, to create an interceptor you can just create a file in the interceptors folder and add that snippet you had earlier. Then all you need to do, is then in your moduleConfig is to then add the interceptor, something along the lines of
Then when the module is loaded, it will setup the interceptor ready to be called. All you need to do is create a file with that interceptor code and re-init the framework or go to the dashboard and reload the application from there. Then any time that point is announced the new module interceptor is then called.
For more on the points, you can find them in the ModuleConfig of ContentBox, ContentBox-UI etc.
Creating the interceptor is the easy bit, understanding what you want to achieve from it is the hard bit.
Ahh, okay, thanks for the rundown, I’ll certainly refer to those resources. Here is what I have done that should work right?
You’ll notice I put an abort statement in the interceptor, that is so I can tell if it is running which its not.
Here’s what I did:
Added an interceptor called /modules/contentbox/modules/WebPanel/model/interceptors/layout.cfc, with the following:
component extends=“contentbox-ui.interceptors.CBRequest” singleton
{
public void function preProcess(event, interceptData) eventPattern="^(contentbox-ui|WebPanel)"
{
abort;
super.preProcess(event, interceptData);
event.setLayout(name=“wizard”, module=“WebPanel”);
}
}
Added the following to /modules/contentbox/modules/WebPanel/ModuleConfig.cfc:
// Custom Declared Interceptors
interceptors = [
{
class=“contentbox.modules.WebPanel.model.interceptors.layout”,
properites = {
varName = “LayoutInterceptor”
}
}
];
Also depends on whether you are starting ColdFusion from the command line or not, but you may want to look into logging with ColdBox and logging to a file.
When you switch that on, you could add this to your interceptor
Yep. Just restarted the coldfusion service too just to make sure. Same thing.
Also I start Coldfusion from the services manager. I will go ahead and get the logging setup if its not already but shouldn’t the abort statement alone be able to tell me if the preProcess is running?
Yep, its the eventPattern. Once I removed it the abort command fired confirming that it works. However I just wanted it to run for my module but the following eventPattern isn’t working: eventPattern="^WebPanel:"