From 65d24097cb0ffff8384e2724d436eb13830c3655 Mon Sep 17 00:00:00 2001 From: Ian Leeder Date: Mon, 29 May 2023 13:03:35 +1000 Subject: [PATCH] Track content object on MetaTagsNotifications --- .../Notifications/AfterMetaTagsNotification.cs | 11 +++++++++++ .../Notifications/BeforeMetaTagsNotification.cs | 11 +++++++++++ .../Providers/DefaultMetaTagsProvider.cs | 4 ++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/SeoToolkit.Umbraco.MetaFields.Core/Notifications/AfterMetaTagsNotification.cs b/src/SeoToolkit.Umbraco.MetaFields.Core/Notifications/AfterMetaTagsNotification.cs index 601231e9..6961dfd2 100644 --- a/src/SeoToolkit.Umbraco.MetaFields.Core/Notifications/AfterMetaTagsNotification.cs +++ b/src/SeoToolkit.Umbraco.MetaFields.Core/Notifications/AfterMetaTagsNotification.cs @@ -1,4 +1,6 @@ using SeoToolkit.Umbraco.MetaFields.Core.Models.SeoService; +using System; +using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.Notifications; namespace SeoToolkit.Umbraco.MetaFields.Core.Notifications @@ -7,11 +9,20 @@ public class AfterMetaTagsNotification : INotification { public string ContentTypeAlias { get; } public MetaTagsModel MetaTags { get; } + public IPublishedContent Content { get; set; } + [Obsolete("This constructor is deprecated and will be removed in the next major release.")] public AfterMetaTagsNotification(string contentTypeAlias, MetaTagsModel metaTags) { ContentTypeAlias = contentTypeAlias; MetaTags = metaTags; } + + public AfterMetaTagsNotification(IPublishedContent content, MetaTagsModel metaTags) + { + Content = content; + ContentTypeAlias = content.ContentType.Alias; + MetaTags = metaTags; + } } } diff --git a/src/SeoToolkit.Umbraco.MetaFields.Core/Notifications/BeforeMetaTagsNotification.cs b/src/SeoToolkit.Umbraco.MetaFields.Core/Notifications/BeforeMetaTagsNotification.cs index 1e8fa138..bcacddc4 100644 --- a/src/SeoToolkit.Umbraco.MetaFields.Core/Notifications/BeforeMetaTagsNotification.cs +++ b/src/SeoToolkit.Umbraco.MetaFields.Core/Notifications/BeforeMetaTagsNotification.cs @@ -1,4 +1,6 @@ using SeoToolkit.Umbraco.MetaFields.Core.Models.SeoService; +using System; +using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.Notifications; namespace SeoToolkit.Umbraco.MetaFields.Core.Notifications @@ -7,11 +9,20 @@ public class BeforeMetaTagsNotification : INotification { public string ContentTypeAlias { get; } public MetaTagsModel MetaTags { get; } + public IPublishedContent Content { get; set; } + [Obsolete("This constructor is deprecated and will be removed in the next major release.")] public BeforeMetaTagsNotification(string contentTypeAlias, MetaTagsModel metaTags) { ContentTypeAlias = contentTypeAlias; MetaTags = metaTags; } + + public BeforeMetaTagsNotification(IPublishedContent content, MetaTagsModel metaTags) + { + Content = content; + ContentTypeAlias = content.ContentType.Alias; + MetaTags = metaTags; + } } } diff --git a/src/SeoToolkit.Umbraco.MetaFields.Core/Providers/DefaultMetaTagsProvider.cs b/src/SeoToolkit.Umbraco.MetaFields.Core/Providers/DefaultMetaTagsProvider.cs index 254e6d05..df4197f0 100644 --- a/src/SeoToolkit.Umbraco.MetaFields.Core/Providers/DefaultMetaTagsProvider.cs +++ b/src/SeoToolkit.Umbraco.MetaFields.Core/Providers/DefaultMetaTagsProvider.cs @@ -57,7 +57,7 @@ public MetaTagsModel Get(IPublishedContent content, bool includeUserValues) //Make sure that the fields are set, otherwise the values cannot be set! var metaTags = new MetaTagsModel(allFields.ToDictionary(it => it, it => (object)null)); - _eventAggregator.Publish(new BeforeMetaTagsNotification(content.ContentType.Alias, metaTags)); + _eventAggregator.Publish(new BeforeMetaTagsNotification(content, metaTags)); var settings = _documentTypeSettingsService.Get(content.ContentType.Id); if (settings is null) @@ -113,7 +113,7 @@ public MetaTagsModel Get(IPublishedContent content, bool includeUserValues) metaTags.SetValue(fieldValue.Field.Alias, fieldValue.Value); } - _eventAggregator.Publish(new AfterMetaTagsNotification(content.ContentType.Alias, metaTags)); + _eventAggregator.Publish(new AfterMetaTagsNotification(content, metaTags)); return metaTags; }