by
KK » Tue Nov 07, 2017 3:28 pm
@klaus,
can I change things now with Couch 2.0?
Sure.
There are two places where we'll need to change the 'view' links - the listing page (magnifying glass icon) and the edit page.
Please place the following in your kfunctions.php file -
- Code: Select all
// This is for the listing page
$FUNCS->add_event_listener( 'alter_render_vars_list_row', 'my_alter_view_link' );
function my_alter_view_link(){
global $CTX, $FUNCS;
$masterpage = 'your-template.php'; // change this to set the masterpage you are interested in
$route = $FUNCS->current_route;
if( $route->module!='pages' || $route->masterpage!=$masterpage ) return;
// set the mew view link
$page_id = $CTX->get('k_page_id');
$view_link = K_SITE_URL . $masterpage .'?p='. $page_id . '&test=123';
$CTX->set( 'k_view_link', $view_link );
}
// This is for the edit page
$FUNCS->add_event_listener( 'alter_pages_form_page_actions', 'my_alter_view_link_in_form' );
function my_alter_view_link_in_form( &$arr_actions ){
global $FUNCS, $PAGE;
$masterpage = 'your-template.php'; // change this to set the masterpage you are interested in
$route = $FUNCS->current_route;
if( $route->module!='pages' || $route->masterpage!=$masterpage ) return;
if( array_key_exists('btn_view', $arr_actions) ){
$view_link = K_SITE_URL . $PAGE->tpl_name . '?p=' . $PAGE->id . '&test=123';
$arr_actions['btn_view']['href'] = $view_link; // set your custom URL here
}
}
Make sure to replace the two instances of 'your-template.php' above with the name of your template that needs the new links.
Now in the listing pages of that template, you'll notice that the link shown by the magnifying glass has an additional '&test=123' appended to it.
You'll notice the same behaviour in the 'View page' button on the edit screen.
This, of course, is not what you asked for but my intention in giving you this code is to demonstrate how and where we can modify the view-link.
Instead of adding the silly test=123 as we did above we can now set any link of our choice here and it will reflect in the admin listing.
I think you'll be able to craft the correct links matching your routes at this point.
For the list page, you'll find the entire 'page' in context here so you can get your field's values from $CTX (like the same above does for k_page_id). For the edit page, we of course have the $PAGE object.
Hope it helps.