In some scenarios we would like to disable creating new blocks functionality on Content Areas. Then editors will add only existing items using drag and drop functionality. We could implement one of few solutions to meet this requirement. It can be EditorDescriptor with client widget or quick hack enclosed in 10 lines of backend code.
Content Area no create new link

By default Content Area editor displays “create a new block” link at the bottom.
standard content area

Content Area property use “epi-cms/contentediting/editors/ContentAreaEditor” widget as Edit Mode editor. The widget has isCreateLinkVisible method responsible managing for action link visibility.

The method is marked as protected, so it can be safety overridden.

Quick solution

It’s possible to replace isCreateLinkVisible method in backed code with just few lines of code. We need to create attribute that implements IMetadataAware interface. In OnMetadataCreated method we set “isCreateLinkVisible” key for EditorConfiguration dictionary. The value will be JavaScript function which simply return false value. By default value will be converted to string. To ensure that it will be serialized as function we will use JRaw class.

Now using the OnlyDnd attribute on property we will change the editor behavior.

This solution is a trick, because JSON object should contains only data and functions are not allowed.

Implementing new editor

If we don’t want to pass functions in JSON properties we could prepare new widget. It will extends ContentAreaEditor and override isCreateLinkVisible method.

ContentArea editor - file structure

In module.config we only register new path to the scripts.

Inside widget code we override “isCreateLinkVisible” method:

To use new widget we set ClientEditor attribute on Content Area property.

This version is more elegant. It’s a standard way of extending EPiServer functionality.

Implementing editor descriptor

If we have more than one ContentArea property with hidden action link, then we could prepare new Editor Descriptor. The Editor Descriptor will inherit from ContentAreaEditorDescriptor and set the widget class to “contentAreaWithDndOnly/contentAreaEditor”.

Then we could replace “contentAreaWithDndOnly.contentAreaEditor” constant used on property with Editor Descriptor UIHint.