Skip to content

Commit

Permalink
Add initial paged edits
Browse files Browse the repository at this point in the history
Early feature.
Off by default. Set `gravityview/features/paged-edit` filter to true.

Basics on #718
  • Loading branch information
soulseekah committed Oct 15, 2019
1 parent f1ab0cf commit 827450f
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 5 deletions.
49 changes: 49 additions & 0 deletions includes/extensions/edit-entry/class-edit-entry-render.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ class GravityView_Edit_Entry_Render {
*/
public $is_valid = NULL;

/**
* Internal page button states.
*
* @var bool
*
* @since develop
*/
public $show_previous_button;
public $show_next_button;
public $show_update_button;

function __construct( GravityView_Edit_Entry $loader ) {
$this->loader = $loader;
}
Expand Down Expand Up @@ -1109,6 +1120,8 @@ private function render_edit_form() {

add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 );
add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') );
add_filter( 'gform_next_button', array( $this, 'render_form_buttons' ) );
add_filter( 'gform_previous_button', array( $this, 'render_form_buttons' ) );
add_filter( 'gform_disable_view_counter', '__return_true' );

add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 );
Expand All @@ -1117,7 +1130,37 @@ private function render_edit_form() {
// We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin.
unset( $_GET['page'] );

$this->show_next_button = false;
$this->show_previous_button = false;

// TODO: Verify multiple-page forms
if ( GFCommon::has_pages( $this->form ) && apply_filters( 'gravityview/features/paged-edit', false ) ) {
if ( intval( $page_number = \GV\Utils::_POST( 'gform_target_page_number_' . $this->form['id'], 1 ) ) > 1 ) {
GFFormDisplay::$submission[ $this->form['id'] ][ 'form' ] = $this->form;
GFFormDisplay::$submission[ $this->form['id'] ][ 'is_valid' ] = true;
GFFormDisplay::$submission[ $this->form['id'] ][ 'page_number' ] = $page_number;
}

if ( ( $page_number = intval( $page_number ) ) < 2 ) {
$this->show_next_button = true; // First page
}

$last_page = \GFFormDisplay::get_max_page_number( $this->form );

$has_more_pages = $page_number < $last_page;

if ( $has_more_pages ) {
$this->show_next_button = true; // Not the last page
} else {
$this->show_update_button = true; // The last page
}

if ( $page_number > 1 ) {
$this->show_previous_button = true; // Not the first page
}
} else {
$this->show_update_button = true;
}

ob_start(); // Prevent PHP warnings possibly caused by prefilling list fields for conditional logic

Expand All @@ -1127,6 +1170,8 @@ private function render_edit_form() {

remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 );
remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) );
remove_filter( 'gform_next_button', array( $this, 'render_form_buttons' ) );
remove_filter( 'gform_previous_button', array( $this, 'render_form_buttons' ) );
remove_filter( 'gform_disable_view_counter', '__return_true' );
remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 );
remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 );
Expand Down Expand Up @@ -1740,6 +1785,10 @@ private function filter_fields( $fields, $configured_fields ) {

$field_type_blacklist = $this->loader->get_field_blacklist( $this->entry );

if ( empty( $configured_fields ) && apply_filters( 'gravityview/features/paged-edit', false ) ) {
$field_type_blacklist = array_diff( $field_type_blacklist, array( 'page' ) );
}

// First, remove blacklist or calculation fields
foreach ( $fields as $key => $field ) {

Expand Down
44 changes: 39 additions & 5 deletions includes/extensions/edit-entry/partials/form-buttons.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
* @file form-buttons.php
* @global GravityView_Edit_Entry_Render $object
*/

if ( current_filter() === 'gform_previous_button' ) {
if ( $object->show_previous_button || $object->show_update_button ) {
return; // Will be called later once more
}
}

if ( current_filter() === 'gform_next_button' ) {
if ( $object->show_update_button ) {
return; // Will be called later once more
}
}

?>
<div id="publishing-action">
<?php
Expand All @@ -29,7 +42,9 @@

$labels = array(
'cancel' => __( 'Cancel', 'gravityview' ),
'submit' => __( 'Update', 'gravityview')
'submit' => __( 'Update', 'gravityview '),
'next' => __( 'Next', 'gravityview' ),
'previous' => __( 'Previous', 'gravityview' ),
);

/**
Expand All @@ -42,11 +57,30 @@
*/
$labels = apply_filters( 'gravityview/edit_entry/button_labels', $labels, $object->form, $object->entry, $object->view_id );

$update_tabindex = GFCommon::get_tabindex();
$cancel_tabindex = GFCommon::get_tabindex();
?>
<input id="gform_submit_button_<?php echo esc_attr( $object->form['id'] ); ?>" class="btn btn-lg button button-large gform_button button-primary gv-button-update" type="submit" <?php echo $update_tabindex; ?> value="<?php echo esc_attr( $labels['submit'] ); ?>" name="save" />
if ( $object->show_previous_button ) {
$previous_tabindex = GFCommon::get_tabindex();
?>
<input id="gform_previous_button_<?php echo esc_attr( $object->form['id'] ); ?>" class="btn btn-lg button button-large gform_button button-primary gv-button-previous" type="submit" <?php echo $previous_tabindex; ?> value="<?php echo esc_attr( $labels['previous'] ); ?>" name="save" />
<?php
}

if ( $object->show_next_button ) {
$next_tabindex = GFCommon::get_tabindex();
?>
<input id="gform_next_button_<?php echo esc_attr( $object->form['id'] ); ?>" class="btn btn-lg button button-large gform_button button-primary gv-button-next" type="submit" <?php echo $next_tabindex; ?> value="<?php echo esc_attr( $labels['next'] ); ?>" name="save" />
<?php
}

if ( $object->show_update_button ) {
$update_tabindex = GFCommon::get_tabindex();
?>
<input id="gform_submit_button_<?php echo esc_attr( $object->form['id'] ); ?>" class="btn btn-lg button button-large gform_button button-primary gv-button-update" type="submit" <?php echo $update_tabindex; ?> value="<?php echo esc_attr( $labels['submit'] ); ?>" name="save" />
<?php
}

$cancel_tabindex = GFCommon::get_tabindex();

?>
<a class="btn btn-sm button button-small gv-button-cancel" <?php echo $cancel_tabindex; ?> href="<?php echo esc_url( $back_link ); ?>"><?php echo esc_attr( $labels['cancel'] ); ?></a>
<?php

Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Beautifully display your Gravity Forms entries. Learn more on [gravityview.co](h
* Added: `gravityview/search/sieve_choices` filter that sieves Search Widget field filter choices to only ones that have been used in entries
* Added: `gravityview/search/filter_details` filter for developers to modify search filter configurations
* Added: `gravityview/admin/available_fields` filter for developers to add their own assignable fields to View configurations
* Added: `gravityview/features/paged-edit` secret filter to enable early-bird paged form edit entries

= 2.4.1.1 on August 27, 2019 =

Expand Down

0 comments on commit 827450f

Please sign in to comment.