Skip to content

Commit d39d09d

Browse files
GH-149 :: Update Finished branch to 30.11.1 (#150)
* GH-149 :: Update to 30.11.1 * GH-125 :: fix broken widgets after content retrieval update
1 parent 98cfcaf commit d39d09d

File tree

7 files changed

+73
-17
lines changed

7 files changed

+73
-17
lines changed

.config/dotnet-tools.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"kentico.xperience.dbmanager": {
6+
"version": "30.11.1",
7+
"commands": [
8+
"kentico-xperience-dbmanager"
9+
],
10+
"rollForward": false
11+
}
12+
}
13+
}

src/Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageVersion Include="kentico.xperience.webapp" Version="30.11.1" />
1616
<PackageVersion Include="Kentico.Xperience.Core" Version="30.11.1" />
1717
<PackageVersion Include="kentico.xperience.mjml" Version="30.11.1" />
18-
18+
1919
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="8.0.14" />
2020
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
2121
<PackageVersion Include="Moq" Version="4.20.70" />

src/TrainingGuides.Web/Features/LandingPages/Widgets/HeroBanner/HeroBannerWidgetViewComponent.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Kentico.PageBuilder.Web.Mvc;
1+
using CMS.DataEngine;
2+
using Kentico.PageBuilder.Web.Mvc;
23
using Microsoft.AspNetCore.Html;
34
using Microsoft.AspNetCore.Mvc;
45
using Microsoft.AspNetCore.Mvc.ViewComponents;
@@ -22,15 +23,18 @@ public class HeroBannerWidgetViewComponent : ViewComponent
2223
{
2324
private readonly IContentItemRetrieverService contentItemRetrieverService;
2425
private readonly IEnumStringService enumStringService;
26+
private readonly IContentTypeService contentTypeService;
2527

2628
public const string IDENTIFIER = "TrainingGuides.HeroBanner";
2729

2830
public HeroBannerWidgetViewComponent(
2931
IContentItemRetrieverService contentItemRetrieverService,
30-
IEnumStringService enumStringService)
32+
IEnumStringService enumStringService,
33+
IContentTypeService contentTypeService)
3134
{
3235
this.contentItemRetrieverService = contentItemRetrieverService;
3336
this.enumStringService = enumStringService;
37+
this.contentTypeService = contentTypeService;
3438
}
3539

