Skip to main content

GravityKit\GravityMigrate\Schema\GfConditionalLogic

Reads a Gravity Forms field's conditional logic into a shape target adapters can emit.

Gravity Forms stores one flat rule list plus a single all/any relation:

[ 'actionType' => 'show', 'logicType' => 'all', 'rules' => [ [ 'fieldId', 'operator', 'value' ] ] ]

A form that loses its logic on the way out arrives with every field permanently visible, which looks like a working form.

Since: %ver%

Source: src/Schema/GfConditionalLogic.php:22

Details​

  • Kind: class
  • Namespace: GravityKit\GravityMigrate\Schema

Methods​

MethodDescription
rule()Builds a Gravity Forms conditional-logic rule that Gravity Forms can actually evaluate.
normalize()Normalizes a field's conditional logic.
has_logic()Whether a field carries conditional logic that does something.
hides_with_no_rules()Whether an empty rule set hides the field it is on.

Method Reference​

rule()​

public static function rule( $field_id, string $operator, $value='' ): ?array

Builds a Gravity Forms conditional-logic rule that Gravity Forms can actually evaluate.

GFFormsModel::matches_conditional_operation() (and the JS twin, gf_matches_operation) handle exactly is, isnot, >, <, greater_than, less_than, contains, starts_with and ends_with. Every other operator falls through to return false, so a rule carrying one never matches: a field set to show when an answer is empty never appears, and a field set to hide when an answer is filled never hides.

Emptiness needs no dedicated operator -- comparing against '' with is or isnot gives the intended result -- so isblank and isnotblank are rewritten rather than refused.

Parameters​

NameTypeDefaultDescription
$field_idint | stringGravity Forms field id the rule tests.
$operatorstringCandidate Gravity Forms operator.
$valuemixed''Rule value.

Returns​

  • array | null — The rule, or null when Gravity Forms cannot express it.

Since: %ver%

Source: src/Schema/GfConditionalLogic.php:87

normalize()​

public static function normalize( array $field, array $field_id_map ): ?array

Normalizes a field's conditional logic.

Returns null when the field has no logic, when the logic is malformed, or when a rule points at a field that did not survive the export. A partial rule set is never returned: dropping one rule from an "all" relation widens when the field shows, and dropping one from an "any" relation narrows it, so both change behavior silently.

Parameters​

NameTypeDefaultDescription
$fieldarrayGravity Forms field.
$field_id_maparrayGravity Forms field id => target field identifier.

Returns​

  • array | null

Since: %ver%

Source: src/Schema/GfConditionalLogic.php:126

has_logic()​

public static function has_logic( array $field ): bool

Whether a field carries conditional logic that does something.

A rule set with no rules is not nothing. Gravity Forms counts matches against sizeof( $logic['rules'] ), so an empty "all" set is fully matched and an empty "any" set is not (forms_model.php:8180-8183): hide/all and show/any hide the field outright, and a hidden field is neither validated nor saved. Reading that as "no logic" exported a field Gravity Forms never showed as a visible, required one, and nothing said so. normalize() still returns null for it -- there is no rule to carry -- so the caller's "could not be recreated" warning is what names the field.

Parameters​

NameTypeDefaultDescription
$fieldarrayGravity Forms field.

Returns​

  • bool

Since: %ver%

Source: src/Schema/GfConditionalLogic.php:189

hides_with_no_rules()​

public static function hides_with_no_rules( array $logic ): bool

Whether an empty rule set hides the field it is on.

Parameters​

NameTypeDefaultDescription
$logicarrayA field's conditionalLogic.

Returns​

  • bool

Since: %ver%

Source: src/Schema/GfConditionalLogic.php:208