I achieved a successful modification of relation field with advanced_gui='1' setting to not show some pages. Unfortunately I could not find an easy way of doing this with overriding addon's theme snippet (content_list_relation_inner.html), but It wouldn't surprise me if it existed knowing how multi-layered CouchCMS code design is.

Here is a sample field definition with 2 new additions: dynamic='default_data' parameter and snippet's file name set inside —
Code: Select all
<cms:editable name='my_relation' label='My relation'
    type='relation'
    has='one'
    masterpage='related_masterpage.php'
    advanced_gui='1'
    dynamic='default_data'
    >test.inc</cms:editable>


Then I would add a line to k_override_renderables() function:

Code: Select all
$FUNCS->add_event_listener( K_THEME_NAME.'_alter_render_vars_content_list_relation_inner', 'MyTheme::_alter_render_vars__advancedgui_relation' );


The line above calls a driver that processes the content of "test.inc":

Code: Select all
static function _alter_render_vars__advancedgui_relation( &$candidate_templates, $name, &$args ){
    global $FUNCS;

    $cur_route = $FUNCS->current_route;
    $relation_field = $cur_route->resolved_values['field'];

    if( $relation_field->dynamic && $relation_field->default_data ){
        $relation_field->resolve_dynamic_params();

        $str = trim($relation_field->default_data);
        $pos = strpos( strtoupper($str), 'NOT ' );
        if( $pos===0 ){
            $ids = trim( substr($str, strpos($str, ' ')) ); // remove NOT
            $arr_ids = array_filter( explode(',', $ids), $FUNCS->_validate_natural );
            if( !count( $arr_ids ) ) return;
            $skip_ids = implode( ",", $arr_ids );
            if( !empty($FUNCS->current_route->resolved_values['data']) ){
                $FUNCS->current_route->resolved_values['data']->skip_ids = $skip_ids;
            }
        }
    }
}


If snippet prints something like "NOT 123, 456" (it is dynamic, so code can be used inside) then pages with mentioned ids (123, 456) will not be visible in list-view of relation selector.

A quick way to validate if the code's working or not after installation is to edit "couch/addons/relation/theme/content_list_relation_inner.html" theme snippet and add parameter return_sql='1' to cms:pages tag. The supplied ids will be visible in the generated sql query.

If you have any questions or issues, do not post below, ask in PM or email. Consider the code above as the most-recent working version.