Copied to clipboard

Flag this post as spam?

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


  • Rihab 104 posts 388 karma points
    Aug 26, 2019 @ 11:00
    Rihab
    0

    Notification Message when delete content

    Hi,

    I'm trying to Show a Warning Message when deleting a content page from backoffice

    I tried this "it is working on Umbraco 7 but not on Umbraco 8.1.1"

      private void ContentService_Trashing(IContentService sender, MoveEventArgs<IContent> e)
        {
            ///inform the user if the post is favorate 
            try
            {
                foreach (var content in e.MoveInfoCollection
                   //Check if the content item type has a specific alias
                   .Where(c => c.Entity.ContentType.Alias.InvariantEquals(Helper.PostContentTypeAlias))
                   //Check if it is a new item
                   //.Where(c => c.HasIdentity == false)
                   )
                {
                    //check if the item has a property called 'richText'
                    if (DB_Oprs.DB_Oprs.IfFavoratePost(content.Entity.Id))
                    {
                        e.Messages.Add(new EventMessage("Warning", string.Format("Can not delete {0}", " This Post Is Favorate"), EventMessageType.Warning));
                    }
                }
            }
            catch (Exception ex)
            {
                Current.Logger.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, ex.Message, ex);
            }
        }
    

    I Appreciate Any Help.

  • Shaishav Karnani from digitallymedia.com 354 posts 1638 karma points
    Aug 26, 2019 @ 11:25
    Shaishav Karnani from digitallymedia.com
    0

    Hi

    Message will only appear when we cancel the event. It can be done using this command.

            e.Cancel = true;
    

    You can add it just after the e.Messages and as Node is not removed so message will appear.

    Please check and let me know your views.

  • Rihab 104 posts 388 karma points
    Aug 27, 2019 @ 06:30
    Rihab
    0

    Ok, That worked fine ... but I don't want to cancel the operation I just want to show a piece of information about the content.

    is that possible?

  • Shaishav Karnani from digitallymedia.com 354 posts 1638 karma points
    Aug 27, 2019 @ 07:09
    Shaishav Karnani from digitallymedia.com
    100

    No - I don't think that is possible because notification is delivered to the page and in this case page gets removed so they have no holding area to show message.

    Hope that helps.

  • Colin Anderson 16 posts 107 karma points
    Nov 16, 2020 @ 14:10
    Colin Anderson
    0

    What about the notification area where Umbraco shows a message to say the page has been deleted?

    If I wanted to show an additional message, how would I do this? (not preventing the deletion)

  • Markus Johansson 1945 posts 5898 karma points MVP 2x c-trib
    Nov 17, 2020 @ 21:34
    Markus Johansson
    0

    A hacky version that would work but would not be optimal is to create a JavaScript properly editor, put this on the document type and use the “onFormSubmitting”-event to trigger a notification in the notificationService.

    This would allow the item to be saved while the notification is shown. The drawback is that you would need a property on the document type only to show the notification.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies