How to dynamically create Extended Attributes/SubTypes - Mura Digital Experience Platform
In Flow: The Mura Blog

How to dynamically create Extended Attributes/SubTypes

Over the last six months i've been working on numerous Mura CMS projects here at Blue River, and these projects often require me to work with extended attributes. While it's easy to create them manually, creating them programatically provides even more functionality and flexibility.

For those who are not familiar with extended attributes they allow common Mura nodes (pages, files, users, portals, etc.) to have additional fields assigned to them. This allows you to create highly structured content in Mura CMS.

Throughout the system these are referred to as subTypes (example: "Page / CustomType"). VERY nice to have whenever you might need to store more data than what Mura comes bundled with.

Now while working on a plugin project I was required to setup some extended attributes dynamically. So after I wrapped up the project I decided to push out some example code here for everyone to use.

How to build a new subType

<!--- create a new subType ---><cfset subType = application.classExtensionManager.getSubTypeBean() /><cfset subType.setType( "Portal" ) /><cfset subType.setSubType( "newPortalType" ) /><cfset subType.setBaseTable( "tcontent" ) /><cfset subType.setSiteID( "your siteId" ) /><!--- we load the subType in case it already exists ---><cfset subType.load() /><!--- save the subType ---><cfset />

how to assign attributes to your "default" subType's extend set

<!--- get the default extend set. this is automatically created for every subType ---><cfset extendSet = subType.getExtendSetByName( "Default" ) /><!--- create a new attribute for the "default" extend set ---><!--- Note that AutoApprove does not exist yet, but getAttributeBy Name will look for it and if not found give me a new bean to use ---><cfset attribute = extendSet.getAttributeByName( "AutoApprove" ) /><cfset attribute.setLabel( "Auto Approve Topics" ) /><cfset attribute.setType( "RadioGroup" ) /><cfset attribute.setOptionList( "Yes^No" ) /><cfset attribute.setOptionLabelList( "Yes^No" ) /><cfset attribute.setDefaultValue( "Yes" ) /><!--- save the attribute ---><cfset />

That's it! Having the ability to manipulate extended attributes can be quite powerful, so be careful and have fun!


Pat Santora
Team Blue River