Copied to clipboard

Flag this post as spam?

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


  • Volodymyr Kuybida 1 post 21 karma points
    Jun 13, 2024 @ 14:13
    Volodymyr Kuybida
    0

    Change field's PropertyEditor in SendingContentNotification handler

    I have GenericPage content type, it has Title property (TextBox).

    In SendingContentNotification, I'd like to change it to TextArea data type (based on parent document type).

    Is it possible to change property PropertyEditor value in the SendingContentNotification?

    I have tried to change it via PropertyEditorAlias but it does not work...

    public void Handle(SendingContentNotification notification) { foreach (var property in notification.Content.Properties) { if (property.Alias == "title") { _logger.LogInformation($"Changing property editor for {property.Alias} to TextArea"); property.PropertyEditorAlias = "Umbraco.TextArea"; } } }

  • Marcio Goularte 388 posts 1360 karma points
    Jun 13, 2024 @ 14:45
    Marcio Goularte
    0

    I have never tried to do this, I believe it is possible but it could cause errors when saving. You're probably not getting it because of the variations.

    I don't know if it will work, but following the documentation it would be this:

    public void Handle(SendingContentNotification notification)
    {
        foreach (var variant in notification.Content.Variants)
        {
            //ContentSavedStateaccording to your needs
            if (variant.State == ContentSavedState.NotCreated)
            {
                foreach (var property in variant.Tabs.SelectMany(f => f.Properties))
                {
                    if (property.Alias == "title")
                    {
                        _logger.LogInformation($"Changing property editor for {property.Alias} to TextArea");
                        property.PropertyEditorAlias = "Umbraco.TextArea";
                    }
                }                    
            }
        }
    }
    

    https://docs.umbraco.com/umbraco-cms/reference/notifications/editormodel-notifications

    Wouldn't it be possible for the field to already be a TextArea?

Please Sign in or register to post replies

Write your reply to:

Draft