Skip to content

Commit ec9deec

Browse files
authored
Sort Gravity Forms options by title and display id (#135)
* Correction to readme about ConditionalLogicGroup
1 parent 5b1286a commit ec9deec

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
### Added
8+
- Sort Gravity Forms options by title and display the id
9+
710
[Unreleased]
811

912
## [1.41.5]

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ ACF's conditional logic groups work very similarly to groups' location rules. Fi
118118

119119
```php
120120
$conditional_logic = new ConditionalLogicGroup();
121-
$conditional_logic->add_rule( 'another_field', '==', true );
121+
$conditional_logic->add_rule( 'another_field', '==', '1' ); // For True/False fields, the value is a string, not boolean.
122122

123123
$text->add_conditional_logic( $conditional_logic );
124124
```

src/Field/GravityForms.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class GravityForms extends \Geniem\ACF\Field\Select {
1818
* @param string|null $name Name for the field.
1919
* @throws \Geniem\ACF\Exception Throw error if mandatory property is not set.
2020
*/
21-
public function __construct( string $label, string $key = null, string $name = null ) {
21+
public function __construct( string $label, ?string $key = null, ?string $name = null ) {
2222
parent::__construct( $label, $key, $name );
2323

2424
if ( ! class_exists( '\GFFormsModel' ) ) {
@@ -42,14 +42,17 @@ protected function populate_options() {
4242

4343
$table_name = \GFFormsModel::get_form_table_name();
4444

45-
$sql = "SELECT id, title from $table_name where is_active = %d and is_trash = %d";
45+
$sql = "SELECT id, title from $table_name where is_active = %d and is_trash = %d ORDER BY title ASC";
4646
$query = $wpdb->prepare( $sql, 1, 0 ); // phpcs:ignore
4747

4848
$gf_form_results = $wpdb->get_results( $query ); // phpcs:ignore
4949

5050
if ( ! empty( $gf_form_results ) ) {
5151
foreach ( $gf_form_results as $gf_form ) {
52-
$this->add_choice( $gf_form->title, $gf_form->id );
52+
53+
$display_title = $gf_form->title . ' (' . $gf_form->id . ')';
54+
55+
$this->add_choice( $display_title, $gf_form->id );
5356
}
5457
}
5558
}

0 commit comments

Comments
 (0)