Thanks @codepuncher for the solution here! Super helpful!
I know it’s been a while but I ended up converting this. I also added some additional logic to handle the separators since they end up getting pushed next to each other depending on what your setup looks like.
<?php
add_filter( 'fl_builder_content_panel_data', function ( array $data ): array {
$group_name = RE_FL_BUILDER_GROUP;
// Get the key of the projects module group.
$group_handle = sanitize_key( $group_name );
if ( !$group_handle ) {
return $data;
}
$module_views = $data['tabs']['modules']['views'];
// Find the index of the matching group
$target_index = null;
foreach( $module_views as $key => $view ) {
if ( isset( $view['handle'] ) && $view['handle'] == $group_handle ) {
$target_index = $key;
break;
}
}
// If the index can't be found exit
if ( !$target_index ) {
return $data;
}
// Remove the new default and add it back in to the start
$new_default = $module_views[ $target_index ];
unset( $module_views[ $target_index ] );
array_unshift( $module_views, $new_default );
// Now let's clean up the separators
$new_views = array_filter( $module_views, function( $item ) {
return !( isset( $item['type'] ) && $item['type'] == 'separator' );
} );
// Create a new separator objects. Since splice will take a full array
// we need to nest our new value
$separator = [ [
'type' => 'separator'
] ];
// Add separator after the first item
array_splice( $new_views, 1, 0, $separator );
// Add separator before the last item
array_splice( $new_views, count( $new_views ) - 1 , 0, $separator );
$data['tabs']['modules']['views'] = $new_views;
return $data;
} );