Category: Orchard CMS

Oct 06 2013

Things to remember about extending Orchard CMS

  1. Use the Orchard command line to create a module   —
    Type “help command” to get a list of command available in the orchard console.
    Enable code generation – type “feature enable Orchard.CodeGeneration”
    Type “help codegen module” to get usage on creating a module
    Type “codegen  module <projectname> /IncludeInSolution:true” to create your module.
  2. Use the Orchard command line to create a migration —
    Type “help codegen datamigration” to get usage
    Type “codegen datamigration <projectname> to create a migration for your project.
  3. To deploy an Orchard site —
    Open a VS command prompt at the root of your build sources
    type “build Precompiled”…this will create “build” and “buildtasks” folders
    The deployment source is in “build\Precompiled”
    Be sure that the App_Pool security context has write permissions on App_Data, and a Media folder (which you will have to create) of the IIS root
    NOTE -
  4. Info on handling existing databases
  5. Handling 1-1 and n-n db relaitonships in Orchard…

TO MAKE A NEW ORCHARD CONTENT PART…Lets call it the Xyz part

  1. Create a XyzPart  class.  Inherit from ContentPart<XyzPartRecord>
    This is a simple poco with property setters and gettters for each field in the part.
    The GET wll return Record..<FieldName>  like get {return Record.ItemCode; }
    The SET does the same like  set { Record.ItemCode = value;}
    Using Orchard and Orchard.ContentManagement
  2. Create a XyzPartRecord (per the reference in step 1) class that inherits from ContentPartRecord. 
    It uses matching virtual properties (so NHibernate can deal with it) like …
      public virtual string ItemCode{ get; set; }
    Using Orchard and Orchard.ContentManagement.Records
  3. Add migrations for updating the database.  
    Add a Create method.
    Use SchemaBuild.CreateTable to create the table and associate the content part with the record using lambdas like this…
    SchemaBuilder.CreateTable(“XyzPartRecord”, table=>table.ContentPartRecord().Column<string>(“ITemCode”));
  4. Creae a XyzPartHandler class which inherits from ContentHandler…
    This class just wires up the IRepository for the part like this…
    CTOR –
    publci XyzPartHandler(IRepository<XyzPartRecord> repository)  {
    Filters.Add(StorageFilter.For(repository));   }
    Using Orchard.Data and Orchard.ContentManagement.Handlers
    The handler plugs into the event lifecycle of a part and is typically used to wire up events.
  5. Please note that a Handler can hook into any part of the Part lifecycle.
    Add a XyzFeatureEventHandler file.
    Inherit from IFeatureEventHandler….implement the interfaces as necessary.  Notice that it has very generous Event Model…Number of points in the lifecycle.
    Delete  the not implemented exception we don’t need.
  6. Create XyzPartDriver which inherits from ContentPartDriver<XyzPart>
    The Driver serves the same function as an MVC Controller except that it operates at the part level rather than the page request level. 
  7. Creaet an XyzService class that Inherits from IXyzService which is an interface declard in the same file (I think this design is to enable use with an IOC).
    At the ver least add an Update method called something like UpwardXyzFor ContentItem and pass in a viewmodel and ContentItem.