Skip to main content

GravityKit\GravityMigrate\Schema\GfComposites

Puts a name or an address back together from the parts a source platform spread across

several fields, and sanitizes the text that goes into them.

Ninja Forms keeps a name as firstname and lastname fields and an address as address, city, zip and more, each its own row. Gravity Forms has one field with sub-inputs, so the import has to recognise the run and fold it back up.

Since: %ver%

Source: src/Schema/GfComposites.php:20

Details

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

Methods

MethodDescription
part_from_label()Which part of a composite field a label names, or null when it names none.
input_suffixes_for()Where each part of a composite of this type is stored.
parts_by_suffix()Which part each input suffix holds, the inverse of the two maps above.
part_of_input_id()The part a composite input id holds, or '' when the id names no part of this type.
input_id_for_part()The input of a field that holds one named part, where the field has such an input.
recompose_composite_fields()Recombines related simple fields into composite Gravity Forms fields.
build_address_field()Builds a composite Address field.
build_composite_label()Builds a composite label from a base label.
build_name_field()Builds a composite Name field.
derive_composite_group_label()Derives a composite group label from a part label.
normalize_composite_group_key()Normalizes a composite group key.
strip_composite_metadata()Removes composite metadata from fields.
sanitize_text()Sanitizes plain text values.
sanitize_textarea()Sanitizes textarea values.
build_address_inputs()Builds inputs for an Address field.
build_name_inputs()Builds inputs for a Name field.

Method Reference

part_from_label()

public static function part_from_label( string $text ): ?string

Which part of a composite field a label names, or null when it names none.

The words are matched whole, so "Fastest" is not a first name and "Countryside" is not a country. Everything that is not a letter or a digit becomes a space first, so "First_Name", "first-name" and "First Name" are one question rather than three.

Parameters

NameTypeDefaultDescription
$textstringA label, a field name, or both joined.

Returns

  • string | null — The composite part, or null.

Since: %ver%

Source: src/Schema/GfComposites.php:110

input_suffixes_for()

public static function input_suffixes_for( string $type ): array

Where each part of a composite of this type is stored.

Parameters

NameTypeDefaultDescription
$typestringUniversal composite type.

Returns

  • array<string, — string> Part name to input suffix. Empty for a type with no parts.

Since: %ver%

Source: src/Schema/GfComposites.php:148

parts_by_suffix()

public static function parts_by_suffix( string $type ): array

Which part each input suffix holds, the inverse of the two maps above.

The type has to be given, because the same digit means different things on the two fields: .2 is a name's prefix and an address's second line. An untyped lookup would answer one of them and be silently wrong about the other.

Parameters

NameTypeDefaultDescription
$typestringUniversal composite type: name or address.

Returns

  • array<string, — string> Input suffix to part name.

Since: %ver%

Source: src/Schema/GfComposites.php:169

part_of_input_id()

public static function part_of_input_id( string $input_id, string $type ): string

The part a composite input id holds, or '' when the id names no part of this type.

Parameters

NameTypeDefaultDescription
$input_idstringGravity Forms input id, such as 3.6.
$typestringUniversal composite type: name or address.

Returns

  • string

Since: %ver%

Source: src/Schema/GfComposites.php:183

input_id_for_part()

public static function input_id_for_part( $field_id, string $part, array $known_ids ): string

The input of a field that holds one named part, where the field has such an input.

A platform whose name field is one field rather than several still lets a sentence ask for one part of it, and that part has to be looked up on the field it landed on rather than assumed: only the parts a form actually shows get an input, so asking a two-part name for its prefix has to come back with nothing rather than with an id that resolves to nothing.

Parameters

NameTypeDefaultDescription
$field_idint | stringGravity Forms field id.
$partstringPart name, as the model spells it.
$known_idsarrayIds the form actually has, keyed by id.

Returns

  • string — The input id, or '' when the field has no such part.

Since: %ver%

Source: src/Schema/GfComposites.php:211

