Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\PaymentGateways\Schema
AbstractPaymentGatewaySettingsSchema::transform_field_to_schema
Transform WooCommerce field definition to API field schema.
Method of the class: AbstractPaymentGatewaySettingsSchema{}
No Hooks.
Returns
Array.
Usage
// private - for code of main (parent) class only $result = $this->transform_field_to_schema( $id, $field, $gateway ): array;
- $id(string) (required)
- Field ID.
- $field(array) (required)
- Field definition.
- $gateway(WC_Payment_Gateway) (required)
- Gateway instance.
AbstractPaymentGatewaySettingsSchema::transform_field_to_schema() AbstractPaymentGatewaySettingsSchema::transform field to schema code WC 10.4.3
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;
}