Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add content to MetaTagsNotification objects #194

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; }
Copy link
Contributor Author

@ianleeder ianleeder Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@patrickdemooij9
I just saw that I allowed set on the automatic property. This should probably be updated to get only, like the other properties. Just habit (and auto-complete).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #199 to fix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I don't use GitHub PRs very often. I couldn't see a way to amend or reopen this one once it was merged. Let me know if there was an easier way to do this. A second PR feels like overkill)


[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 (settings is null)
Expand Down Expand Up @@ -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;
}
Expand Down