3640
public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetProperties properties)
@@ -41,11 +45,13 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
4145
{
4246
var productPage = await contentItemRetrieverService.RetrieveCurrentPage<ProductPage>(3);
4347

44-
if (productPage != null)
48+
int? productClassId = contentTypeService.GetContentTypeId(ProductPage.CONTENT_TYPE_NAME);
49+
50+
if (productPage is not null && productPage.SystemFields.ContentItemContentTypeID == productClassId)
4551
{
4652
banner = GetProductPageBanner(productPage);
4753

48-
if (banner != null)
54+
if (banner is not null)
4955
{
5056
banner.CTALink = properties.ProductPageAnchor;
5157
banner.CTAText = properties.CTA;
@@ -55,7 +61,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
5561
}
5662
else if (string.Equals(properties.Mode, "productPage"))
5763
{
58-
if (properties.ProductPage.FirstOrDefault() != null)
64+
if (properties.ProductPage.FirstOrDefault() is not null)
5965
{
6066
var productPageGuid = properties.ProductPage?.Select(i => i.Identifier).FirstOrDefault();
6167
var productPage = productPageGuid.HasValue
@@ -64,7 +70,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
6470
: null;
6571

6672
banner = GetProductPageBanner(productPage);
67-
if (banner != null)
73+
if (banner is not null)
6874
{
6975
string relativeUrl = productPage?.SystemFields.WebPageUrlPath is not null
7076
? $"~/{productPage.SystemFields.WebPageUrlPath}"
@@ -78,7 +84,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
7884
}
7985
else
8086
{
81-
if (properties.Hero != null && properties.Hero.Any())
87+
if (properties.Hero is not null && properties.Hero.Any())
8288
{
8389
var heroGuid = properties?.Hero?.Select(i => i.Identifier).ToList().FirstOrDefault();
8490

@@ -89,7 +95,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
8995

9096
banner = GetModel(hero, properties);
9197

92-
if (banner?.Link != null)
98+
if (banner?.Link is not null)
9399
{
94100
banner.CTALink = !string.IsNullOrEmpty(banner.Link.LinkUrl) ? banner!.Link.LinkUrl : banner.Link.LinkToExternal ?? string.Empty;
95101
banner.CTAText = !string.IsNullOrEmpty(properties?.CTA) ? properties.CTA : banner.Link.CallToAction;
@@ -98,7 +104,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
98104
}
99105
}
100106

101-
if (banner != null)
107+
if (banner is not null)
102108
{
103109

104110
banner.DisplayCTA = !string.IsNullOrEmpty(banner.CTALink) && !string.IsNullOrEmpty(banner.CTAText) && properties!.DisplayCTA;
@@ -135,13 +141,13 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
135141
}
136142

137143
private HeroBannerWidgetViewModel? GetProductPageBanner(ProductPage? productPage) =>
138-
productPage == null ? null : GetHeroBannerViewModel(productPage);
144+
productPage is null ? null : GetHeroBannerViewModel(productPage);
139145

140146
private static HeroBannerWidgetViewModel? GetHeroBannerViewModel(ProductPage productPage)
141147
{
142148
var product = productPage.ProductPageProduct.FirstOrDefault();
143149

144-
if (product != null)
150+
if (product is not null)
145151
{
146152
var benefits = product.ProductBenefits.ToList();
147153
var media = product.ProductMedia.FirstOrDefault();
@@ -151,7 +157,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
151157
Header = product.ProductName,
152158
SubheaderHtml = new HtmlString(product.ProductShortDescription),
153159
Benefits = benefits.Select(BenefitViewModel.GetViewModel).ToList(),
154-
Media = media != null
160+
Media = media is not null
155161
? AssetViewModel.GetViewModel(media)
156162
: new AssetViewModel()
157163
};
@@ -162,7 +168,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
162168

163169
private HeroBannerWidgetViewModel? GetModel(Hero? hero, HeroBannerWidgetProperties? properties)
164170
{
165-
if (hero == null || properties == null)
171+
if (hero is null || properties is null)
166172
{
167173
return null;
168174
}
@@ -181,7 +187,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(HeroBannerWidgetPropertie
181187
LinkUrl = url?.RelativePath ?? string.Empty,
182188
CallToAction = hero.HeroCallToAction
183189
},
184-
Media = media != null
190+
Media = media is not null
185191
? AssetViewModel.GetViewModel(media)
186192
: new AssetViewModel()
187193
};

src/TrainingGuides.Web/Features/Products/Widgets/Product/ProductWidgetViewComponent.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using CMS.DataEngine;
12
using CMS.Helpers;
23
using Kentico.PageBuilder.Web.Mvc;
34
using Microsoft.AspNetCore.Mvc;
@@ -31,15 +32,18 @@ public class ProductWidgetViewComponent : ViewComponent
3132
private readonly IContentItemRetrieverService contentItemRetrieverService;
3233
private readonly IComponentStyleEnumService componentStyleEnumService;
3334
private readonly IProductPageService productPageService;
35+
private readonly IContentTypeService contentTypeService;
3436

3537
public ProductWidgetViewComponent(
3638
IContentItemRetrieverService contentItemRetrieverService,
3739
IComponentStyleEnumService componentStyleEnumService,
38-
IProductPageService productPageService)
40+
IProductPageService productPageService,
41+
IContentTypeService contentTypeService)
3942
{
4043
this.contentItemRetrieverService = contentItemRetrieverService;
4144
this.componentStyleEnumService = componentStyleEnumService;
4245
this.productPageService = productPageService;
46+
this.contentTypeService = contentTypeService;
4347
}
4448

4549
public async Task<ViewViewComponentResult> InvokeAsync(ProductWidgetProperties properties)
@@ -94,8 +98,13 @@ private async Task<ProductWidgetViewModel> GetProductWidgetViewModel(ProductWidg
9498
: null;
9599
}
96100

97-
return productPage;
101+
int? productContentTypeId = contentTypeService.GetContentTypeId(ProductPage.CONTENT_TYPE_NAME);
102+
103+
return productPage?.SystemFields.ContentItemContentTypeID == productContentTypeId
104+
? productPage
105+
: null;
98106
}
107+
99108
private async Task<ProductPageViewModel?> GetProductPageViewModel(ProductWidgetProperties properties)
100109
{
101110
var productPage = await GetProductPage(properties);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using CMS.DataEngine;
2+
3+
namespace TrainingGuides.Web.Features.Shared.Services;
4+
5+
public class ContentTypeService : IContentTypeService
6+
{
7+
/// <summary>
8+
/// Gets the content type ID for a given content type name.
9+
/// </summary>
10+
/// <param name="contentTypeName"></param>
11+
/// <returns>Content type ID of provided content type, null if not found</returns>
12+
public int? GetContentTypeId(string contentTypeName) =>
13+
DataClassInfoProvider
14+
.GetDataClassInfo(contentTypeName)?
15+
.ClassID;
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace TrainingGuides.Web.Features.Shared.Services;
2+
3+
public interface IContentTypeService
4+
{
5+
/// <summary>
6+
/// Gets the content type ID for a given content type name.
7+
/// </summary>
8+
/// <param name="contentTypeName"></param>
9+
/// <returns>Content type ID of provided content type, null if not found</returns>
10+
int? GetContentTypeId(string contentTypeName);
11+
}

src/TrainingGuides.Web/ServiceCollectionExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static class ServiceCollectionExtensions
2222
{
2323
public static void AddTrainingGuidesServices(this IServiceCollection services)
2424
{
25+
services.AddSingleton<IContentTypeService, ContentTypeService>();
2526
services.AddSingleton<IStringEncryptionService, AesEncryptionService>();
2627
services.AddSingleton<IFormCollectionService, FormCollectionService>();
2728
services.AddSingleton<ICookieConsentService, CookieConsentService>();

0 commit comments

Comments
 (0)