GravityView  1.19.4
The best, easiest way to display Gravity Forms entries on your website.
Public Member Functions | Data Fields | Static Public Attributes | Protected Attributes | Private Member Functions | Static Private Attributes
GravityView_Edit_Entry_Render Class Reference

Public Member Functions

 __construct (GravityView_Edit_Entry $loader)
 
 custom_validation ($validation_results)
 Make validation work for Edit Entry. More...
 
 edit_entry_form ()
 Display the Edit Entry form. More...
 
 filter_modify_form_fields ($form, $ajax=false, $field_values= '')
 Modify the form fields that are shown when using GFFormDisplay::get_form() More...
 
 get_entry ()
 TODO: This seems to be hacky... More...
 
 gform_pre_validation ($form)
 Add field keys that Gravity Forms expects. More...
 
 init ($gv_data)
 Load required files and trigger edit flow. More...
 
 is_edit_entry ()
 Is the current page an Edit Entry page? More...
 
 is_edit_entry_submission ()
 Is the current page an Edit Entry page? More...
 
 load ()
 
 manage_conditional_logic ($has_conditional_logic, $form)
 Disable the Gravity Forms conditional logic script and features on the Edit Entry screen. More...
 
 modify_fileupload_settings ($plupload_init, $form_id, $instance)
 Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView Late validation done on self::custom_validation. More...
 
 prevent_maybe_process_form ()
 Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms backend form, we need to prevent them from saving twice. More...
 
 prevent_render_form ()
 Don't show any forms embedded on a page when GravityView is in Edit Entry mode. More...
 
 render_form_buttons ()
 Display the Update/Cancel/Delete buttons for the Edit Entry form. More...
 
 verify_nonce ()
 Is the current nonce valid for editing the entry? More...
 
 verify_user_can_edit_post ($field_content= '', $field, $value, $lead_id=0, $form_id)
 When displaying a field, check if it's a Post Field, and if so, make sure the post exists and current user has edit rights. More...
 

Data Fields

 $entry
 
 $fields_with_calculation = array()
 
 $form
 
 $form_after_validation = null
 
 $form_id
 
 $is_valid = NULL
 
 $total_fields = array()
 
 $view_id
 

Static Public Attributes

static $nonce_key
 

Protected Attributes

 $loader
 

Private Member Functions

 after_update ()
 Perform actions normally performed after updating a lead. More...
 
 check_user_cap_edit_field ($field)
 checks if user has permissions to edit a specific field More...
 
 fill_post_template ($template, $form, $entry, $do_shortcode=false)
 Convert a field content template into prepared output. More...
 
 filter_admin_only_fields ($fields=array(), $edit_fields=null, $form=array(), $view_id=0)
 Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property. More...
 
 filter_conditional_logic ($form)
 Remove the conditional logic rules from the form button and the form fields, if needed. More...
 
 get_configured_edit_fields ($form, $view_id)
 Get the Edit Entry fields as configured in the View. More...
 
 get_field_value ($field)
 Modify the value for the current field input. More...
 
 is_field_json_encoded ($field)
 Is the field stored in a JSON-encoded manner? More...
 
 maybe_print_message ()
 Display success or error message if the form has been submitted. More...
 
 maybe_update_post_fields ($form)
 Loop through the fields being edited and if they include Post fields, update the Entry's post object. More...
 
 merge_field_properties ($field, $field_setting)
 Override GF Form field properties with the ones defined on the View. More...
 
 print_scripts ()
 Force Gravity Forms to output scripts as if it were in the admin. More...
 
 process_save ()
 Process edit entry form save. More...
 
 process_save_process_files ($form_id)
 Have GF handle file uploads. More...
 
 render_edit_form ()
 Display the Edit Entry form in the original Gravity Forms format. More...
 
 setup_vars ()
 When Edit entry view is requested setup the vars. More...
 
 unset_hidden_field_values ()
 Delete the value of fields hidden by conditional logic when the entry is edited. More...
 
 update_calculation_fields ()
 
 update_post_image ($form, $field, $field_id, $value, $entry, $post_id)
 Handle updating the Post Image field. More...
 
 user_can_edit_entry ($echo=false)
 Check if the user can edit the entry. More...
 
 user_can_edit_field ($field, $echo=false)
 Check whether a field is editable by the current user, and optionally display an error message GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities. More...
 
 validate ()
 Process validation for a edit entry submission. More...
 

Static Private Attributes

static $nonce_field = 'is_gv_edit_entry'
 
static $original_entry = array()
 
static $original_form
 
static $supports_product_fields = false
 
static $supports_save_and_continue = false
 

Detailed Description

Definition at line 17 of file class-edit-entry-render.php.

Constructor & Destructor Documentation

__construct ( GravityView_Edit_Entry  $loader)

Definition at line 115 of file class-edit-entry-render.php.

References $loader.

Member Function Documentation

after_update ( )
private

Perform actions normally performed after updating a lead.

Since
1.8
See also
GFEntryDetail::lead_detail_page()
Returns
void

Definition at line 801 of file class-edit-entry-render.php.

References $entry, and $field.

Referenced by process_save().

check_user_cap_edit_field (   $field)
private

checks if user has permissions to edit a specific field

Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!!

Parameters
[type]$field [description]
Returns
bool

Definition at line 1959 of file class-edit-entry-render.php.

References $field, and GVCommon\has_cap().

Referenced by user_can_edit_field().

custom_validation (   $validation_results)

Make validation work for Edit Entry.

Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end form pretending to be a back-end form), validate() doesn't know we can't edit post fields. This goes through all the fields and if they're an invalid post field, we set them as valid. If there are still issues, we'll return false.

Parameters
[type]$validation_results [description]
Returns
[type] [description]

Definition at line 1384 of file class-edit-entry-render.php.

References $entry, $field, $value, and get_entry().

edit_entry_form ( )

Display the Edit Entry form.

Returns
void

Fixes weird wpautop() issue

See also
https://github.com/katzwebservices/GravityView/issues/451
Runs Filter:
gravityview_edit_entry_title Modify the edit entry title
Parameters
string$edit_entry_titleModify the "Edit Entry" title
GravityView_Edit_Entry_Render$thisThis object

Definition at line 826 of file class-edit-entry-render.php.

References GravityView_Edit_Entry\$file, gravityview_ob_include(), gravityview_strip_whitespace(), maybe_print_message(), and render_edit_form().

Referenced by init().

fill_post_template (   $template,
  $form,
  $entry,
  $do_shortcode = false 
)
private

Convert a field content template into prepared output.

GravityView_GFFormsModel::get_post_field_images()

Since
1.17
Parameters
string$templateThe content template for the field
array$formGravity Forms form
bool$do_shortcodeWhether to process shortcode inside content. In GF, only run on Custom Field and Post Content fields
Returns
mixed|string|void

Definition at line 771 of file class-edit-entry-render.php.

References $entry, $form, $output, GravityView_GFFormsModel\get_post_field_images(), and GRAVITYVIEW_DIR.

Referenced by maybe_update_post_fields().

filter_admin_only_fields (   $fields = array(),
  $edit_fields = null,
  $form = array(),
  $view_id = 0 
)
private

Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property.

Since
1.9.1
Parameters
array|GF_Field[]$fields Gravity Forms form fields
array | null$edit_fieldsFields for the Edit Entry tab configured in the View Configuration
array$formGF Form array
int$view_idView ID
Returns
array Possibly modified form array
Runs Filter:
gravityview/edit_entry/use_gf_admin_only_setting When Edit tab isn't configured, should the Gravity Forms "Admin Only" field settings be used to control field display to non-admins? Default: true If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators. If the Edit Entry tab is configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions
Since
1.9.1
Parameters
boolean$use_gf_adminonly_settingTrue: Hide field if set to Admin Only in GF and the user is not an admin. False: show field based on GV permissions, ignoring GF permissions.
array$formGF Form array
int$view_idView ID

Definition at line 1693 of file class-edit-entry-render.php.

References $field, $field_id, $field_value, $form, $value, $view_id, and GVCommon\has_cap().

Referenced by get_configured_edit_fields().

