The Class Extension Manager

The Class Extension Manager allows you to create subTypes which extend the base types of content (users, pages, portals, etc.) found in Mura. This allows you to create highly structured data by adding new fields/attributes to existing Mura CMS data types. 

Here are a few examples of situations when creating a new subType in Mura CMS would be useful:

  • Products with specific attributes (cost, weight, version number, etc.)
  • Site Members with specific attributes (gender, age, eye color, favorite ice cream flavor, etc.)
  • Events with specific attributes (date, location, topic, time, etc.)

The Class Extension Manager is one of the more complex parts of Mura CMS, and it's important to understand how each aspect of the Class Extension Manager relates to the others. It's also important to mention that your naming convention needs to be strict - you must treat each named attribute as a variable, with no spaces and no special characters.

  • Types: As mentioned above, types are the default data types in Mura CMS such as users, pages and portals. Each data type serves a unique purpose in Mura, both on a data and a rendering level.
  • SubTypes: SubTypes allow you extend a base Mura type. You can have as many subTypes as you'd like, each defining the associated type further. For example, you could create a "Resume" subType. This would be a Mura page but with a "Resume" subType, with the attributes we've assigned to that subType. Remember, keep your naming convention strict (like a variable).

    It's important to note that if you build a subType labeled "Default" this will cause EVERY instance of that Type (user, page, etc.) to automatically have its associated attributes added to it. It's a way of giving you the ability to add global fields to use in Mura CMS.
  • Attribute Sets are groups of attributes that associate to a given subType. Each group can be uniquely named to help define its purpose. For instance, you could have a "Resume" subType. Most resumes contain a section for listing out skills a user possesses. So we'll add an Attribute Set labeled "Skills" to store special attributes for skill-related information.

    It's also important to note that when you create a new subType Mura automatically creates a data set for that subType labeled "Default". This is not a required data set in this case. It's simply a data set you can just start using.

For this example, we'll extend the base Page type by adding a new subType with new attributes. Our example will include the creation of a "Resume" subType. 

Access your site's Class Extension Manager:

  1. Log into your Mura Admin screens, and select the site you want to work with
  2. From the Site Settings menu in the upper right of the yellow bar in your Mura CMS admin screens, click Edit Current Site
  3. On the Site Settings page, click the link to Class Extension Manager (directly under the title)

Click Add Class Extension - this will give you the ability to create a new subType.

Select "Page" from the base type options - we're going to call our example subType "Resume". Click the "Add" button.

Now you'll see the Class Extension Attribute Sets page. You'll see a few options: 

  • List All Class Extensions: This will take you back to the list of subTypes.
  • Edit Class Extension: This will let you change the subType name. Here you will also be able to delete the subType itself.
  • Add/Edid Attribute Set: This will let you add/edit the Attribute Set.

Select the Add Attribute Set link. Name your Attribute Set "Skills". If you have any categories or interests setup for your site you will have the option to associate them to this attribute set here if you so desire.

Add Attribute Sets

Now you'll see your Skills Attribute Set details - but notice that it has no attributes yet. Select the "Add New Attributes" link.

Here you can add the details of your Attributes. Attributes are the new "fields" you create per Attribute Set. An example of a new Attribute would be a "Common skills" field (MutliSelect box) for the above mentioned "Skills" Attribute set. These attributes sets along with their associated attributes would appear in all Extended Attribute tabs that have the subType.

Here are the fields explained:

  • Name: This is the "variable" name for the attribute. This is another case where you need to keep your naming convention strict.

    It is also important to namespace the variable based on its subType and Attribute Set's name. This isn't shown in this example, but if you have many attributes in your site you could easily build two (or more) attributes with the same name - don't do this! Mura always renders the first one found based on the attribute name itself.
  • Label: This is the friendly label that you would want everyone to see. If one is not supplied then the name field is used in its place.
  • Hint: Next to each field within the "Extended Attributes" tab for each type you have the option to provide a hint "pop-up" that will help the user understand what that field is meant for in the admin view of that subType.
  • Input Type: This field dictates how the field will be rendered (Selectbox, MultiSelect, HTMLEditor [FCKEditor], etc.).
  • Default Value: This field holds a default value if one is not selected by the user.
  • Required: This field ensures that a user supplies an entry for the attribute. If an entry is not supplied then the "Validation Message" error pop-up message appears for them and halts the process from going any further.
  • Validate: Date, numeric, email, regex.
  • Regex: If Regex is chosen then it's associated validation regex goes here.
  • Validation Message: This field holds the error message you would like to have displayed if you have validation turned to "true".
  • Option List: The is a "^" delimited list of options "values" that would be used if you choose a input type of selectBox, multiSelect or radioButton
  • Option Label List: This is a "^" delimited list of labels for each option you would provide to the above option list. The positioning of the entry within the list correlates to the option list.

You should now see your attribute within the Attribute Set. Here you will find a "Reorder" link that will give you the ability to reorder the attributes if you like - this is primarily for display purposes.

Now that the new subType is fully setup we can now use it within a page. To do this, simply go to your site manager, choose any page that you would like to have the subType assigned to and select it.

Once the subType is selected it will automatically update the Extended Attributes tab with that subType's associated Attribute Sets/Attributes.

Displaying Extended Attributes

There are many ways you can display extended attributes. The most common way to display the value of an attribute is to use the content bean from the event upon rendering and ask for the attribute. This can be done by using the below code:

<cfoutput>#$.content('attributeName')</cfoutput>

For the above example it would be:

<cfoutput>#$.content('CommonSkills')#</cfoutput>

It's important to know that each Mura type displays differently from the other. In the above we focused on how a page type would be setup, but a user type will be a little different (showing extended attributes on the edit profile screen, etc).

Also, you can also use similar code within the body section of the page via Mura tags:

[ mura]$.content('CommonSkills')[/mura ]

(Remember to remove spaces around the Mura tag)

It will display like this on the front end.

Comments

Greg

You mentioned that adding a subType of productswould be a good example of holding more information about a spacific product. My question is, what base type would you suggest adding this to? page?

This also leads to a second question, is there any way to add "Type" so for example you could have:

User Group, User, Address, Page, Portal, File Calendar, Gallery, Link, Product?

January 25, 2010, 4:41 PM
Pat Santora

@Greg

Use page as your type. It's the most common type in Mura.

For the other question: Are you wanting to access your subtype in a custom event manner? If so this is totally possible and I can explain more if this is the case. If not, can you explain this further?

Pat

January 31, 2010, 2:14 AM
Greg

Actually that is exactly what I would like to do. Maybe if I could see how it would work that would be helpful.

February 1, 2010, 2:23 PM
Pat Santora

@Greg,

Take a look at this post http://www.getmura.com/mura/index.cfm/blog/mapping-events-in-mura/

What you are going to want to do is map to the on{Type}{SubType}BodyRender event.

It would look something like this within your plugin or event handler:

<cffunction name="onPageResumeBodyRender">

<cfargument name="event"/>

<!--- do something here --->

</cffunction>

This event will be caught upon rendering of the Mura type/subtype and let us adjust the event, render accordingly.

Hope this helps.

-Pat

February 2, 2010, 2:33 PM
Jonas

Thank you for showing this clearly with a good example (resume / skills). I successfully extended the User/default to include a couple of option boxes to tick whether or not somebody had paid membership fees. How do I limit this so only Admins / "the backend" has access to this data and it is not visible in the standard "Edit Profile" form from the public User Tools component? Thanks for clarification!

March 9, 2010, 7:03 PM
Matt Levine

If you update you core to the latest version (5.2.1887) You can now set an attribute type to "Hidden".

You will also need to either update your site version or just update your dsp_edit_profile.cfm.

http://svn.blueriver.com/mura/trunk/www/default/includes/display_objects/dsp_edit_profile.cfm

March 9, 2010, 8:04 PM
Jonas Eriksson

Hi Matt, thanks - could this be added to the instructions above? Not quite clear where I set this "Hidden" so I still see it in the Admin section but not in thw public Edit Profile part. Cheers.

April 25, 2010, 8:48 AM
voltronad

Hello - this is a great article! I am currently working on a site where i need to make site members (users) have a lot of extra fields not in the default profile (for example, attach an image to their profile).

I need to enhance the User (site member) sub-type, and I just am having some problems applying the above example to my situation. I have created this post and if anyone can provide assistance, I'd really appriciate it:

http://www.getmura.com/forum/messages.cfm?threadid=803466B0-6466-4B63-B4F4E46350999563

May 26, 2010, 6:58 PM
murphyhg

I have been able to create a class extension to the File content type. It is called File/type_software and it has an Attribute Set called att_software and it has attributes called language_software, version_software, and size_software. I am not sure of the syntax to get the query object or object and loop over it to get at those attributes? Can you please show that syntax?

July 9, 2010, 10:34 AM
Matt Levine

@murphyhp

I would download out new developer pdf and read the part about Mura content iterators

http://docs.getmura.com/index.cfm/developer-guides/back-end-development/

July 10, 2010, 12:06 AM
Post a Comment
  1. Leave this field empty

Required Field