ACF\AI\GEO

Schema::get_preferred_object_typepublic staticACF 6.8.0

Get the preferred object type for a property

When a property expects an object, this returns the most appropriate type. For properties with multiple possible types, returns the first one.

Method of the class: Schema{}

No Hooks.

Returns

String|null. The type name, or null if property doesn't expect an object

Usage

$result = Schema::get_preferred_object_type( $property );
$property(string) (required)
The property name.

Changelog

Since 6.8.0 Introduced.

Schema::get_preferred_object_type() code ACF 6.8.8

public static function get_preferred_object_type( $property ) {
	if ( ! self::property_expects_object( $property ) ) {
		return null;
	}

	$range = self::get_property_range( $property );

	// Filter out primitive types
	$object_types = array_diff( $range, self::$primitive_types );

	// Return first object type
	return ! empty( $object_types ) ? reset( $object_types ) : null;
}