Quantcast
Channel: Real World Software
Viewing all articles
Browse latest Browse all 19

Orchard CMS

$
0
0

Introduction

Recently I have been doing development work on Orchard CMS, creating and modifying modules in Visual Studio. I have found that the documentation is fairly limited especially for the new features. I have had to use stackoverflow.com and various blogs to make my new Modules work.  So far the most useful blog has been

http://www.ideliverable.com/blog/writing-an-orchard-webshop-module-from-scratch-part-1

This tutorial proved to be useful however it covers a lot of ground and I had problems debugging it.

 Basic Requirements for a module

If you want to create a basic content part in your module it must have the following components.

  • Driver
  • Handler
  • Model
  • Data tables, created from the data migration
  • placement.info entries.  Without this your part will not be displayed.
  • Module.txt

If you are adding a new feature to a module then you will need to mark each of the classes with the OrchardFeature attribute.  The FeatureName must match the Features value in Module.txt.

Orchard Data Schema

The key feature of Orchard is that a Content Definition is made up of Content Parts. A Content Definition can also have Fields on the Content Item itself as well as properties on the Parts which make up the Content Definition.  This SQL query shows how this is reflected in the database is structure.

SELECT i.Id, v.Data, t.Title
FROM Orchard_Framework_ContentItemRecord i
JOIN Orchard_Framework_ContentItemVersionRecord v ON v.ContentItemRecord_id = i.Id
JOIN Title_TitlePartRecord t ON t.Id = v.Id
WHERE i.ContentType_id IN (SELECT Id FROM Orchard_Framework_ContentTypeRecord WHERE Name = 'MyContentDefinition');

The v.Data in this query will return XML which contains the Content Definition Fields and the Title comes from the TitlePart which is a part of the ‘MyContentDefinition’ Content Definition (confusingly, ContentType is another name for Content Definition).

In Orchard 1.8 the Part data can be is stored in the Data XML instead of using a separate table for each part.  This is implemented with an InfoSet which will de-normalize the data and improve DB performance.

If you create your own parts (in a module) they will be similar to the built in Title Part however your Part Record will not have a ContentItemRecord_id field.  The Id field will be used to join onto the content item record, for example

JOIN MyCompany_MyModule_MyPartRecord p ON p.Id = i.Id

Here you can see that the primary key on your record table is also a foreign key linking to the content.  You can query Orchard data by building HQL (NHibernate) queries in C#.  This is probably the most efficient and powerful way to access Orchard data however it is not always used because it can add complexity where built in Orchard functions could be used.



Viewing all articles
Browse latest Browse all 19

Trending Articles