This (ContentPublishedNotification changed to ContentPublishingNotification) is what I need, but it gives the error:
public void Handle(ContentPublishingNotification notification)
{
foreach (var node in notification.PublishedEntities)
{
if (node.HasProperty("hashValue"))
{
var hashValue = node.GetValue<string>("hashValue");
if (hashValue == null)
{
node.SetValue("hashValue", RandomString(6));
}
}
}
}
Full error is:
cannot be used as type parameter 'TNotificationHandler' in the generic type or method 'UmbracoBuilderExtensions.AddNotificationHandler<TNotification, TNotif
icationHandler>(IUmbracoBuilder)'. There is no implicit reference conversion from 'MrContentService.DontShout' to 'Umbraco.Cms.Core.Events.INotificationHand
ler<Umbraco.Cms.Core.Notifications.ContentPublishedNotification>'. [C:\Users\marti\OneDrive - Martin Rud\Dev2.0\wallscreen_umbracoHeadless\wal
lscreen_umbracoHeadless.csproj]
It seems the error is thrown where you add the notification handler.
Maybe you forgot to change from ContentPublishedNotification to ContentPublishingNotification?
So either:
public class DontShout : INotificationHandler<ContentPublishedNotification>
to
public class DontShout : INotificationHandler<ContentPublishingNotification>
or
builder.AddNotificationHandler<ContentPublishedNotification, DontShout>();
to
builder.AddNotificationHandler<ContentPublishingNotification, DontShout>();
Error using 'ContentPublishingNotification' ('cannot be used as type parameter...')
Hi forum,
I want a property value to be filled in and saved automatically if it's empty.
This works, but it triggers AFTER publish which is not what I need:
Full code can be seen here: https://goonlinetools.com/snapshot/code/#iejbo6av3cdcw77czwmimq
This (ContentPublishedNotification changed to ContentPublishingNotification) is what I need, but it gives the error:
Full error is:
Hi Martin.
It seems the error is thrown where you add the notification handler.
Maybe you forgot to change from ContentPublishedNotification to ContentPublishingNotification?
So either:
or
Cool, thanks. You were right; I haven't updated the Startup.cs correctly:
It was
But should be:
(have also changed "DontShout" to "AddHashValue"), but that's only for making more sense. :)
is working on a reply...