filter_conditional_logic (   $form)
private

Remove the conditional logic rules from the form button and the form fields, if needed.

Since
1.9
Parameters
array$formGravity Forms form
Returns
array Modified form, if not using Conditional Logic
Runs Filter:
gravityview/edit_entry/conditional_logic Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields?
Since
1.9
Parameters
bool$use_conditional_logicTrue: Gravity Forms will show/hide fields just like in the original form; False: conditional logic will be disabled and fields will be shown based on configuration. Default: true
array$formGravity Forms form

Definition at line 1795 of file class-edit-entry-render.php.

References $field, and $form.

Referenced by filter_modify_form_fields().

filter_modify_form_fields (   $form,
  $ajax = false,
  $field_values = '' 
)

Modify the form fields that are shown when using GFFormDisplay::get_form()

By default, all fields will be shown. We only want the Edit Tab configured fields to be shown.

Parameters
array$form
boolean$ajaxWhether in AJAX mode
array | string$field_valuesPassed parameters to the form
Since
1.9
Returns
array Modified form array

Definition at line 999 of file class-edit-entry-render.php.

References $form, $form_after_validation, filter_conditional_logic(), and get_configured_edit_fields().

get_configured_edit_fields (   $form,
  $view_id 
)
private

Get the Edit Entry fields as configured in the View.

Since
1.8
Parameters
int$view_id
Returns
array Array of fields that are configured in the Edit tab in the Admin
Runs Filter:
gravityview/edit_entry/form_fields Modify the fields displayed in Edit Entry form
Since
1.17
Parameters
GF_Field[]$fields Gravity Forms form fields
array | null$edit_fieldsFields for the Edit Entry tab configured in the View Configuration
array$formGF Form array (fields key modified to have only fields configured to show in Edit Entry)
int$view_idView ID

Definition at line 1538 of file class-edit-entry-render.php.

References $field, $form, $view_id, filter_admin_only_fields(), GravityView_View_Data\getInstance(), and merge_field_properties().

Referenced by filter_modify_form_fields(), and validate().

get_entry ( )

TODO: This seems to be hacky...

we should remove it. Entry is set when updating the form using setup_vars()! Get the current entry and set it if it's not yet set.

Returns
array Gravity Forms entry array

Definition at line 1515 of file class-edit-entry-render.php.

References $entry, gravityview_get_entry(), and GravityView_frontend\is_single_entry().

Referenced by custom_validation(), and gform_pre_validation().

get_field_value (   $field)
private

Modify the value for the current field input.

Parameters
GF_Field$field
Returns
array|mixed|string|void
Runs Filter:
gravityview/edit_entry/pre_populate/override Allow the pre-populated value to override saved value in Edit Entry form. By default, pre-populate mechanism only kicks on empty fields.
Parameters
booleanTrue: override saved values; False: don't override (default)
$fieldGF_Field object Gravity Forms field object
Since
1.13

Definition at line 1158 of file class-edit-entry-render.php.

References $field, $field_value, and gv_empty().

Referenced by verify_user_can_edit_post().

gform_pre_validation (   $form)

Add field keys that Gravity Forms expects.

See also
GFFormDisplay::validate()
Parameters
array$formGF Form
Returns
array Modified GF Form

this whole fileupload hack is because in the admin, Gravity Forms simply doesn't update any fileupload field if it's empty, but it DOES in the frontend.

What we have to do is set the value so that it doesn't get overwritten as empty on save and appears immediately in the Edit Entry screen again.

Definition at line 1229 of file class-edit-entry-render.php.

References $entry, $field, $form, $form_id, $value, get_entry(), and verify_nonce().

init (   $gv_data)

Load required files and trigger edit flow.

Run when the is_edit_entry returns true.

Parameters
GravityView_View_Data$gv_dataGravityView Data object
Returns
void

Definition at line 228 of file class-edit-entry-render.php.

References edit_entry_form(), print_scripts(), process_save(), setup_vars(), and user_can_edit_entry().

is_edit_entry ( )

Is the current page an Edit Entry page?

Returns
boolean

Definition at line 184 of file class-edit-entry-render.php.

