Try our conversational search powered by Generative AI!

TinyMCE customization depending on page context

Vote:
 

Let's say that I have two page content types PageA and PageB. Both of them are having property defined like that:

[EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<OfferDetailsItem>))]
public override IList<OfferDetailsItem> OfferDetailsItems { get; set; }

with OfferDetailsItem defined like that:

public class OfferDetailsItem
{
   [Display(Order = 1)]
   public string Label { get; set; }

   [Display(Order = 2)]
   public XhtmlString Value { get; set; }

   [Display(Order = 3)]
   public bool Large { get; set; }
}

[PropertyDefinitionTypePlugIn]
public class OfferDetailsItemPropertyList : PropertyList<OfferDetailsItem>
{
}

I would like to customize TinyMCE editor for Value property of OfferDetailsItem class. I would like to do this depending on page context so there is different toolbar config when its used on PageA and different when its used on PageB.

I tried to use CustomEditorDescriptor for XhtmlString TargetType and override:

public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)

but in this case metadata.Parent is null so I can't reach content page context. For properties that are not collections this is possible.

Do you know if there is any other way to deal with this?

#261824
Edited, Sep 07, 2021 19:45
Vote:
 

Did you inherit from EPiServer.Cms.TinyMce.Core.XhtmlStringEditorDescriptor ?

Does 

var content = metadata.FindOwnerContent();

also returns null?

#262157
Sep 13, 2021 10:42
Michał Szkołut - Sep 13, 2021 11:30
I inherit from EditorDescriptor.
There is no method FindOwnerContent() available on metadata.
Bartosz Sekula - Sep 14, 2021 9:13
Yes there is. It's an extension method.
EPiServer.Cms.Shell.Extensions.ExtendedMetadataExtensions.FindOwnerContent
Michał Szkołut - Sep 14, 2021 12:03
Its still null.
Bartosz Sekula - Sep 14, 2021 12:40
Yes, you're right. Hypothetically, if there was a bugfix for that. Would you be willing to upgrade?
What's your current CMS version?
Michał Szkołut - Sep 14, 2021 12:52
Current version that w are using is 11.13.1.
Upgrading is always delicate process that we have to plan. If there will be only this bugfix there then it will be easier. But if we had to upgrade to version 12 or something with more braking changes and or dependencies to other packages then it may not be so fast.
Vote:
 

Hi Michał,

I have no answer direct to you question, but it is a recommendation try using ContentArea and block type instead of the generic PropertyList as your current implementation, see https://world.optimizely.com/documentation/developer-guides/CMS/Content/Properties/generic-propertylist/

Regards,

#262158
Sep 13, 2021 10:55
Michał Szkołut - Sep 13, 2021 19:29
Problem is that when I have ContentArea I don't know anything about page context. Firstly I create ContentArea items (no idea about the context), then I place them in that content area. I need to know context during item creation.
Vote:
 

OK, I managed to fix this.
Solution would be available in CMS UI 11.36.2
Stay tuned!

Available here: https://nuget.optimizely.com/package/?id=EPiServer.CMS.UI&v=12.0.2

#263162
Edited, Sep 15, 2021 11:10
Michał Szkołut - Oct 04, 2021 10:31
I updated to CMS UI 11.36.2 and still have the same issue: parent is null, FindOwnerContent returns null also.
Michał Szkołut - Oct 04, 2021 13:44
I used solution with CurrentContentContext and it works but partially. The problem now is that context does not refresh when I switch between two pages. I have to reload the episerver/cms page in the browser to get the content refreshed. Are you able to fix that also?
Bartosz Sekula - Oct 04, 2021 17:19
good point, I missed that
Michał Szkołut - Oct 06, 2021 8:42
Is there any chance to get it fixed? When should I expect it?
Bartosz Sekula - Oct 07, 2021 5:35
11.36.3 has just passed the QA. it will most likely be out early next week.
Bartosz Sekula - Oct 12, 2021 11:15
Michał, 11.36.3 is available now https://nuget.optimizely.com/package/?id=EPiServer.CMS.UI.Core&v=11.36.3
Please let me know if it helped
Michał Szkołut - Oct 13, 2021 11:32
Yes that worked as expected - thanks for your support!
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.