Skip to content

Commit

Permalink
Add a "View in Admin" link to the Data Source links
Browse files Browse the repository at this point in the history
  • Loading branch information
zackkatz committed Nov 5, 2020
1 parent 6b3e300 commit 06a92db
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions class-gravityview-admin-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,25 @@ public function add_hooks() {
add_filter( 'gravityview/edit/link', array( $this, 'edit_entry_link' ), 10, 3 );

add_filter( 'gravityview/edit_entry/success', array( $this, 'edit_entry_success' ), 10, 4 );
add_filter( 'gravityview_connected_form_links', array( $this, 'add_data_source_link' ), 20, 2 );

add_action( 'gravityview_before', array( $this, 'maybe_output_notices' ) );


/**
* Modify the links shown in the Connected Form links in the Data Source box
*
* @param array $links Links to show
* @param array $form Gravity Forms form array
*/
public function add_data_source_link( $links, $form = array() ) {
global $post;

$links[] = $this->get_admin_link( $post->ID );

return $links;
}

private function is_admin_view_request() {

if ( ! $request = gravityview()->request ) {
Expand Down Expand Up @@ -200,15 +216,20 @@ public function view_admin_action( $actions, $post ) {
return $actions;
}

$action_link = add_query_arg( 'page', 'adminview', admin_url( 'edit.php?post_type=gravityview' ) );
$actions['adminview'] = $this->get_admin_link( $post->ID );

$actions['adminview'] = sprintf(
return $actions;
}

private function get_admin_link( $view_id = 0 ) {

$base = add_query_arg( 'page', 'adminview', admin_url( 'edit.php?post_type=gravityview' ) );

return sprintf(
'<a href="%s">%s</a>',
esc_url( add_query_arg( 'gvid', urlencode( $post->ID ), $action_link ) ),
esc_url( add_query_arg( 'gvid', urlencode( $view_id ), $base ) ),
__( 'View in Admin', 'gravityview-adminview' )
);

return $actions;
}

/**
Expand Down

0 comments on commit 06a92db

Please sign in to comment.