Skip to content

Commit

Permalink
Add title type
Browse files Browse the repository at this point in the history
Signed-off-by: brookewp <[email protected]>
  • Loading branch information
brookewp committed Feb 27, 2025
1 parent 73a6bfc commit df8d7b3
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/extending/query-output_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Unless your API returns a single value, `type` will be constructed of an associa
- `null`
- `number`
- `string`
- `title`
- `url`
- `uuid`

Expand Down
4 changes: 2 additions & 2 deletions example/rest-api/art-institute/art-institute.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function register_aic_block(): void {
],
'title' => [
'name' => 'Title',
'type' => 'string',
'type' => 'title',
'path' => '$.title',
],
'image_id' => [
Expand Down Expand Up @@ -136,7 +136,7 @@ function register_aic_block(): void {
],
'title' => [
'name' => 'Title',
'type' => 'string',
'type' => 'title',
'path' => '$.title',
],
'image_url' => [
Expand Down
6 changes: 5 additions & 1 deletion inc/Editor/BlockPatterns/BlockPatterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,16 @@ public static function register_default_block_pattern( string $block_name, strin
$bindings['heading']['content'] = [ $field, $name ];
break;
}

$bindings['paragraphs'][] = [
'content' => [ $field, $name ],
];
break;

case 'title':
$bindings['heading']['content'] = [ $field, $name ];
break;

case 'image_alt':
$bindings['image']['alt'] = [ $field, $name ];
break;
Expand Down
4 changes: 2 additions & 2 deletions inc/Integrations/SalesforceD2C/SalesforceD2CIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static function get_queries( SalesforceD2CDataSource $data_source ): arr
'name' => [
'name' => 'Name',
'path' => '$.name',
'type' => 'string',
'type' => 'title',
],
'sku' => [
'name' => 'SKU',
Expand Down Expand Up @@ -134,7 +134,7 @@ private static function get_queries( SalesforceD2CDataSource $data_source ): arr
'name' => [
'name' => 'Name',
'path' => '$.name',
'type' => 'string',
'type' => 'title',
],
'image_url' => [
'name' => 'Image URL',
Expand Down
4 changes: 2 additions & 2 deletions inc/Integrations/Shopify/ShopifyIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static function get_queries( ShopifyDataSource $data_source ): array {
'title' => [
'name' => 'Title',
'path' => '$.data.product.title',
'type' => 'string',
'type' => 'title',
],
'variant_id' => [
'name' => 'Variant ID',
Expand Down Expand Up @@ -109,7 +109,7 @@ public static function get_queries( ShopifyDataSource $data_source ): array {
'title' => [
'name' => 'Product title',
'path' => '$.node.title',
'type' => 'string',
'type' => 'title',
],
],
],
Expand Down
3 changes: 3 additions & 0 deletions inc/Sanitization/Sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public static function sanitize_primitive_type( string $type_name, mixed $value
case 'string':
return sanitize_text_field( strval( $value ) );

case 'title':
return sanitize_text_field( strval( $value ) );

case 'button_text':
case 'html':
case 'id':
Expand Down
1 change: 1 addition & 0 deletions inc/Validation/ConfigSchemas.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ private static function generate_http_query_config_schema(): array {
'image_alt',
'image_url',
'markdown',
'title',
// 'json_path' is omitted since it likely has no user utility.
'url',
'uuid',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function ItemList( props: ItemListProps ) {

// Find title field from availableBindings by checking type
const titleField = Object.entries( availableBindings ).find(
( [ _, binding ] ) => binding.type === 'string' && binding.name.toLowerCase() === 'title'
( [ _, binding ] ) => binding.type === 'title'
)?.[ 0 ];

// Find media field from availableBindings by checking type
Expand Down
1 change: 1 addition & 0 deletions src/blocks/remote-data-container/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export const TEXT_FIELD_TYPES = [
'markdown',
'number',
'string',
'title',
];
1 change: 1 addition & 0 deletions tests/inc/Validation/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function testValidPrimitiveTypes(): void {
'image_url' => 'https://example.com/image.jpg',
'json_path' => '$.foo.bar',
'markdown' => '# Hello, world!',
'title' => 'A Title',
'url' => 'https://example.com/foo',
'uuid' => '123e4567-e89b-12d3-a456-426614174000',
] ) );
Expand Down

0 comments on commit df8d7b3

Please sign in to comment.