Skip to content

Handle existing RichTextEditorValue when parsing from markup or JSON structure #19266

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

Conversation

AndyButland
Copy link
Contributor

@AndyButland AndyButland commented May 7, 2025

Prerequisites

  • I have added steps to test this contribution in the description below

Fixes #19274

Description

We had this issue come in through Umbraco support where the customer was using a SendingContentNotification to hide certain properties from certain editors.

They found when doing this with a rich text editor, any existing value would get lost on save (replaced with "Umbraco.Cms.Core.RichTextEditorValue").

I found it was happening as the existing value is provided to the FromEditor method of the property value converter, but the parsing doesn't expect to get the actual object here and only handles a JSON structure or the raw markup. So I've just added an initial check to the parsing, to see if we have the object of the right type already, and if so, return it.

Testing

  • Set up a document with a rich text editor, add some text and save the document.
  • Apply a notification handler like the following:
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;

public class EditorSendingContentNotificationHandler : INotificationHandler<SendingContentNotification>
{
    public void Handle(SendingContentNotification notification)
    {
        var contentItemDisplay = notification.Content;
        var contentTypeAlias = "homePage";
        var propertyAlias = "bodyText";
        if (contentItemDisplay.ContentTypeAlias.InvariantEquals(contentTypeAlias))
        {
            foreach (var variant in contentItemDisplay.Variants)
            {
                foreach (var tab in variant.Tabs)
                {
                    tab.Properties = tab.Properties?.Where(x => !x.Alias.InvariantEquals(propertyAlias));
                }
            }
        }
    }
}

public class TestComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        builder.AddNotificationHandler<SendingContentNotification, EditorSendingContentNotificationHandler>();
    }
}

  • Verify the rich text field no longer displays.
  • Save the document.
  • Remove the notification handler and verify that the original value is still in place.

@Copilot Copilot AI review requested due to automatic review settings May 7, 2025 13:29
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses an issue where rich text editor values were being lost when properties were hidden, by returning the existing RichTextEditorValue if already provided instead of re-parsing.

  • Added a check to return the existing RichTextEditorValue instance
  • Updated XML documentation to reflect the newly supported value types

…torHelper.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

@nikolajlauridsen nikolajlauridsen left a comment

Choose a reason for hiding this comment

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

Looks good, tests good 👍

@nikolajlauridsen nikolajlauridsen merged commit 6a4aa04 into v13/dev May 8, 2025
6 checks passed
@nikolajlauridsen nikolajlauridsen deleted the v13/bugfix/ensure-rich-text-value-is-not-list-when-property-is-hidden branch May 8, 2025 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants