Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\PaymentGateways\Schema

AbstractPaymentGatewaySettingsSchema::transform_field_to_schemaprivateWC 1.0

Transform WooCommerce field definition to API field schema.

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

Хуков нет.

Возвращает

Массив.

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

// private - только в коде основоного (родительского) класса
$result = $this->transform_field_to_schema( $id, $field, $gateway ): array;
$id(строка) (обязательный)
Field ID.
$field(массив) (обязательный)
Field definition.
$gateway(WC_Payment_Gateway) (обязательный)
Gateway instance.

Код AbstractPaymentGatewaySettingsSchema::transform_field_to_schema() WC 11.0.1

private function transform_field_to_schema( string $id, array $field, WC_Payment_Gateway $gateway ): array {
	$field_type = $field['type'] ?? 'text';

	$schema_field = array(
		'id'    => $id,
		'label' => $field['title'] ?? $field['label'] ?? '',
		'type'  => $this->normalize_field_type( $field_type ),
		'desc'  => $field['description'] ?? '',
	);

	// For checkbox fields, use the 'label' field as description if no explicit description exists.
	if ( 'checkbox' === $field_type && empty( $schema_field['desc'] ) && ! empty( $field['label'] ) ) {
		$schema_field['desc'] = $field['label'];
	}

	// Add options for select/multiselect fields.
	if ( in_array( $schema_field['type'], array( 'select', 'multiselect' ), true ) ) {
		if ( ! empty( $field['options'] ) ) {
			$schema_field['options'] = $field['options'];
		} else {
			// Generate options dynamically for specific fields.
			$schema_field['options'] = $this->get_field_options( $id );
		}
	}

	return $schema_field;
}