Automattic\WooCommerce\Abilities
ActionableAbility::add_extensions_input_schema
Add the extensions property one time, at the top level of the input schema. It lists the fields that have an update_callback, and allows null for each one. Each oneOf, anyOf and allOf branch only accepts the key, so a branch with additionalProperties set to false does not reject it, and the schema does not grow with the number of branches.
Метод класса: ActionableAbility{}
Хуков нет.
Возвращает
array<string, mixed>.
Использование
// private - только в коде основоного (родительского) класса $result = $this->add_extensions_input_schema( $schema ): array;
- $schema(array<string, mixed>) (обязательный)
- Input schema.
Код ActionableAbility::add_extensions_input_schema() ActionableAbility::add extensions input schema WC 11.3.0
private function add_extensions_input_schema( array $schema ): array {
$extensions = array(
'type' => 'object',
'description' => __( 'Values to write to the fields that extensions add, keyed by extension namespace, then field. A null value deletes the value.', 'woocommerce' ),
'additionalProperties' => false,
);
foreach ( ExtensibleAbilities::get_fields( $this->get_resource() ) as $namespace => $fields ) {
$writable = array_filter(
$fields,
static function ( array $args ): bool {
return isset( $args['update_callback'] );
}
);
if ( empty( $writable ) ) {
continue;
}
$extensions['properties'][ $namespace ] = array(
'type' => 'object',
'properties' => array_map(
static function ( array $args ): array {
$field_schema = $args['schema'];
if ( isset( $field_schema['type'] ) ) {
$field_schema['type'] = array_values( array_unique( array_merge( (array) $field_schema['type'], array( 'null' ) ) ) );
}
if ( isset( $field_schema['enum'] ) && ! in_array( null, $field_schema['enum'], true ) ) {
$field_schema['enum'][] = null;
}
return $field_schema;
},
$writable
),
'additionalProperties' => false,
);
}
$schema['properties']['extensions'] = $extensions;
foreach ( array( 'oneOf', 'anyOf', 'allOf' ) as $keyword ) {
foreach ( array_keys( $schema[ $keyword ] ?? array() ) as $index ) {
$schema[ $keyword ][ $index ]['properties']['extensions'] = array(
'type' => 'object',
'description' => __( 'The fields are listed in the top-level extensions property.', 'woocommerce' ),
);
}
}
return $schema;
}