Skip to content

Commit 2e36b13

Browse files
authored
Merge pull request #90 from umbraco/feature/v10/hubspot-append-values
Add feature to allow contact field value append.
2 parents 5e4e953 + e546ee4 commit 2e36b13

File tree

6 files changed

+55
-9
lines changed

6 files changed

+55
-9
lines changed

src/Umbraco.Forms.Integrations.Crm.Hubspot/App_Plugins/UmbracoForms.Integrations/Crm/Hubspot/hubspot-field-mapper-template.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
</div>
2121

2222
<div class="umb-forms-mappings mt2" ng-show="vm.mappings.length > 0 && vm.hubspotFields.length > 0">
23-
2423
<div class="umb-forms-mapping-header">
2524
<div class="umb-forms-mapping-field -no-margin-left">Form Field</div>
2625
<div class="umb-forms-mapping-field">Hubspot Field</div>
26+
<div ng-if="vm.allowContactUpdate" class="umb-forms-mapping-field text-center">Append when updating values</div>
2727
<div class="umb-forms-mapping-remove -no-margin-right"></div>
2828
</div>
2929

@@ -46,6 +46,14 @@
4646
</select>
4747
</div>
4848

49+
<div ng-if="vm.allowContactUpdate" class="umb-forms-mapping-field flex justify-center">
50+
<umb-checkbox name="chkAppend"
51+
value="mapping.appendValue"
52+
model="mapping.appendValue"
53+
on-change="vm.stringifyValue()">
54+
</umb-checkbox>
55+
</div>
56+
4957
<div class="umb-forms-mapping-remove -no-margin-right">
5058
<a href="" ng-click="vm.deleteMapping($index)"><i class="icon-trash"></i></a>
5159
</div>

