Skip to content

Commit 86034ba

Browse files
committed
feat: airtable hooks
1 parent 9dc5a7e commit 86034ba

1 file changed

Lines changed: 135 additions & 0 deletions

File tree

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?php
2+
/**
3+
* Airtable addon hooks
4+
*
5+
* @package formsbridge
6+
*/
7+
8+
if ( ! defined( 'ABSPATH' ) ) {
9+
exit();
10+
}
11+
12+
add_filter(
13+
'forms_bridge_bridge_schema',
14+
function ( $schema, $addon ) {
15+
if ( 'airtable' !== $addon ) {
16+
return $schema;
17+
}
18+
19+
$schema['properties']['endpoint']['default'] = '/{base_id}/{table_name}';
20+
21+
$schema['properties']['backend']['const'] = 'Airtable API';
22+
23+
$schema['properties']['method']['enum'] = array( 'GET', 'POST', 'PUT', 'PATCH' );
24+
$schema['properties']['method']['default'] = 'POST';
25+
26+
return $schema;
27+
},
28+
10,
29+
2
30+
);
31+
32+
add_filter(
33+
'forms_bridge_template_defaults',
34+
function ( $defaults, $addon, $schema ) {
35+
if ( 'airtable' !== $addon ) {
36+
return $defaults;
37+
}
38+
39+
$defaults = wpct_plugin_merge_object(
40+
array(
41+
'fields' => array(
42+
array(
43+
'ref' => '#credential',
44+
'name' => 'name',
45+
'label' => __( 'Name', 'forms-bridge' ),
46+
'type' => 'text',
47+
'required' => true,
48+
),
49+
array(
50+
'ref' => '#credential',
51+
'name' => 'schema',
52+
'type' => 'text',
53+
'value' => 'Bearer',
54+
),
55+
array(
56+
'ref' => '#credential',
57+
'name' => 'api_key',
58+
'label' => __( 'API Key', 'forms-bridge' ),
59+
'type' => 'text',
60+
'required' => true,
61+
),
62+
array(
63+
'ref' => '#bridge',
64+
'name' => 'endpoint',
65+
'label' => __( 'Endpoint', 'forms-bridge' ),
66+
'description' => __( 'Format: base_id/table_name', 'forms-bridge' ),
67+
'type' => 'text',
68+
'required' => true,
69+
),
70+
array(
71+
'ref' => '#bridge',
72+
'name' => 'method',
73+
'value' => 'POST',
74+
),
75+
array(
76+
'ref' => '#backend',
77+
'name' => 'name',
78+
'default' => 'Airtable API',
79+
),
80+
array(
81+
'ref' => '#backend',
82+
'name' => 'base_url',
83+
'value' => 'https://api.airtable.com',
84+
),
85+
),
86+
'backend' => array(
87+
'name' => 'Airtable API',
88+
'base_url' => 'https://api.airtable.com',
89+
'headers' => array(
90+
array(
91+
'name' => 'Authorization',
92+
'value' => 'Bearer {api_key}',
93+
),
94+
array(
95+
'name' => 'Content-Type',
96+
'value' => 'application/json',
97+
),
98+
),
99+
),
100+
'bridge' => array(
101+
'backend' => 'Airtable API',
102+
'endpoint' => '',
103+
),
104+
'credential' => array(
105+
'name' => '',
106+
'schema' => 'Bearer',
107+
'api_key' => '',
108+
),
109+
),
110+
$defaults,
111+
$schema
112+
);
113+
114+
return $defaults;
115+
},
116+
10,
117+
3
118+
);
119+
120+
add_filter(
121+
'forms_bridge_template_data',
122+
function ( $data, $template_id ) {
123+
if ( strpos( $template_id, 'airtable-' ) !== 0 ) {
124+
return $data;
125+
}
126+
127+
// Ensure endpoint format is correct for Airtable
128+
if ( ! empty( $data['bridge']['endpoint'] ) && strpos( $data['bridge']['endpoint'], '/' ) === false ) {
129+
$data['bridge']['endpoint'] = '/' . $data['bridge']['endpoint'];
130+
}
131+
return $data;
132+
},
133+
10,
134+
2
135+
);

0 commit comments

Comments
 (0)