Skip to content

Commit

Permalink
Track content object on MetaTagsNotifications (#194)
Browse files Browse the repository at this point in the history
Co-authored-by: Ian Leeder <ileeder@intuitiveit.com.au>
  • Loading branch information
2 people authored and patrickdemooij9 committed Jun 1, 2023
1 parent da0c5e1 commit 6b3d856
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 (_seoSettingsService.IsEnabled(content.ContentType.Id) != true)
Expand Down Expand Up @@ -111,7 +111,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;
}
Expand Down

0 comments on commit 6b3d856

Please sign in to comment.