Skip to content

Commit

Permalink
Fix sorting complex fields
Browse files Browse the repository at this point in the history
- Remove the option to sort by composite fields like Name, Address,
Product; Gravity Forms doesn't process those sort requests properly
- Remove List and Paragraph fields from being sortable
- Add `$include_parent_field` parameter in
`gravityview_get_form_fields()` function.
  • Loading branch information
zackkatz committed Jun 20, 2014
1 parent c15266a commit ca490ef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions gravityview.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ public static function get_default_widget_areas() {
* @access public
* @return void
*/
function default_field_blacklist() {
return array( 'html', 'section', 'captcha', 'page' );
function default_field_blacklist( $array = array() ) {
return array_merge( $array, array( 'html', 'section', 'captcha', 'page' ) );
}


Expand Down
19 changes: 12 additions & 7 deletions includes/connector-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function gravityview_get_forms() {
* @param string|array $form_id (default: '') or $form object
* @return array
*/
function gravityview_get_form_fields( $form = '', $add_default_properties = false ) {
function gravityview_get_form_fields( $form = '', $add_default_properties = false, $include_parent_field = true ) {

if( !is_array( $form ) ) {
$form = gravityview_get_form( $form );
Expand All @@ -87,7 +87,10 @@ function gravityview_get_form_fields( $form = '', $add_default_properties = fals

if( $form ) {
foreach( $form['fields'] as $field ) {
$fields[ $field['id'] ] = array( 'label' => $field['label'], 'type' => $field['type'] );

if( $include_parent_field || empty( $field['inputs'] ) ) {
$fields[ $field['id'] ] = array( 'label' => $field['label'], 'type' => $field['type'] );
}

if( $add_default_properties && !empty( $field['inputs'] ) ) {
foreach( $field['inputs'] as $input ) {
Expand Down Expand Up @@ -236,17 +239,19 @@ function gravityview_get_sortable_fields( $formid, $current = '' ) {
return $output;
}

$fields = gravityview_get_form_fields( $formid );
// Get fields with sub-inputs and no parent
$fields = gravityview_get_form_fields( $formid, true, false );

if( !empty( $fields ) ) {

$blacklist_field_types = apply_filters( 'gravityview_blacklist_field_types', array() );
$blacklist_field_types = apply_filters( 'gravityview_blacklist_field_types', array( 'list', 'textarea' ) );

$output .= '<option value="date_created" '. selected( 'date_created', $current, false ).'>'. esc_html__( 'Date Created', 'gravity-view' ) .'</option>';

foreach( $fields as $id => $field ) {
if( in_array( $field['type'], $blacklist_field_types ) ) {
continue;
}

if( in_array( $field['type'], $blacklist_field_types ) ) { continue; }

$output .= '<option value="'. $id .'" '. selected( $id, $current, false ).'>'. esc_attr( $field['label'] ) .'</option>';
}

Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ Beautifully display your Gravity Forms entries.
* Added: `search_field` parameter to the shortcode. This allows you to specify a field ID where you want the search performed (The search itself is defined in `search_value`)
* Added: [Using the Shortcode](https://katzwebservices.zendesk.com/hc/en-us/articles/202934188) help article
* Added: Data Source added to the Views page
* Fixed: Apostrophes no longer have slashes before them
* Fixed: Field labels escaping issue (`It's an Example` was displaying as `It\'s an Example`)
* Fixed: Settings "gear" not showing when adding a new field
* Fixed: Sorting issues
- Remove the option to sort by composite fields like Name, Address, Product; Gravity Forms doesn't process those sort requests properly
- Remove List and Paragraph fields from being sortable
* Improved: Added visibility toggles to some Field Settings. For example, if the "Show Label" setting is not checked, then the "Custom Label" setting is hidden.
* Modified how data is sent to the template: removed the magic methods getter/setters setting the `$var` variable - not data is stored directly as object parameters.
* Added many translations. Thanks everyone!
* Bengali translation by [@tareqhi](https://www.transifex.com/accounts/profile/tareqhi/)
* German translation by [@seschwarz](https://www.transifex.com/accounts/profile/seschwarz/)
Expand Down

0 comments on commit ca490ef

Please sign in to comment.