spivurno
10/28/2015 - 6:47 PM

GP Unique ID // Gravity Perks // Editable Input for Gravity View

GP Unique ID // Gravity Perks // Editable Input for Gravity View

<?php
/**
 * GP Unique ID // Gravity Perks // Editable Input for Gravity View
 * http://gravitywiz.com/documentation/gp-unique-id/
 *
 * Updates the input HTML from "hidden" (default) to "text" when viewing entry via Gravity View edit view.
 */
if( function_exists( 'gp_unique_id' ) ) {

	add_filter( 'gpui_input_html_options', function ( $options ) {
		if( rgget( 'view' ) == 'entry' && rgget( 'edit' ) ) {
			$options['input_type'] = 'text';
		}
		return $options;
	} );

	add_action( 'init', function () {
		if( rgget( 'view' ) == 'entry' && rgget( 'edit' ) ) {
			remove_filter( 'gform_field_css_class', array( gp_unique_id()->field_obj, 'field_class' ), 10, 3 );
		}
	}, 11 );
	
	// enable GP Read Only for all uuid fields
        add_filter( 'gform_pre_render', function( $form ) {
		foreach( $form['fields'] as &$field ) {
			if( GFFormsModel::get_input_type( $field ) == 'uid' ) {
				$field->gwreadonly_enable = true;
			}
		}
		return $form;
	} );

}