event.setView ignores module

I have a custom module I am building that uses custom content that extends the baseContent class. When I try to use versioning, of course, I cannot do several things (for instance, version.index only recognizes the hard coded Page, Entry and ContentStore types). So I created a versions.cfc handler that extends the contentbox-admin:versions handler. This way I can make the small adjustments then let the core do the rest. I just need to point it back to the core view when I’m done.

event.setView(view="/versions/index", module=“contentbox-admin”);

The above should work in theory. However, the view it tries to find, regardless of what I set the module to, is [site-root]/views/versions/index.cfm. Checking the value from getCurrentView() and getCurrentViewModule() show that the object has indeed been set. It’s just ignoring the module concept all together and looking in the root.

I’m guessing I have something set incorrectly somewhere as this would seem to be a major impediment to module developers.

Thanks in advance.

John

P.S. I’ve also tried it as event.setView(view=“versions/index”, module=“contentbox-admin”);

Oh, I forgot to mention that I have no problem getting renderview() to use the module argument correctly.

Anyone have any ideas on this?

I’m still in need of assistance on this and it is really killing my work at the moment. I have a huge deadline next week and I can’t get this core functionality to work. Anybody have any ideas?

As noted, the event’s view and module properties are indeed changed by setView(), but when the page renders it looks in the site root rather than the event’s module.

Luis,

After digging into the code I think we have a bug in the ContentBox admin module.

What I am working on is adding new content types into ContentBox within a module I am writing. So I want to make use of the existing contentbox-admin module for as much of the functionality as I can (rather than making copies of all the necessary files). In two different instances thus far I have found issues when I make an event in a handler in my module so that the event mimics the same event in the cbadmin module.

For example, in one of my new content types (extending the base content class) I want to provide the ability to add related content that includes not just Page, Entry and ContentStore, but also my new content type. So I created the following in my content type’s handler in my module:

function showRelatedContentSelector( event, rc, prc ) {
event.paramValue( “search”, “” );
event.paramValue( “clear”, false );
event.paramValue( “excludeIDs”, “” );
event.paramValue( “contentType”, “Page,Entry,ContentStore,MyContentType” );
// exit handlers
prc.xehRelatedContentSelector = “#prc.cbAdminEntryPoint#.content.relatedContentSelector”;
prc.CBHelper = CBHelper;

event.setView(view=“content/relatedContentSelector”, module=“contentbox-admin”, layout=“ajax” );
}

The problem arises in contentbox-admin/handlers/modules.cfc. After var results = runEvent(event="#module.getname()#:#prc.contentbox_moduleEvent#"); runs and returns null, the following code incorrectly overwrites the module specified in setView():

// stash the module view, so it renders in the admin layout
prc.viewModule = module.getName();

The intent was to insist that the view gets rendered in the admin layout. The result, however, is that it applies the module that the event is in, which in this case is my module. So it changes the module from my setting of “contentbox-admin” to the module my code is in. The view, of course, is not present in my module (as noted, the intent is to make use of the core and not make copies that could end up being out of date upon upgrade of ContentBox). So ColdBox looks for the module in the wrong module and, when it fails to find it in the module, looks for it in the root.

Of course, we can’t just remove this line as it causes the pages of my module to fail. But REMming out the line and simply browsing the showRelatedContentSelector() event correctly displays the Add Related Content interface with my additional content type.

Obviously ContentBox wasn’t written with this scenario in mind. In my mind it would make sense for custom modules to operate within the admin area and be able to reference and use admin area code. I think the prc.viewModule = module.getName(); line contentbox-admin.handlers.modules.execute() achieved the desired result without going about it the right way. I don’t think it anticipated executions of events that only need to call a view (and that specify the desired module for the view).

Perhaps I am missing the correct method of specifying the module within this context. Please let me know.

Also, if you, Luis, agree that this is something to be addressed as a bug, let me know and I will enter it into jira.

John

interesting. What if you return the render view instead of setView()

Luis Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com
P/F: 1-888-557-8057
Direct: (909) 248-3408

ColdBox Platform: http://www.coldbox.org

ContentBox Platform: http://www.gocontentbox.org
Linked In: http://www.linkedin.com/pub/3/731/483

Social: twitter.com/ortussolutions | twitter.com/coldbox | twitter.com/lmajano | twitter.com/gocontentbox

renderView() does utilize the passed module parameter correctly.

Hmm, I am not sure, how to tackle this one where you set the view to the right module. Let me think about it.

Actually, can you do a test, can you do this:

if( !structKeyExistS( prc, “viewModule”) OR !len( prc.viewModule ) {

prc.viewModule = module.getName();

}

See if that works. This tells it that if the viewModule is already set, don’t mess with it.

Luis Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com
P/F: 1-888-557-8057
Direct: (909) 248-3408

ColdBox Platform: http://www.coldbox.org

ContentBox Platform: http://www.gocontentbox.org
Linked In: http://www.linkedin.com/pub/3/731/483

Social: twitter.com/ortussolutions | twitter.com/coldbox | twitter.com/lmajano | twitter.com/gocontentbox

Luis,

The answer is yes… and no.

First, I had to alter the code just a bit (some incorrect syntax). For those following along, the corrected code is (replacing line 57 of contentbox-admin.handlers.modules):

if( !structKeyExists( prc, “viewModule”) or !len( prc.viewModule )) {
prc.viewModule = module.getName();
}

This does fix the initial problem such that event.setView(view="/versions/index", module=“contentbox-admin”); works within a custom module. This change does not break module pages that utilize the cbadmin layout. So it solved our problem.

However, now that we can get a bit further, I see there is another problem exposed.

At this point, I have made a copy of contentbox-admin.handlers.versions. This was necessary to enable my custom content types to work with the “Full History” page of versioning because the version.index event manually sets xehBackTrack and xehOpenContent for each content type (I have noticed elsewhere that similar code is accompanied with remarks to make such hard codings dynamic… adding custom content types does require a fair amount of copied files from the cbadmin area because of this; I have yet to investigate fixing the issue by overriding such cfcs by intercepting them afterInstanceCreation: http://www.andyscott.id.au/blog/a-funky-way-to-replacing-captcha-in-contentbox). So my module’s versions.cfc handler uses setView() to show /versions/index (the full history page) when you click the “Full History” button of the custom content type in the custom module. (I know, repetitive language there).

With the aforementioned fix, this now works. However, when on the Full History page, the “Compare Versions” button launches a modal containing an error that “views/versions/diff.cfm” cannot be found in the root of the application. So it appears something at this point is not correctly pointing to the correct module.

I am crunching on a deadline so I don’t expect to look into this and fix the full versioning until a later date. But it’s good to note that the code fix you (Luis) provided does indeed fix the initial problem, though may need further fixing for instances like that I just described.

John

Luis inadvertently posted his response (to my latest post in this thread) in another thread. Here it is:

I have added two new interception points for versions, so you can override for custom con tent types:

[CONTENTBOX-557](https://ortussolutions.atlassian.net/browse/CONTENTBOX-557)
Versions now get two new interception points: cbadmin_onVersionIndex, cbadmin_onVersionDiff