Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Antonio Messina 4 posts 74 karma points
    Dec 05, 2019 @ 11:34
    Antonio Messina
    0

    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.

    Any ideas? Is it a possible bug?

    Antonio

  • Aleksander 45 posts 205 karma points
    Apr 06, 2020 @ 07:03
    Aleksander
    0

    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..

  • Aleksander 45 posts 205 karma points
    Apr 06, 2020 @ 07:16
    Aleksander
    0

    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

  • Antonio Messina 4 posts 74 karma points
    May 11, 2020 @ 10:10
    Antonio Messina
    0

    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

  • Ahmed Mohamed 4 posts 84 karma points
    Mar 15, 2022 @ 09:02
    Ahmed Mohamed
    0

    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();

Please Sign in or register to post replies

Write your reply to:

Draft