ACF\AI\GEO

FieldSettings::get_output_format_choicesprivateACF 6.8.0

Get output format choices for a field

Returns the valid output formats for the field's type and selected property. For example, an Image field mapped to the 'image' property can output either 'URL' or 'ImageObject'.

Метод класса: FieldSettings{}

Хуки из метода

Возвращает

array. Array of format => label pairs.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->get_output_format_choices( $field );
$field(массив) (обязательный)
The field being edited.

Список изменений

С версии 6.8.0 Введена.

Код FieldSettings::get_output_format_choices() ACF 6.8.8

private function get_output_format_choices( $field ) {
	$field_type         = $field['type'] ?? '';
	$qualified_property = $field['schema_property'] ?? '';

	// If no property selected yet, return empty choices.
	if ( empty( $qualified_property ) ) {
		return array();
	}

	// Extract just the property name from qualified property (e.g., "Recipe.recipeYield" -> "recipeYield").
	$property      = Schema::get_property_name( $qualified_property );
	$valid_formats = Schema::get_valid_output_formats( $field_type, $property );

	if ( empty( $valid_formats ) ) {
		return array();
	}

	// Build choices array with format as both key and label.
	$choices = array();
	foreach ( $valid_formats as $format ) {
		$choices[ $format ] = $format;
	}

	/**
	 * Filter the available output format choices.
	 *
	 * @param array  $choices    The output format choices.
	 * @param string $field_type The ACF field type.
	 * @param string $property   The selected Schema.org property.
	 */
	return apply_filters( 'acf/schema/output_format_choices', $choices, $field_type, $property );
}