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

GeneralSettingsSchema::transform_setting_to_fieldprivateWC 1.0

Transform a WooCommerce setting into REST API field format.

Method of the class: GeneralSettingsSchema{}

No Hooks.

Returns

Array|null. Transformed field or null if should be skipped.

Usage

// private - for code of main (parent) class only
$result = $this->transform_setting_to_field( $setting ): ?array;
$setting(array) (required)
WooCommerce setting array.

GeneralSettingsSchema::transform_setting_to_field() code WC 10.4.3

private function transform_setting_to_field( array $setting ): ?array {
	$setting_id   = $setting['id'] ?? '';
	$setting_type = $setting['type'] ?? 'text';

	$field = array(
		'id'    => $setting_id,
		'label' => $setting['title'] ?? $setting_id,
		'type'  => $this->normalize_field_type( $setting_type ),
		'desc'  => $setting['desc'] ?? '',
	);

	// Add options for select fields.
	if ( isset( $setting['options'] ) && is_array( $setting['options'] ) ) {
		$field['options'] = $setting['options'];
	} else {
		// Generate options for special field types.
		$field['options'] = $this->get_field_options( $setting_id );
	}

	return $field;
}