CB autoaction route triggers

1 year 5 months ago #331597 by krileon
Replied by krileon on topic CB autoaction route triggers
That's not valid PHP. Variables in PHP are accessed by $variables. So to access var1 you'd use $variables.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

1 year 5 months ago - 1 year 5 months ago #331598 by activha
Replied by activha on topic CB autoaction route triggers
edit mistake

Please Log in to join the conversation.

1 year 5 months ago - 1 year 5 months ago #331600 by krileon
Replied by krileon on topic CB autoaction route triggers
Below is a simple example to get you started. It will rewrite of &action=ACTION_HERE&func=FUNC_HERE&id=ID_HERE into /ACTION_HERE/FUNC_HERE/ID_HERE structure. It doesn't do anything special beyond that and is a simple example that you could work from.

Global
Triggers: onBuildRoute
Type: Code
User: Self
Access: Everybody
Action
Method: PHP
Code:
if ( ( $variables['var2'] !== 'cbactivity' ) || ( ! $variables['var4'] ) || ( ! isset( $variables['var4']['action'] ) ) ) {
    return;
}

$action                            =    $variables['var4']['action'];

unset( $variables['var4']['action'] );

$variables['var3']            =    $action;

if ( isset( $variables['var4']['func'] ) ) {
    $variables['var3']        =    $variables['var4']['func'];

    unset( $variables['var4']['func'] );

    if ( isset( $variables['var4']['id'] ) ) {
        $variables['var3']    =    $variables['var4']['id'];

        unset( $variables['var4']['id'] );
    }
}

Parameters
References: Variable 3 and Variable 4

Global
Triggers: onParseRoute
Type: Code
User: Self
Access: Everybody
Action
Method: PHP
Code:
if ( ( $variables['var2'] !== 'cbactivity' ) || ( ! $variables['var3'] ) ) {
    return;
}

if ( isset( $variables['var3'][0] ) ) {
    $variables['var4']['action'] = $variables['var3'][0];

    if ( isset( $variables['var3'][1] ) ) {
        $variables['var4']['func'] = $variables['var3'][1];

        if ( isset( $variables['var3'][2] ) ) {
            $variables['var4']['id'] = $variables['var3'][2];
        }
    }
}

Parameters
References: Variable 4

I'm still unsure how well this will work using CB Auto Actions though. It's possible CBs Input object may initialize too early using this and cause problems. Routing really wasn't intended to be used outside of a plugins core PHP.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

1 year 5 months ago #331612 by activha
Replied by activha on topic CB autoaction route triggers
Thanks a lot for your help.
The build code part gives an exception error from the site router: implode(): Argument #2 ($array) must be of type ?array, string given
I tried to comment the line //$variables   =    $action; which solved the error but gives back the default url menuitem/?id=ID_HERE

Do you see what is wrong ?

Please Log in to join the conversation.

1 year 5 months ago #331614 by krileon
Replied by krileon on topic CB autoaction route triggers
Just rename it or remove it since it's not being accessed. It's conflicting with the core $action variable.
if ( ( $variables['var2'] !== 'cbactivity' ) || ( ! $variables['var4'] ) || ( ! isset( $variables['var4']['action'] ) ) ) {
	return;
}

$variables['var3'][]			=	$variables['var4']['action'];

unset( $variables['var4']['action'] );

if ( isset( $variables['var4']['func'] ) ) {
	$variables['var3'][]		=	$variables['var4']['func'];

	unset( $variables['var4']['func'] );

	if ( isset( $variables['var4']['id'] ) ) {
		$variables['var3'][]	=	$variables['var4']['id'];

		unset( $variables['var4']['id'] );
	}
}

Note there is an issue that causes routing to break due to our Input() API initializing before Joomla routing has processed the route into GET. A fix is already pending.

forge.joomlapolis.com/issues/9072


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

1 year 5 months ago #331622 by activha
Replied by activha on topic CB autoaction route triggers
oK thanks for the fix ;-)

BTW did you change urls with CB 6 ?
You wrote &action=ACTION_HERE&func=FUNC_HERE&id=ID but on my install it's &action=ACTION_HERE&id=ID ??

Another question, will the Activity object be built correctly in this code during the routing ? or is there any other order to respect between  joomla and CB ?
// $plugin = $variables['var2'];
// $segments = $variables['var3'];
// $query = $variables['var4'];
if ( ( $variables['var2'] !== 'cbactivity' ) || ( ! $variables['var4'] ) || ( ! isset( $variables['var4']['action'] ) ) ) {
    return;
}

$variables['var3'][]            =    $variables['var4']['action'];

unset( $variables['var4']['action'] );

if ( isset( $variables['var4']['func'] ) ) {
    $variables['var3'][]        =    $variables['var4']['func'];

    unset( $variables['var4']['func'] );

    if ( isset( $variables['var4']['id'] ) ) {
    //build activity object and retrieve params activ if exists
        $activity = new \CB\Plugin\Activity\Table\ActivityTable();
        $activity->load( (int) $variables['var4']['id'] );
        if ( ! $activity->getInt( 'id', 0 ) ) {
            return;
        }
        $params = $activity->params() ;
        $title =  !empty($params['activ']) ? urlencode($params['activ'].'-') : null;
        $variables['var3'][]    =    $title.$variables['var4']['id'];

        unset( $variables['var4']['id'] );
    }
}

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.266 seconds

Facebook Twitter LinkedIn