Tags:

Update GroupName for built-in block types in Optimizely CMS

If you are using Optimizely Forms, you have the «Form Container» (named FormContainerBlock in code) as one of your available block types, when editors create new blocks.

Block, with Form container in its default group: Forms

What if you want to change the name of the Group from «Forms» to something else? What if you want to move the Form container to a different group?

Renaming Forms group

If you want to rename the Forms group created by Optimzely Forms, you may do so following this procedure using XML language files.

<?xml version="1.0" encoding="utf-8" ?>
<languages>
    <language name="English" id="en">  
        <groups>
            <formscontainerelements>Blocks not in use</formscontainerelements>
        </groups>
    </language>
</languages>

The groups after adding the above XML file.

Block, with Form container in its default group renamed to: Blocks not in use

Adding Form container to different group

Using an Initialization Module like this, we may update the GroupName property of the FormContainerBlock to match the group of any other block.

[InitializableModule]
public class ContentTypeInitialization : IInitializableModule
{
    public void Initialize(InitializationEngine context)
    {
            var contentTypeRepo = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
            var formContainer = contentTypeRepo.Load(nameof(FormContainerBlock));
            var writeabeformContainer= formContainer.CreateWritableClone() as ContentType;
            writeabeformContainer.GroupName = "My Blocks";
            contentTypeRepo.Save(writeabeformContainer);
    }
}

The groups after addeding the above XML file.

Block, with Form container moved to user defined group: My Blocks

If you are using CMS 11 and Optimizely Search & Navigation (previously Optimizely Find) you may use the same concept for the block «Customized search» (called CustomizedSearchBlock in code). The only difference is that it has no existing group, but you may use an Initialization module, to move it to a group.

 

That's all!