Skip to content

Commit 759d7d3

Browse files
committed
Fix rendering component for Umbraco 9; pass region parameter to rendering component using the view model.
1 parent b6047c2 commit 759d7d3

File tree

9 files changed

+41
-32
lines changed

9 files changed

+41
-32
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,14 @@
1-
@using System.Configuration
2-
@inherits Umbraco.Web.Mvc.UmbracoViewPage<Umbraco.Cms.Integrations.Crm.Hubspot.Models.ViewModels.HubspotFormViewModel>
1+
@inherits Umbraco.Web.Mvc.UmbracoViewPage<Umbraco.Cms.Integrations.Crm.Hubspot.Models.ViewModels.HubspotFormViewModel>
32

43
@{
5-
var region = ConfigurationManager.AppSettings["Umbraco.Cms.Integrations.Crm.Hubspot.Region"];
6-
7-
var hbsptScriptPath = string.IsNullOrEmpty(region) ? "//js.hsforms.net/forms/shell.js" : "//js-eu1.hsforms.net/forms/shell.js";
4+
var hbsptScriptPath = string.IsNullOrEmpty(Model.Region) ? "//js.hsforms.net/forms/shell.js" : "//js-eu1.hsforms.net/forms/shell.js";
85
}
96

107
<script charset="utf-8" type="text/javascript" src="@hbsptScriptPath"></script>
11-
@if (string.IsNullOrEmpty(region))
12-
{
13-
<script>
14-
hbspt.forms.create({
15-
portalId: "@Model.PortalId",
16-
formId: "@Model.Id"
17-
});
18-
</script>
19-
20-
}
21-
else
22-
{
23-
<script>
24-
hbspt.forms.create({
25-
region: "@region",
26-
portalId: "@Model.PortalId",
27-
formId: "@Model.Id"
28-
});
29-
</script>
30-
31-
}
8+
<script>
9+
hbspt.forms.create({
10+
region: "@Model.Region",
11+
portalId: "@Model.PortalId",
12+
formId: "@Model.Id"
13+
});
14+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Integrations.Crm.Hubspot.Models.ViewModels.HubspotFormViewModel>
2+
3+
@{
4+
var hbsptScriptPath = string.IsNullOrEmpty(Model.Region) ? "//js.hsforms.net/forms/shell.js" : "//js-eu1.hsforms.net/forms/shell.js";
5+
}
6+
7+
<script charset="utf-8" type="text/javascript" src="@hbsptScriptPath"></script>
8+
<script>
9+
hbspt.forms.create({
10+
region: "@Model.Region",
11+
portalId: "@Model.PortalId",
12+
formId: "@Model.Id"
13+
});
14+
</script>

src/Umbraco.Cms.Integrations.Crm.Hubspot/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/views/formpickereditor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</div>
1313
<div class="hsOverlayGroup">
1414
<ul class="hsFormsList">
15-
<li ng-repeat="form in vm.hubspotFormsList | orderBy:'name' | filter:vm.searchTerm" ng-click="model.pickForm(form, vm.euRegion)" class="ng-scope" role="button" tabindex="0">
15+
<li ng-repeat="form in vm.hubspotFormsList | orderBy:'name' | filter:vm.searchTerm" ng-click="model.pickForm(form)" class="ng-scope" role="button" tabindex="0">
1616
<a href="" ng-attr-title="form.name">
1717
<i class="icon-umb-contour"></i>
1818
<span class="formLine">{{form.name}}</span>

src/Umbraco.Cms.Integrations.Crm.Hubspot/Controllers/FormsController.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ public async Task<ResponseDto> GetAll()
126126
Name = hubspotForm.Name,
127127
PortalId = hubspotForm.PortalId.ToString(),
128128
Id = hubspotForm.Guid,
129+
Region = Options.Region,
129130
Fields = string.Join(", ", hubspotForm.FormFieldGroups.SelectMany(x => x.Fields).Select(y => y.Label))
130131
};
132+
131133
responseDto.Forms.Add(hubspotFormDto);
132134
}
133135