src/Umbraco.Forms.Integrations.Crm.Hubspot/App_Plugins/UmbracoForms.Integrations/Crm/Hubspot/hubspotfields.component.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ function HubSpotFieldsController($scope, $routeParams, umbracoFormsIntegrationsC
5353

5454
vm.$onInit = function () {
5555

56+
vm.allowContactUpdate = Umbraco.Sys.ServerVariables.umbracoPlugins.umbracoFormsIntegrationsCrmHubspot.allowContactUpdate;
57+
5658
if (!vm.setting.value) {
5759
vm.mappings = [];
5860
} else {
59-
vm.mappings = JSON.parse(vm.setting.value);
61+
vm.mappings = parseMappings(vm.setting.value);
6062
}
6163

6264
umbracoFormsIntegrationsCrmHubspotResource.isAuthorizationConfigured().then(function (response) {
@@ -178,7 +180,8 @@ function HubSpotFieldsController($scope, $routeParams, umbracoFormsIntegrationsC
178180
// Add new empty object into the mappings array.
179181
vm.mappings.push({
180182
formField: "",
181-
hubspotField: ""
183+
hubspotField: "",
184+
appendValue: false
182185
});
183186
};
184187

@@ -190,4 +193,14 @@ function HubSpotFieldsController($scope, $routeParams, umbracoFormsIntegrationsC
190193
vm.stringifyValue = function () {
191194
vm.setting.value = JSON.stringify(vm.mappings);
192195
};
196+
197+
function parseMappings(settingValue) {
198+
var mappings = JSON.parse(settingValue);
199+
return mappings.map(mappingObj => {
200+
if (mappingObj.appendValue === undefined) {
201+
mappingObj.appendValue = false;
202+
}
203+
return mappingObj;
204+
});
205+
}
193206
}

src/Umbraco.Forms.Integrations.Crm.Hubspot/HubspotServerVariablesParsingHandler.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using Microsoft.AspNetCore.Http;
22
using Microsoft.AspNetCore.Routing;
3-
3+
using Microsoft.Extensions.Options;
44
using System;
55
using System.Collections.Generic;
6-
6+
using System.Runtime.Serialization;
77
using Umbraco.Cms.Core.Events;
88
using Umbraco.Cms.Core.Notifications;
99
using Umbraco.Extensions;
10+
using Umbraco.Forms.Integrations.Crm.Hubspot.Configuration;
1011
using Umbraco.Forms.Integrations.Crm.Hubspot.Controllers;
1112

1213
namespace Umbraco.Forms.Integrations.Crm.Hubspot
@@ -15,12 +16,15 @@ public class HubspotServerVariablesParsingHandler : INotificationHandler<ServerV
1516
{
1617
private readonly IHttpContextAccessor _httpContextAccessor;
1718
private readonly LinkGenerator _linkGenerator;
19+
private readonly HubspotSettings _settings;
1820

19-
public HubspotServerVariablesParsingHandler(IHttpContextAccessor httpContextAccessor, LinkGenerator linkGenerator)
21+
public HubspotServerVariablesParsingHandler(IHttpContextAccessor httpContextAccessor, LinkGenerator linkGenerator, IOptions<HubspotSettings> options)
2022
{
2123
_httpContextAccessor = httpContextAccessor;
2224

23-
_linkGenerator = linkGenerator;
25+
_linkGenerator = linkGenerator;
26+
27+
_settings = options.Value;
2428
}
2529

2630
public void Handle(ServerVariablesParsingNotification notification)
@@ -51,6 +55,22 @@ public void Handle(ServerVariablesParsingNotification notification)
5155
umbracoUrls["umbracoFormsIntegrationsCrmHubspotBaseUrl"] =
5256
_linkGenerator.GetUmbracoApiServiceBaseUrl<HubspotController>(controller => controller.GetAllProperties());
5357

58+
if (serverVars.ContainsKey("umbracoPlugins"))
59+
{
60+
var umbracoPlugins = (Dictionary<string, object>)serverVars["umbracoPlugins"];
61+
umbracoPlugins.Add("umbracoFormsIntegrationsCrmHubspot", new ClientSideConfiguration
62+
{
63+
AllowContactUpdate = _settings.AllowContactUpdate
64+
});
65+
}
66+
67+
}
68+
69+
[DataContract]
70+
internal sealed class ClientSideConfiguration
71+
{
72+
[DataMember(Name = "allowContactUpdate")]
73+
public bool AllowContactUpdate { get; set; }
5474
}
5575
}
5676
}

src/Umbraco.Forms.Integrations.Crm.Hubspot/Models/MappedProperty.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ public class MappedProperty
99

1010
[JsonProperty(PropertyName = "hubspotField")]
1111
public string HubspotField { get; set; }
12+
13+
[JsonProperty(PropertyName = "appendValue")]
14+
public bool AppendValue { get; set; }
1215
}
1316
}

src/Umbraco.Forms.Integrations.Crm.Hubspot/Services/HubspotContactService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ public async Task<CommandResult> PostContactAsync(Record record, List<MappedProp
160160
var recordField = record.GetRecordField(Guid.Parse(fieldId));
161161
if (recordField != null)
162162
{
163-
var value = recordField.ValuesAsHubspotString(false);
163+
var value = _settings.AllowContactUpdate && mapping.AppendValue
164+
? ";" + recordField.ValuesAsHubspotString(false)
165+
: recordField.ValuesAsHubspotString(false);
164166

165167
propertiesRequestV1.Properties.Add(new PropertiesRequestV1.PropertyValue(mapping.HubspotField, value));
166168
propertiesRequestV3.Properties.Add(mapping.HubspotField, value);

src/Umbraco.Forms.Integrations.Crm.Hubspot/Umbraco.Forms.Integrations.Crm.Hubspot.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageIconUrl></PackageIconUrl>
1212
<PackageProjectUrl>https://github.com/umbraco/Umbraco.Forms.Integrations/tree/main-v10/src/Umbraco.Forms.Integrations.Crm.Hubspot</PackageProjectUrl>
1313
<RepositoryUrl>https://github.com/umbraco/Umbraco.Forms.Integrations</RepositoryUrl>
14-
<Version>3.2.1</Version>
14+
<Version>3.3.0</Version>
1515
<Authors>Umbraco HQ</Authors>
1616
<Company>Umbraco</Company>
1717
<PackageTags>Umbraco;Umbraco-Marketplace</PackageTags>

0 commit comments

Comments
 (0)