CB autoaction route triggers

1 year 5 months ago #331509 by krileon
Replied by krileon on topic CB autoaction route triggers
Not sure I understand what you mean using CB Auto Actions to only act on certain menu items. That's not how routing behavior works. If you want CB Auto Actions to handle this you'd create 2 auto actions to handle it as follows.

Global
Triggers: onBuildRoute
Type: Code
User: Self
Access: Everybody
Action
Method: PHP
Code: ROUTING_CODE_HERE

Global
Triggers: onParseRoute
Type: Code
User: Self
Access: Everybody
Action
Method: PHP
Code: ROUTING_CODE_HERE

One auto action would rewrite the URL and the other would reverse the rewrite so it sends them where they need to be. I don't think you're going to be able to limit this to a specific menu item, but if that works it'd probably be done in the onBuildRoute behavior checking against the $query. $menuItem is just the currently active menu item and is really only used to ensure you're not overriding a menu items query data in certain situations so it's not always relevant.


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 #331520 by activha
Replied by activha on topic CB autoaction route triggers
Not sure I understand how these triggers works
I tried very simple code to test before implementing the activity name but no output so far :
Trigger : onBuildRoute
        if ( ( $plugin !== 'cbactivity' ) || ( ! $query ) || ( ! isset( $query['action'] ) ) ) {
            return;
        }        
        $action = $query['action'];        
        unset( $query['action']);
        
        if($action=='activity') {
            if ( isset( $query['id'] ) ) {
                 //CBActivity::getAction((int) $id );
                 unset( $query['id']);
              }    
         }            
        $segments[]    = $action;    

and 
Trigger : onParseRoute
        if ( ( $plugin !== 'cbactivity' ) || ( ! $segments ) ) {
            return;
        }
                
         $vars['action'] = 'test';
         $vars['id'] = (int) $segments[0];

    }

I can rely on the menu item description in joomla but I just want to achieve a rewrite like /menuitem/[varx_activity_params-title]-idactivity

No idea how to do this
Unless you can help, I guess I'll have to wait for your proposal for a business membership :-(

Please Log in to join the conversation.

1 year 5 months ago - 1 year 5 months ago #331523 by krileon
Replied by krileon on topic CB autoaction route triggers
The best way to understand how they work is to read the code in CB GroupJive. It's also the exact same way you implement legacy routing rules in Joomla (those triggers are just passing along Joomla's routing information). I can't even guarantee it will work. SEF routing needs to perform the following.

1. Rewrite the URL in a way that can be reversed
2. Reverse the rewrite so they can be sent to where they're trying to go

You cannot just rewrite URLs freely. They need to be reversable. This is usually done by making sure the URLs have a unique identifier for where someone is trying to go. This is ideally just the activity id for example.

If this is a 1 way implementation then you might be able to just use CB Redirect Bot and its REGEXP URL rewriting behavior to redirect them to wherever you're wanting to go, but again you need to have some information that can be used here. Example as follows.

/WHATEVER_YOU_WANT_HERE/activity_id-WHATEVER_YOU_WANT_HERE

That could easily be redirected to the following using CB Redirect Bot.

index.php?option=com_comprofiler&view=pluginclass&plugin=cbactivity&action=activity&func=show&id=ACTIVITY_ID_HERE

Additionally in CB Auto Actions you are working within a closed off ecosystem. It has no idea what variables are references or what variables even exist. You have to set that yourself under Parameters. You can then access them using $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 #331529 by activha
Replied by activha on topic CB autoaction route triggers
Yes I had thought at the CB Redirect Bot but I need a two way implementation.

All the urls displayed on CB Activities pages with my specified asset formulation and param activ title should be displayed with the rewrite as they will be shared and used by the users.

Usually it's simpler as I can output variables and figure out what to do with the autoaction but as these two triggers have no output, this is much more complicated to know which variables can be used to find the activity data.

Any clue on that ? what variable can I reference in parameters ?

is $plugin = [var2] correct ? and corresponding to activity ?
is &$query = [var3] correct ? and corresponding to the id ?

Please Log in to join the conversation.

1 year 5 months ago #331540 by krileon
Replied by krileon on topic CB autoaction route triggers
The variables are just incremental. Please understand routing is not simple. Joomla makes it especially complicated by allowing routing aliases via Menu Items. It's possible what you're wanting is just not doable.

onBuildRoute
$_PLUGINS->trigger( 'onBuildRoute', array( $this, $plugin, &$segments, &$query, &$menuItem ) );
var1 = $this = ComprofilerRouter (base routing class for CB)
var2 = $plugin = plugin object that's being accessed
var3 = $segments = array of url segments that need to be populated (each segment is separated by a / by Joomla)
var4 = $query = array of the url query data
var5 = $menuItem = the menu Joomla item currently loaded (this is based off Itemid)

var3, var4, and var5 are all references. To modify them you need to mark them as references under Parameters tab of your auto action.

onParseRoute
$_PLUGINS->trigger( 'onParseRoute', array( $this, $plugin, $segments, &$vars, $menuItem ) );
var1 = $this = ComprofilerRouter (base routing class for CB)
var2 = $plugin = plugin object that's being accessed
var3 = $segments = the array of url segments that has already been populated (this is what you need to reverse)
var4 = $vars = the array of parsed segment data that needs to be populated (e.g. if you parsed an activity id out of $segments then you'd set id with that value into $vars)
var5 = $menuItem = the menu Joomla item currently loaded (this is based off Itemid)

var4 is a references. To modify it you need to mark it as references under Parameters tab of your auto action.


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 #331594 by activha
Replied by activha on topic CB autoaction route triggers
Following your info I wrote for a first test

For onBuildRoute
        if ( ( [var2] !== 'cbactivity' ) || ( ! [var4] ) || ( ! isset( [var4]['action'] ) ) ) {
            return;
        }        
        $action = [var4]['action'];        
        unset( [var4]['action']);
        
        if($action=='activity') {
            if ( isset( [var4]['id'] ) ) {
                 //CBActivity::getAction((int) $id );
                 unset( [var4]['id']);
              }    
         }            
        [var3]    = $action;    

and for onParseRoute
        if ( ( [var2] !== 'cbactivity' ) || ( ! [var3] ) ) {
            return;
        }
                
        [var4]['action'] = 'test';
         [var4]['id'] = (int) [var3][0];

    }

with the proper mentioned var referrenced

However the output gives a fatal error :  Cannot use temporary expression in write context 

Can you help on this ?

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.256 seconds

Facebook Twitter LinkedIn