Content Service Events - Cancel Operation method doesn't show bubble message in backoffice new node creation
Hi all,
this is my first post on Umbraco Community.
I'm migrating the site code from v7 to v8 and I have a problem on method CancelOperation that should throw a bubble message on a new node save event (in the v7 code it works perfectly), in backoffice.
That I notice is the code below works well when I save an existing node but it fails (simply the message is not showed) when i try to create a new node.
public class ValidateTagsComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.Components().Append<ValidateTagsComponent>();
}
}
public class ValidateTagsComponent : IComponent
{
// initialize: runs once when Umbraco starts
public void Initialize()
{
ContentService.Saving += ContentService_Saving;
}
// terminate: runs once when Umbraco stops
public void Terminate()
{ }
private void ContentService_Saving(IContentService sender, ContentSavingEventArgs eventArgs)
{
foreach (var node in eventArgs.SavedEntities)
{
if (node.HasProperty("govitCategory") && node.GetValue("govitCategory") != null)
{
if (node.GetValue("govitCategory").ToString().Split(',').Length > 1)
{
// Explain why the publish event is cancelled
eventArgs.CancelOperation(new EventMessage("Categoria", "E' consentita una sola categoria.", messageType: EventMessageType.Error));
}
}
}
}
}
I already tried to use the other form suggested here in the forum, first setting eventArgs.Cancel = true; and then using the Add method eventArgs.Messages.Add(new EventMessage("Categoria", "E' consentita una sola categoria.", EventMessageType.Error));, but unfortunately it doesn't work: it is displayed only the following message:
'' could not be published, a 3rd party add-in cancelled the action.
Did you find a solution for this ? it's super weird. I had a website where this was working fine. Then suddenly it stopped working... Event gets cancelled, but the message is not shown...
Not event the "Cancelled by third party" is shown any longer... I recently updated to 8.6, but it worked for a while on 8.6..
Hi Alex,
I apologize for the delay. Yes, we still have the problem, I saw you open an issue about this point on GitHub and there's a proposed solution waiting for the merge.
https://github.com/umbraco/Umbraco-CMS/issues/7902
you can search for file umbraco.directives.js
and set in line 3086
to make sure message appear
formHelper.showNotifications(err.data);
clearNotifications($scope.content);
overlayService.close();
Content Service Events - Cancel Operation method doesn't show bubble message in backoffice new node creation
Hi all,
this is my first post on Umbraco Community. I'm migrating the site code from v7 to v8 and I have a problem on method
CancelOperation
that should throw a bubble message on a new node save event (in the v7 code it works perfectly), in backoffice. That I notice is the code below works well when I save an existing node but it fails (simply the message is not showed) when i try to create a new node.I already tried to use the other form suggested here in the forum, first setting
eventArgs.Cancel = true;
and then using the Add methodeventArgs.Messages.Add(new EventMessage("Categoria", "E' consentita una sola categoria.", EventMessageType.Error));
, but unfortunately it doesn't work: it is displayed only the following message:Any ideas? Is it a possible bug?
Antonio
Did you find a solution for this ? it's super weird. I had a website where this was working fine. Then suddenly it stopped working... Event gets cancelled, but the message is not shown...
Not event the "Cancelled by third party" is shown any longer... I recently updated to 8.6, but it worked for a while on 8.6..
Update: For me it seems like the only time the error messages isn't showing is if you are publishing a newly created node which varies by culture
Hi Alex, I apologize for the delay. Yes, we still have the problem, I saw you open an issue about this point on GitHub and there's a proposed solution waiting for the merge. https://github.com/umbraco/Umbraco-CMS/issues/7902
Thank you for your contribution!
Antonio
you can search for file umbraco.directives.js
and set in line 3086 to make sure message appear formHelper.showNotifications(err.data); clearNotifications($scope.content); overlayService.close();
is working on a reply...