This project is read-only.

Extend document

Nov 4, 2014 at 2:52 AM
Hi guys,

Thank you for providing such a great CMS as Mr.CMS.

Can you help me to understand how I can extend document table with another string column. And later to use that property in inserting document process?

Nov 4, 2014 at 5:19 AM
Hi Bogdan,

To do what you're wanting to do there are a few steps to go through, to work the way that we have been on our implementations:
  • Create an app in your main project. To do this create a folder in the Apps folder in MrCMS.Web, and an implementation of MrCMSApp (e.g. GalleriesApp in the standard distribution)
  • Create a subclass of Webpage in your App folder. We tend to use the convention of creating a Pages subfolder in the app for them to go into, but this is not strictly necessary. An example of our version would be this though. All you need to do is ensure that properties are virtual (to keep NHibernate happy/functional) and are public with a public getter and setter, and they'll be picked up by convention.
  • Within your app, create an Areas and Admin folder, to mirror the standard admin, then a Views folder (don't forget to add a web.config, just copy one from any other views folder) and finally a Webpage folder in the Views, so you should end up with a folder like this. In that folder, add 2 partial views [YourSubclassName].cshtml and [YourSubclassName]Add.cshtml, which will contain the editor fields for the extra properties that you've extended. These will be picked up by the CMS via convention when adding
  • To display the data on the front end, you'll need to create a Views/Pages folder at the root of your app (again remembering to get a views web.config for the Views root), and put a [YourSubclassName].cshtml file into there as per this.
That is kinda the bare bare minimum to get something working. There is then a bunch of extensibility that's kicking about that is frankly not documented well enough that I'll try to go over here.
  • If you need to do something custom with your entity data (you can use MrCMS to create any sort of table in the DB, Webpages being one of these types), you can use implementations of the FluentNHibernate IAutoMappingOverride<T>interface to do this, an example being this in Articles. A typical use-case for this is making string fields varchar(max), which can now be done using the .MakeVarCharMax() extension method.
  • If you need to use a custom controller (by default GET requests for all MrCMS pages are handled by WebpageController in the core), create an implementation of DocumentMetadataMap<T> in your project, where T is your page type, and example of which is this in Core. There are a few overriden fields there, but the pertinent one is WebGetController, which tells MrCMS to look for that controller, which in this case resolves LoginController (not our tidiest controller, but never mind...) This will resolve any constructor injections using autowired Ninject IoC, so create any interfaces and services as required.
  • If you need to add admin view data as a part of setting up your page, create an implementation of BaseAssignWebpageAdminViewData<T> as per this example in Articles to bring in a list of options for a Article's author. All implementations of this class are called during both add and edit of a page type, so you can feel free to split out your viewdata into a class per property if you so desire.
I'm sure there are things that I've missed off here still, as to be honest we tend to keep building features and extension points as we need them. Also, if I've jumped over something blatantly obvious that you're having bother with, feel free to let me know and I'll see if I can be of help.

Marked as answer by bnicovski on 11/4/2014 at 7:18 AM
Nov 4, 2014 at 1:47 PM
Thank's a lot. This helps me.