Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRESIDECMS-2944 outputView & outputViewlet #1536

Open
wants to merge 2 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/autobuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ jobs:
box server start serverConfigFile="server.json" cfengine="${{ matrix.cfengine }}" --noSaveSettings
http_response=$(curl --max-time 120 -s -o /dev/null -w "%{http_code}" http://127.0.0.1:9998)
if [ $http_response != "200" ]; then
echo "Website startup exited with error: $http_response"
echo "Logs:"
echo "============"
echo
box server log name="fullcmsapp"
exit 1
fi

Expand Down
8 changes: 8 additions & 0 deletions system/Bootstrap.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ component {
return application.cbBootstrap.onMissingTemplate( argumentCollection=arguments );
}
}
public function onMissingFunction( functionName, functionArguments ) {
if ( arguments.functionName == "testOnMissingFunctionAvailability" ) {
return true;
}

return application.presidehelperClass[ arguments.functionName ]( argumentCollection=functionArguments );
}

public void function onError( required struct exception, required string eventName ) output=true {
if ( _dealWithSqlReloadProtectionErrors( arguments.exception ) ) {
Expand Down Expand Up @@ -267,6 +274,7 @@ component {
bootstrap.loadColdbox();

application.cbBootstrap = bootstrap;
application.presideHelperClass = bootstrap.getController().getWirebox().getInstance( "presideHelperClass" );
}

private boolean function _reloadRequired() {
Expand Down
110 changes: 100 additions & 10 deletions system/coldboxModifications/Controller.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ component extends="coldbox.system.web.Controller" {
, string cacheLastAccessTimeout = ""
, string cacheSuffix = ""
, string cacheProvider = "template"
, boolean throwOnMissing = true
) {
if ( arguments.delayed && _getDelayedViewletRendererService().isDelayableContext() ) {
return _getDelayedViewletRendererService().renderDelayedViewletTag(
Expand Down Expand Up @@ -133,37 +134,126 @@ component extends="coldbox.system.web.Controller" {
return rendered;
}

var result = "";
var view = "";
var handler = arguments.event;
var defaultAction = getSetting( name="EventAction", fwSetting=true, defaultValue="index" );
var hndlrExists = handlerExists( handler );
var result = "";
var view = ListChangeDelims( arguments.event, "/", "." );
var deferredViewlet = "";
var viewletArgs = arguments.args;
var handler = arguments.event;
var defaultAction = getSetting( name="EventAction", fwSetting=true, defaultValue="index" );
var hndlrExists = handlerExists( handler );

if ( !hndlrExists ) {
handler = ListAppend( handler, defaultAction, "." );
hndlrExists = handlerExists( handler );
}

if ( hndlrExists ) {
return runEvent(
var requestContext = getRequestContext();
requestContext.pushViewletContext( view );

var result = runEvent(
event = handler
, prepostExempt = arguments.prepostExempt
, private = arguments.private
, eventArguments = { args = arguments.args }
, eventArguments = { args = viewletArgs }
);

if ( IsNull( local.result ) ) {
view = requestContext.getViewletView();
deferredViewlet = requestContext.getDeferredViewlet();
viewletArgs = requestContext.getViewletArgs( viewletArgs );
}
requestContext.popViewletContext();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this higher up and return early? (ie before if ( IsNull( local.result ) )

if ( !IsNull( local.result ) ) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because requestContext.getViewletView(), etc. all depend on the viewlet context being the current viewlet. Can/must pop it after that.


if ( !IsNull( local.result ) ) {
return result;
}

if ( Len( Trim( deferredViewlet ) ) ) {
return renderViewlet( event=deferredViewlet, args=viewletArgs );
}
if ( !Len( Trim( view ) ) ) {
return "";
}
}

view = ListChangeDelims( arguments.event, "/", "." );
if ( !viewExists( view ) ) {

var vwExists = viewExists( view )
if ( !vwExists ) {
view = ListAppend( view, defaultAction, "/" );
vwExists = viewExists( view );
}

if ( !vwExists && ( !arguments.throwOnMissing || hndlrExists ) ) {
return "";
}

return getRenderer().renderView(
view = view
, args = arguments.args
, args = viewletArgs
);
}

public void function outputViewlet(
required string event
, struct args = {}
, boolean delayed = _getDelayedViewletRendererService().isViewletDelayedByDefault( arguments.event )
, boolean throwOnMissing = false
, boolean cache = false
) output=true {
if ( arguments.cache || ( arguments.delayed && _getDelayedViewletRendererService().isDelayableContext() ) ) {
echo( renderViewlet( argumentCollection=arguments ) );
return;
}
silent {
var view = "";
var handler = arguments.event;
var defaultAction = getSetting( name="EventAction", fwSetting=true, defaultValue="index" );
var hndlrExists = handlerExists( handler );
var requestContext = getRequestContext();
var view = ListChangeDelims( arguments.event, "/", "." );
var deferredViewlet = "";
var viewletArgs = {};

if ( !hndlrExists ) {
handler = ListAppend( handler, defaultAction, "." );
hndlrExists = handlerExists( handler );
}

if ( hndlrExists ) {
requestContext.pushViewletContext( view );
var handlerResult = runEvent(
event = handler
, private = true
, prePostExempt = true
, eventArguments = { args=arguments.args, bufferedViewlet=true }
);
if ( !IsSimpleValue( local.handlerResult ?: "" ) ) {
handlerResult = NullValue();
} else {
view = requestContext.getViewletView();
deferredViewlet = requestContext.getDeferredViewlet();
viewletArgs = requestContext.getViewletArgs( args );
}
requestContext.popViewletContext();
}

if ( IsNull( local.handlerResult ) && Len( view ) && !viewExists( view ) ) {
view = ListAppend( view, defaultAction, "/" );
}
}

if ( !IsNull( handlerResult ) ) {
echo( handlerResult );
} else if ( Len( Trim( deferredViewlet ) ) ) {
outputViewlet( event=deferredViewlet, args=viewletArgs );
} else if ( Len( view ) ) {
if ( arguments.throwOnMissing || viewExists( view ) ) {
getRenderer().outputView( view=view, args=viewletArgs );
}
}
}

public any function getRequestContext() {
return getRequestService().getContext();
}
Expand Down
77 changes: 75 additions & 2 deletions system/coldboxModifications/RequestContextDecorator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ component accessors=true extends="preside.system.coldboxModifications.RequestCon

if ( arguments.includeLanguageSlug ) {
if ( this.getModel( "featureService" ).isFeatureEnabled( "multilingual" ) ) {
var multilingualSettings = getModel( "systemConfigurationService" ).getCategorySettings(
var multilingualSettings = getModel( "systemConfigurationService" ).getCategorySettings(
category = "multilingual"
, tenantId = arguments.siteId
);

arguments.includeLanguageSlug = multilingualSettings.urls_enabled ?: false;
}
}

if ( IsBoolean( arguments.includeLanguageSlug ) && arguments.includeLanguageSlug ) {
var languageSlug = this.getLanguageSlug();
Expand Down Expand Up @@ -1189,6 +1189,79 @@ component accessors=true extends="preside.system.coldboxModifications.RequestCon
return getRequestContext().getValue( name="_isEmailRenderingContext", defaultValue=false, private=true );
}

// OUTPUTVIEWLET HELPERS
public function pushViewletContext( required string view ) {
var prc = getRequestContext().getCollection( private=true );
if ( !StructKeyExists( prc, "_viewletContexts" ) ) {
prc._viewletContexts = [];
}

ArrayAppend( prc._viewletContexts, { view=arguments.view, deferredViewlet="" } );
}

public function popViewletContext() {
var prc = getRequestContext().getCollection( private=true );
if ( StructKeyExists( prc, "_viewletContexts" ) && ArrayLen( prc._viewletContexts ) ) {
ArrayDeleteAt( prc._viewletContexts, ArrayLen( prc._viewletContexts ) );
}
}

public function getViewletContext() {
var prc = getRequestContext().getCollection( private=true );

if ( !StructKeyExists( prc, "_viewletContexts" ) || !ArrayLen( prc._viewletContexts ) ) {
prc._viewletContexts = [ { view="", deferredViewlet="" } ];
}

return ArrayLast( prc._viewletContexts );
}

public function setViewletView( required string view ) {
var viewletCtx = getViewletContext();

viewletCtx.view = arguments.view;
}

public function noViewletView() {
setViewletView( "" );
}

public function deferViewlet( required string deferredViewlet ) {
var viewletCtx = getViewletContext();

viewletCtx.deferredViewlet = arguments.deferredViewlet;
}

public function setViewletArgs( required struct args ) {
var viewletCtx = getViewletContext();

viewletCtx.args = arguments.args;
}

public string function getViewletView() {
var viewletCtx = getViewletContext();

return viewletCtx.view ?: "";
}

public string function getDeferredViewlet() {
var viewletCtx = getViewletContext();

return viewletCtx.deferredViewlet ?: "";
}

public struct function getViewletArgs( required struct defaultArgs ) {
var viewletCtx = getViewletContext();

if ( StructKeyExists( viewletCtx, "args" ) && IsStruct( viewletCtx.args ) ) {
return viewletCtx.args;
}

return arguments.defaultArgs;
}



// status codes
public void function notFound() {
announceInterception( "onNotFound" );
Expand Down
Loading