recompose_composite_fields()

public static function recompose_composite_fields( array $fields, array&$field_id_map=[], array&$warnings=[], array&$origins=[] ): array

Recombines related simple fields into composite Gravity Forms fields.

Parameters

NameTypeDefaultDescription
$fieldsarrayGravity Forms fields.
&$field_id_maparray[]Source identifier to Gravity Forms field id, by reference. Entries for a part are repointed at the part's input id, not at the composite field, so a reference resolves to the one box.
&$warningsarray[]Warning messages to append, by reference.
&$originsarray[]Assembled label => the labels of the fields it was assembled from, by reference. The assembled field is called something no source field is called -- "First Name" and "Last Name" become "Name" -- so the wizard's field report, which matches the two forms by label, needs telling or it grows a row for a field nobody put on the form.

Returns

  • array

Since: %ver%

Source: src/Schema/GfComposites.php:272

build_address_field()

public static function build_address_field( array $base_field, array $parts, string $label ): array

Builds a composite Address field.

Parameters

NameTypeDefaultDescription
$base_fieldarrayBase field configuration.
$partsarrayGrouped parts.
$labelstringComposite label.

Returns

  • array

Since: %ver%

Source: src/Schema/GfComposites.php:535

build_composite_label()

public static function build_composite_label( string $label, string $type ): string

Builds a composite label from a base label.

Parameters

NameTypeDefaultDescription
$labelstringBase label.
$typestringComposite type.

Returns

  • string

Since: %ver%

Source: src/Schema/GfComposites.php:577

build_name_field()

public static function build_name_field( array $base_field, array $parts, string $label ): array

Builds a composite Name field.

Parameters

NameTypeDefaultDescription
$base_fieldarrayBase field configuration.
$partsarrayGrouped parts.
$labelstringComposite label.

Returns

  • array

Since: %ver%

Source: src/Schema/GfComposites.php:607

derive_composite_group_label()

public static function derive_composite_group_label( string $label, string $type, string $part ): string

Derives a composite group label from a part label.

Parameters

NameTypeDefaultDescription
$labelstringPart label.
$typestringComposite type.
$partstringComposite part.

Returns

  • string

Since: %ver%

Source: src/Schema/GfComposites.php:638

normalize_composite_group_key()

public static function normalize_composite_group_key( string $value ): string

Normalizes a composite group key.

Parameters

NameTypeDefaultDescription
$valuestringGroup label.

Returns

  • string

Since: %ver%

Source: src/Schema/GfComposites.php:722

strip_composite_metadata()

public static function strip_composite_metadata( array $fields ): array

Removes composite metadata from fields.

Parameters

NameTypeDefaultDescription
$fieldsarrayField list.

Returns

  • array

Since: %ver%

Source: src/Schema/GfComposites.php:741

sanitize_text()

public static function sanitize_text( $value ): string

Sanitizes plain text values.

Parameters

NameTypeDefaultDescription
$valuemixedValue to sanitize.

Returns

  • string

Since: %ver%

Source: src/Schema/GfComposites.php:759

sanitize_textarea()

public static function sanitize_textarea( $value ): string

Sanitizes textarea values.

Parameters

NameTypeDefaultDescription
$valuemixedValue to sanitize.

Returns

  • string

Since: %ver%

Source: src/Schema/GfComposites.php:783

build_address_inputs()

public static function build_address_inputs( int $field_id, array $parts ): array

Builds inputs for an Address field.

Parameters

NameTypeDefaultDescription
$field_idintField ID.
$partsarrayGrouped parts.

Returns

  • array

Since: %ver%

Source: src/Schema/GfComposites.php:804

build_name_inputs()

public static function build_name_inputs( int $field_id, array $parts ): array

Builds inputs for a Name field.

Parameters

NameTypeDefaultDescription
$field_idintField ID.
$partsarrayGrouped parts.

Returns

  • array

Since: %ver%

Source: src/Schema/GfComposites.php:848