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 at all.

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:68

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 at all.

Parameters

NameTypeDefaultDescription
$fieldarrayGravity Forms field.

Returns

  • bool

Since: %ver%

Source: src/Schema/GfConditionalLogic.php:181