@@ -190,6 +192,7 @@ public async Task<ResponseDto> GetAllOAuth()
190192
Name = hubspotForm.Name,
191193
PortalId = hubspotForm.PortalId.ToString(),
192194
Id = hubspotForm.Guid,
195+
Region = Options.Region,
193196
Fields = string.Join(", ", hubspotForm.FormFieldGroups.SelectMany(x => x.Fields).Select(y => y.Label))
194197
};
195198
responseDto.Forms.Add(hubspotFormDto);

src/Umbraco.Cms.Integrations.Crm.Hubspot/Editors/FormPickerValueConverter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPub
3232
var jObject = JObject.Parse(source.ToString());
3333
var jformId = jObject["id"];
3434
var jportalId = jObject["portalId"];
35+
var jRegion = jObject["region"];
3536

3637
if (jformId != null && jportalId != null)
3738
{
3839
var hubspotFormViewModel = new HubspotFormViewModel
3940
{
4041
Id = jformId.Value<string>(),
41-
PortalId = jportalId.Value<string>()
42+
PortalId = jportalId.Value<string>(),
43+
Region = jRegion.Value<string>()
4244
};
4345
return hubspotFormViewModel;
4446
}

src/Umbraco.Cms.Integrations.Crm.Hubspot/Helpers/HtmlHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ namespace Umbraco.Cms.Integrations.Crm.Hubspot.Helpers
1616
public static class HubspotHtmlExtensions
1717
{
1818
#if NETCOREAPP
19-
public static IHtmlContent RenderHubspotForm(this HtmlHelper htmlHelper, HubspotFormViewModel hubspotFormViewModel)
19+
public static IHtmlContent RenderHubspotForm(this IHtmlHelper<dynamic> htmlHelper, HubspotFormViewModel hubspotFormViewModel)
2020
{
21-
return htmlHelper.Partial("~/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/Render/HubspotForm.cshtml", hubspotFormViewModel ?? new HubspotFormViewModel());
21+
return htmlHelper.Partial("~/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/Render/HubspotFormV9.cshtml", hubspotFormViewModel ?? new HubspotFormViewModel());
2222
}
2323
#else
2424
public static IHtmlString RenderHubspotForm(this HtmlHelper htmlHelper, HubspotFormViewModel hubspotFormViewModel)

src/Umbraco.Cms.Integrations.Crm.Hubspot/Models/Dtos/HubspotFormDto.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class HubspotFormDto
1616
[JsonProperty("fields")]
1717
public string Fields { get; set; }
1818

19-
[JsonProperty("euRegion")]
20-
public bool EuRegion { get; set; }
19+
[JsonProperty("region")]
20+
public string Region { get; set; }
2121
}
2222
}

src/Umbraco.Cms.Integrations.Crm.Hubspot/Models/ViewModels/HubspotFormViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ public class HubspotFormViewModel
55
public string PortalId { get; set; }
66

77
public string Id { get; set; }
8+
9+
public string Region { get; set; }
810
}
911
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<ItemGroup Condition="'$(TargetFramework)' == 'net50'">
2323
<PackageReference Include="Umbraco.Cms.Web.Website" version="9.0.1" />
2424
<PackageReference Include="Umbraco.Cms.Web.BackOffice" version="9.0.1" />
25+
<PackageReference Include="Umbraco.Cms.Web.Common" version="9.0.1" />
2526
</ItemGroup>
2627

2728
<ItemGroup>
@@ -42,6 +43,10 @@
4243
</Content>
4344
</ItemGroup>
4445

46+
<ItemGroup>
47+
<None Remove="App_Plugins\UmbracoCms.Integrations\Crm\Hubspot\Render\HubspotFormV9.cshtml" />
48+
</ItemGroup>
49+
4550
<Target Name="RemoveLuceneAnalyzer" BeforeTargets="CoreCompile">
4651
<ItemGroup>
4752
<Analyzer Remove="@(Analyzer)" Condition="%(FileName) == 'Lucene.Net.CodeAnalysis.CSharp'" />

0 commit comments

Comments
 (0)