From 8ff5de65d8e32c1c0fe30333ae13b413bca80046 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 26 Nov 2026 12:52:43 +0000 Subject: [PATCH 1/2] fall back to the field name when a hubspot field has no label Amp-Thread-ID: https://ampcode.com/threads/T-01a217e6-19d9-7669-a90d-3f6d0240771f Co-authored-by: Amp --- src/FormConnectors/HubSpot/HubSpotClient.php | 2 +- .../HubSpot/HubSpotConnectorTest.php | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/FormConnectors/HubSpot/HubSpotClient.php b/src/FormConnectors/HubSpot/HubSpotClient.php index feddd8a..60d8e60 100644 --- a/src/FormConnectors/HubSpot/HubSpotClient.php +++ b/src/FormConnectors/HubSpot/HubSpotClient.php @@ -87,7 +87,7 @@ private function summarise(array $form): array ->reject(fn (array $field): bool => $field['name'] === 'email') ->map(fn (array $field): array => Arr::removeNullValues([ 'name' => $field['name'], - 'label' => $field['label'], + 'label' => $field['label'] ?? $field['name'], 'object_type_id' => $field['objectTypeId'], 'required' => (bool) ($field['required'] ?? false), ])) diff --git a/tests/FormConnectors/HubSpot/HubSpotConnectorTest.php b/tests/FormConnectors/HubSpot/HubSpotConnectorTest.php index fa4367e..6319f79 100644 --- a/tests/FormConnectors/HubSpot/HubSpotConnectorTest.php +++ b/tests/FormConnectors/HubSpot/HubSpotConnectorTest.php @@ -211,6 +211,30 @@ public function it_excludes_the_email_property_from_the_summary() $this->assertNotContains('email', array_column($properties, 'name')); } + /** + * @see https://github.com/statamic/forms-pro/issues/38 + */ + #[Test] + public function it_falls_back_to_the_property_name_when_a_field_has_no_label() + { + $definition = $this->definition(); + $definition['fieldGroups'][0]['fields'][] = [ + 'objectTypeId' => '0-1', 'name' => 'lead_source', 'required' => false, 'hidden' => true, + ]; + + $this->fakeHttp([ + 'api.hubapi.com/marketing/v3/forms*' => Http::response(['results' => [$definition]]), + 'api.hubapi.com/communication-preferences/*' => Http::response(['subscriptionDefinitions' => []]), + ]); + + $properties = (new HubSpot)->forForm($this->form())->render()->toArray()['props']['hubspotForms'][self::FORM]['properties']; + + $this->assertContains( + ['name' => 'lead_source', 'label' => 'lead_source', 'object_type_id' => '0-1', 'required' => false], + $properties, + ); + } + #[Test] public function it_still_renders_the_forms_when_the_subscription_lookup_fails() { From 1467bfc7ff269a7a0c9f1313b534f5deaa485585 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 26 Nov 2026 12:57:15 +0000 Subject: [PATCH 2/2] exclude hidden hubspot fields from the property mappings Amp-Thread-ID: https://ampcode.com/threads/T-01a217e6-19d9-7669-a90d-3f6d0240771f Co-authored-by: Amp --- src/FormConnectors/HubSpot/HubSpotClient.php | 4 ++-- tests/FormConnectors/HubSpot/HubSpotConnectorTest.php | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/FormConnectors/HubSpot/HubSpotClient.php b/src/FormConnectors/HubSpot/HubSpotClient.php index 60d8e60..50aa7f0 100644 --- a/src/FormConnectors/HubSpot/HubSpotClient.php +++ b/src/FormConnectors/HubSpot/HubSpotClient.php @@ -84,10 +84,10 @@ private function summarise(array $form): array return [ 'name' => $form['name'], 'properties' => $fields - ->reject(fn (array $field): bool => $field['name'] === 'email') + ->reject(fn (array $field): bool => $field['name'] === 'email' || ($field['hidden'] ?? false)) ->map(fn (array $field): array => Arr::removeNullValues([ 'name' => $field['name'], - 'label' => $field['label'] ?? $field['name'], + 'label' => $field['label'], 'object_type_id' => $field['objectTypeId'], 'required' => (bool) ($field['required'] ?? false), ])) diff --git a/tests/FormConnectors/HubSpot/HubSpotConnectorTest.php b/tests/FormConnectors/HubSpot/HubSpotConnectorTest.php index 6319f79..99e6fcd 100644 --- a/tests/FormConnectors/HubSpot/HubSpotConnectorTest.php +++ b/tests/FormConnectors/HubSpot/HubSpotConnectorTest.php @@ -215,7 +215,7 @@ public function it_excludes_the_email_property_from_the_summary() * @see https://github.com/statamic/forms-pro/issues/38 */ #[Test] - public function it_falls_back_to_the_property_name_when_a_field_has_no_label() + public function it_excludes_hidden_properties_from_the_summary() { $definition = $this->definition(); $definition['fieldGroups'][0]['fields'][] = [ @@ -229,10 +229,7 @@ public function it_falls_back_to_the_property_name_when_a_field_has_no_label() $properties = (new HubSpot)->forForm($this->form())->render()->toArray()['props']['hubspotForms'][self::FORM]['properties']; - $this->assertContains( - ['name' => 'lead_source', 'label' => 'lead_source', 'object_type_id' => '0-1', 'required' => false], - $properties, - ); + $this->assertNotContains('lead_source', array_column($properties, 'name')); } #[Test]