Try our conversational search powered by Generative AI!

"Could not save property. The page may have been changed by another user. Please reload the page." When creating a CustomContentArea

Vote:
 

Hi all,

i am working on creating a custom content area which inherits from ContentArea

public class CustomExpandableContentArea : ContentArea

{


}

I also implemented my custom content area property to go with it

[Serializable]
[PropertyDefinitionTypePlugIn]
public class CustomPropertyContentArea : PropertyContentArea
{

    public override Type PropertyValueType => typeof(CustomExpandableContentArea);

}

I also implemented my EditDescriptor 

[EditorDescriptorRegistration(EditorDescriptorBehavior = EditorDescriptorBehavior.OverrideDefault, TargetType = typeof(CustomExpandableContentArea, , UIHint = "ContentAreaDescriptor"))]
public class CustomContentAreaEditorDescriptor : ContentAreaEditorDescriptor
{
}

and in my ContentType I implemented it as this

 [Display(Name = "Custom expandable content area", Order = 20)]
 [BackingType(typeof(CustomPropertyContentArea))]
 [UIHint("ContentAreaDescriptor")]
 public virtual CustomExpandableContentArea CustomContentArea { get; set; }

When I add any type of content inside of my custom content area it throws this error in a dialog:

Could not save property. The page may have been changed by another user. Please reload the page.

I have tried everything, any help is appreciated.

#317537
Feb 22, 2024 15:32
Vote:
 

My guess would be that you're getting a type casting error under the hood. Check your logs and browser console for errors. You would probably need to do quite a bit more work in your `PropertyDefinitionTypePlugIn` to handle conversion by overriding the `Value` prop (and potentially other properties/methods).

I am curious however why you would want a new custom ContentArea property, I can't think of many use cases to do so...

#317579
Feb 23, 2024 3:22
Taher.elhares - Feb 23, 2024 16:00
Check my reply below
Taher.elhares - Feb 23, 2024 16:00
Check my reply below
Vote:
 

Yeah, I am with Daniel on this one, not many use cases for a custom content area property, however looking at the name of the property you are trying to create, I think you are trying to create a different user experience and make the content area expandable.

If this is the case you don't need a new property you just need to override the editing experience.

The guys at Ted & Gustaf have an example that might be useful if you wish to just override the editing experience.

https://tedgustaf.com/blog/2016/create-a-custom-editor-for-a-content-area-in-episerver/

#317584
Edited, Feb 23, 2024 10:30
Vote:
 

I have a custom property converter provider that calls a custom content area property converter. what I am trying to do is check if the property value type is of a certain type then call my expand method when it is.

public class CustomPropertyConverterProvider : IPropertyConverterProvider
{
    public int SortOrder => 200;

    public IPropertyConverter Resolve(PropertyData propertyData)
    {
        if (propertyData is PropertyContentArea)
        {
            return new CustomContentAreaPropertyConverter();
        }

        return null;
    }
}
[ServiceConfiguration(typeof(IPropertyConverter), Lifecycle = ServiceInstanceScope.Singleton)]
public class CustomContentAreaPropertyConverter : IPropertyConverter
{
    public IPropertyModel Convert(PropertyData propertyData, ConverterContext converterContext)
    {
        if (propertyData is not PropertyContentArea propertyContentArea)
        {
            throw new InvalidOperationException();
        }

        var model = new ExpandedContentAreaPropertyModel(propertyContentArea, converterContext, ServiceLocator.Current.GetInstance<IContentExpander>());

        if (propertyData.PropertyValueType.Name == nameof(CustomExpandableContentArea))
        {
            model.Expand(converterContext.Language);
        }

        return model;
    }

}




#317609
Edited, Feb 23, 2024 16:18
Vote:
 

Hi Taher,

I just thought I would get back to you on this.

From what I can see you are trying to expand the content area when using the Content Delivery API, is this correct?

If so then you don't need to create a custom content area property, you just need to change how the Content Delivery API converters the content area to json when serializing, you can see this upon https://docs.developers.optimizely.com/content-management-system/v1.5.0-content-delivery-api/docs/customizing-conversion-from-icontent-to-contentapimodel#example-expand-multiple-levels-of-nested-contentarea-property.

A colleague of mine also has a good blog post of this type of customization https://world.optimizely.com/blogs/Minesh-Shah/Dates/2022/2/property-lists-serialization-and-content-delivery-api/, this is for a property list however all the code should be there to follow along and do the same for content areas.

#317742
Feb 26, 2024 9:52
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.