References is_edit_entry_submission(), and GravityView_frontend\is_single_entry().

Referenced by manage_conditional_logic(), modify_fileupload_settings(), prevent_render_form(), and verify_nonce().

is_edit_entry_submission ( )

Is the current page an Edit Entry page?

Since
1.9
Returns
boolean

Definition at line 196 of file class-edit-entry-render.php.

Referenced by is_edit_entry(), prevent_maybe_process_form(), verify_nonce(), and verify_user_can_edit_post().

is_field_json_encoded (   $field)
private

Is the field stored in a JSON-encoded manner?

Parameters
GF_Field$field
Returns
bool True: stored in DB json_encode()'d; False: not encoded

Definition at line 740 of file class-edit-entry-render.php.

References $field.

Referenced by maybe_update_post_fields(), and unset_hidden_field_values().

load ( )

"GRAVITYVIEW_DIR" "../../../"

Definition at line 119 of file class-edit-entry-render.php.

References GRAVITYVIEW_DIR.

manage_conditional_logic (   $has_conditional_logic,
  $form 
)

Disable the Gravity Forms conditional logic script and features on the Edit Entry screen.

Since
1.9
Parameters
$has_conditional_logic
$form
Returns
mixed|void
See also
GravityView_Edit_Entry_Render::filter_conditional_logic for filter documentation

Definition at line 1829 of file class-edit-entry-render.php.

References $form, and is_edit_entry().

maybe_print_message ( )
private

Display success or error message if the form has been submitted.

GVCommon::generate_notice

Since
1.16.2.2
Returns
void
Runs Filter:
gravityview/edit_entry/success Modify the edit entry success message (including the anchor link)
Since
1.5.4
Parameters
string$entry_updated_messageExisting message
int$view_idView ID
array$entryGravity Forms entry array
string$back_linkURL to return to the original entry.
Since
1.6

Definition at line 892 of file class-edit-entry-render.php.

References $back_link, and GVCommon\generate_notice().

Referenced by edit_entry_form().

maybe_update_post_fields (   $form)
private

Loop through the fields being edited and if they include Post fields, update the Entry's post object.

Parameters
array$formGravity Forms form
Returns
void

Definition at line 619 of file class-edit-entry-render.php.

References $entry, $field, $field_id, $form, $value, fill_post_template(), GVCommon\has_cap(), is_field_json_encoded(), and update_post_image().

Referenced by process_save().

merge_field_properties (   $field,
  $field_setting 
)
private

Override GF Form field properties with the ones defined on the View.

Parameters
GF_Field$fieldGF Form field object
array$field_settingGV field options
Since
1.5
Returns
array|GF_Field

Normalize page numbers - avoid conflicts with page validation

Since
1.6

Definition at line 1657 of file class-edit-entry-render.php.

References $field.

Referenced by get_configured_edit_fields().

modify_fileupload_settings (   $plupload_init,
  $form_id,
  $instance 
)

Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView Late validation done on self::custom_validation.

Parameters
$plupload_initarray Plupload settings
$form_id
$instance
Returns
mixed

Definition at line 419 of file class-edit-entry-render.php.

References $field, $form, and is_edit_entry().

prevent_maybe_process_form ( )

Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms backend form, we need to prevent them from saving twice.

Returns
void

Definition at line 171 of file class-edit-entry-render.php.

References is_edit_entry_submission(), and verify_nonce().

prevent_render_form ( )

Don't show any forms embedded on a page when GravityView is in Edit Entry mode.

Adds a __return_empty_string filter on the Gravity Forms shortcode on the wp_head action And then removes it on the wp_footer action

Since
1.16.1
Returns
void

Definition at line 156 of file class-edit-entry-render.php.

References is_edit_entry().

print_scripts ( )
private

Force Gravity Forms to output scripts as if it were in the admin.

Returns
void

Definition at line 260 of file class-edit-entry-render.php.

References $gravityview_view, and GravityView_View\getInstance().

Referenced by init().

process_save ( )
private

Process edit entry form save.

This step is needed to unset the adminOnly from form fields, to add the calculation fields

to avoid the capability validation of the method save_lead for GF 1.9+

to force Gravity Forms to use $read_value_from_post in GFFormsModel::save_lead()

Since
1.17.2

Must be AFTER after_update()!

See also
https://github.com/gravityview/GravityView/issues/764
Runs Actions:
gravityview/edit_entry/after_update Perform an action after the entry has been updated using Edit Entry
Parameters
array$formGravity Forms form array
string$entry_idNumeric ID of the entry that was updated

Definition at line 275 of file class-edit-entry-render.php.

References $form, after_update(), maybe_update_post_fields(), process_save_process_files(), unset_hidden_field_values(), update_calculation_fields(), validate(), and verify_nonce().

Referenced by init().

process_save_process_files (   $form_id)
private

Have GF handle file uploads.

Copy of code from GFFormDisplay::process_form()

Parameters
int$form_id

Definition at line 399 of file class-edit-entry-render.php.

References $form_id.

Referenced by process_save().

render_edit_form ( )
private

Display the Edit Entry form in the original Gravity Forms format.

Since
1.9
Returns
void
Runs Actions:
gravityview/edit-entry/render/before Before rendering the Edit Entry form
Since
1.17
Parameters
GravityView_Edit_Entry_Render$this
Runs Actions:
gravityview/edit-entry/render/after After rendering the Edit Entry form
Since
1.17
Parameters
GravityView_Edit_Entry_Render$this

Definition at line 932 of file class-edit-entry-render.php.

References $html.

Referenced by edit_entry_form().

render_form_buttons ( )

Display the Update/Cancel/Delete buttons for the Edit Entry form.

Since
1.8
Returns
string

Definition at line 981 of file class-edit-entry-render.php.

References GravityView_Edit_Entry\$file, and gravityview_ob_include().

setup_vars ( )
private

When Edit entry view is requested setup the vars.

Definition at line 203 of file class-edit-entry-render.php.

References $entries, $gravityview_view, GravityView_Edit_Entry\get_nonce_key(), and GravityView_View\getInstance().

Referenced by init().

unset_hidden_field_values ( )
private

Delete the value of fields hidden by conditional logic when the entry is edited.

GFFormsModel::update_lead_field_value()

Since
1.17.4
Returns
void

Definition at line 363 of file class-edit-entry-render.php.

References $field, $field_value, and is_field_json_encoded().

Referenced by process_save().

update_calculation_fields ( )
private

Definition at line 462 of file class-edit-entry-render.php.

References $entry, and $form.

Referenced by process_save().

update_post_image (   $form,
  $field,
  $field_id,
  $value,
  $entry,
  $post_id 
)
private

Handle updating the Post Image field.

Sets a new Featured Image if configured in Gravity Forms; otherwise uploads/updates media

Since
1.17

GFFormsModel::media_handle_upload set_post_thumbnail

Parameters
array$formGF Form array
GF_Field$fieldGF Field
string$field_idNumeric ID of the field
string$value
array$entryGF Entry currently being edited
int$post_idID of the Post being edited
Returns
mixed|string

todo: As soon as ::media_handle_upload becomes a public method, move this call to ::media_handle_upload and remove the hack from this class. Note: the method became public in GF 1.9.17.7, but we don't require that version yet.

Definition at line 527 of file class-edit-entry-render.php.

References $ary, $entry, $field, $field_id, $form, $image_meta, $value, GRAVITYVIEW_DIR, and GravityView_GFFormsModel\media_handle_upload().

Referenced by maybe_update_post_fields().

user_can_edit_entry (   $echo = false)
private

Check if the user can edit the entry.

  • Is the nonce valid?
  • Does the user have the right caps for the entry
  • Is the entry in the trash?
Parameters
boolean$echoShow error messages in the form?
Returns
boolean True: can edit form. False: nope.
  1. Permalinks are turned off
  2. There are two entries embedded using oEmbed
  3. One of the entries has just been saved

If the Entry is embedded, there may be two entries on the same page. If that's the case, and one is being edited, the other should fail gracefully and not display an error.

Since
1.9

Definition at line 1854 of file class-edit-entry-render.php.

References GravityView_Edit_Entry\check_user_cap_edit_entry(), GVCommon\generate_notice(), GravityView_oEmbed\getInstance(), gravityview_get_link(), and verify_nonce().

Referenced by init().

user_can_edit_field (   $field,
  $echo = false 
)
private

Check whether a field is editable by the current user, and optionally display an error message GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities.

Parameters
array$fieldField or field settings array
boolean$echoWhether to show error message telling user they aren't allowed
Returns
boolean True: user can edit the current field; False: nope, they can't.

Definition at line 1927 of file class-edit-entry-render.php.

References $field, check_user_cap_edit_field(), and GVCommon\generate_notice().

validate ( )
private

Process validation for a edit entry submission.

Sets the is_valid object var

Returns
void

If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry GF User Registration Add-on version > 3.x has a different class name

Since
1.16.2

For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions. You can enter whatever you want! We try validating, and customize the results using self::custom_validation()

Definition at line 1335 of file class-edit-entry-render.php.

References get_configured_edit_fields().

Referenced by process_save().

verify_nonce ( )

Is the current nonce valid for editing the entry?

Returns
boolean
Runs Filter:
gravityview/edit_entry/verify_nonce Override Edit Entry nonce validation. Return true to declare nonce valid.
Since
1.13
Parameters
int | boolean$validFalse if invalid; 1 or 2 when nonce was generated
string$nonce_fieldKey used when validating submissions. Default: is_gv_edit_entry

Definition at line 1981 of file class-edit-entry-render.php.

References is_edit_entry(), and is_edit_entry_submission().

Referenced by gform_pre_validation(), prevent_maybe_process_form(), process_save(), and user_can_edit_entry().

verify_user_can_edit_post (   $field_content = '',
  $field,
  $value,
  $lead_id = 0,
  $form_id 
)

When displaying a field, check if it's a Post Field, and if so, make sure the post exists and current user has edit rights.

Since
1.16.2.2
Parameters
string$field_contentAlways empty. Returning not-empty overrides the input.
GF_Field$field
string | array$valueIf array, it's a field with multiple inputs. If string, single input.
int$lead_idLead ID. Always 0 for the gform_field_input filter.
int$form_idForm ID
Returns
string If error, the error message. If no error, blank string (modify_edit_field_input() runs next)
Runs Filter:
gravityview/edit_entry/unsupported_post_field_text Modify the message when someone isn't able to edit a post
Parameters
string$messageThe existing "You don't have permission..." text
Runs Filter:
gravityview/edit_entry/no_post_text Modify the message when someone is editing an entry attached to a post that no longer exists
Parameters
string$messageThe existing "This field is not editable; the post no longer exists." text

Definition at line 1033 of file class-edit-entry-render.php.

References $field, $field_value, $form_id, $gv_field, $value, GravityView_Fields\get_associated_field(), get_field_value(), and is_edit_entry_submission().

Field Documentation

$entry
$fields_with_calculation = array()

Definition at line 86 of file class-edit-entry-render.php.

$form
$form_after_validation = null

Definition at line 80 of file class-edit-entry-render.php.

Referenced by filter_modify_form_fields().

$form_id
$is_valid = NULL

Definition at line 113 of file class-edit-entry-render.php.

$loader
protected

Definition at line 22 of file class-edit-entry-render.php.

Referenced by __construct().

$nonce_field = 'is_gv_edit_entry'
staticprivate

Definition at line 33 of file class-edit-entry-render.php.

$nonce_key
static

Definition at line 27 of file class-edit-entry-render.php.

$original_entry = array()
staticprivate

Definition at line 59 of file class-edit-entry-render.php.

$original_form
staticprivate

Definition at line 73 of file class-edit-entry-render.php.

$supports_product_fields = false
staticprivate

Definition at line 45 of file class-edit-entry-render.php.

$supports_save_and_continue = false
staticprivate

Definition at line 39 of file class-edit-entry-render.php.

$total_fields = array()

Definition at line 92 of file class-edit-entry-render.php.

$view_id

The documentation for this class was generated from the following file: