• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
OrchardCMS module development
 

OrchardCMS module development

on

  • 2,597 views

So, you need a Content Management System on the .NET framework. While your business might spend wheelbarrows of money on a platform that is powerful and extensible, your personal site would abandon ...

So, you need a Content Management System on the .NET framework. While your business might spend wheelbarrows of money on a platform that is powerful and extensible, your personal site would abandon extensibility for a free, open-source solution. But what if we had an option that was free and powerful and extensible? We do: Orchard CMS. Since we already know that Orchard is free, in this session we will discuss the power of Orchard’s CMS engine. You will learn how to build new modules for the Orchard platform, allowing you to extend functionality as you see fit to meet the needs of your site, your business, and customers.

Statistics

Views

Total Views
2,597
Views on SlideShare
2,553
Embed Views
44

Actions

Likes
8
Downloads
0
Comments
0

2 Embeds 44

http://localhost 43
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    OrchardCMS module development OrchardCMS module development Presentation Transcript

    • Orchard MODULES GROWING YOUR
    • “ We wanted a modern CMS based on ASP.NET MVC. We also wanted an extremely extensible platform similar to what PHP has with Drupal. But most importantly we wanted to build better bridges between our team at Microsoft and the open-source community. ” Betrand Le Roy, Creator of Orchard
    • Content FUNDAMENTALS
    • ContentFields
    • lly!” y be in m Get “ es ! ” h no “O ContentFields contain Data
    • ContentParts
    • eye cary s arp ig s h b eeth t ContentParts ean! lly m r ea have Behavior
    • ContentTypes
    • ContentTypes are Consumable by Users
    • Types Parts Fields Data
    • Types Fields Data
    • each is an a content item instance of content type
    • Module/Feature
    • Module/Feature features extend the CMS modules contain and distribute
    • Module FUNDAMENTALS
    • RecordsAndParts records are Data Models parts are View Models
    • HandlersAndDrivers handlers give behavior to the code drivers are are specialized controllers
    • ShapeTemplates
    • DependencyInjection
    • Controllers
    • ModuleManifest
    • Manifest [Module|Theme] “ A manifest stores metadata that Orchard uses to describe modules and themes to the system, such as name, version, description, author, and tags. ” docs.orchardproject.net
    • 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Name: AntiSpam AntiForgery: enabled Author: The Orchard Team Website: http://orchardproject.net Version: 1.7.2 OrchardVersion: 1.7.2 Description: Provides anti-spam services to protect your Features: Orchard.AntiSpam: Name: Anti-Spam Description: Provides anti-spam services to prot Category: Security Dependencies: Orchard.Tokens, Orchard.jQuery Akismet.Filter: Name: Akismet Anti-Spam Filter Description: Provides an anti-spam filter based Category: Security Dependencies: Orchard.AntiSpam
    • Orchard EXECUTABLE
    • WebSiteAndConsoleApp
    • “ The Orchard command interpreter supports running a few built-in commands as well as specific commands from enabled features of an Orchard installation. ” Orchard.exe
    • C:OrchardsrcOrchard.Webbin> Orchard.exe_
    • C:OrchardsrcOrchard.Webbin> Orchard.exe Initializing Orchard session. (This might take a few seconds...) Type "?" for help, "exit" to exit, "cls" to clear screen orchard> _
    • orchard> call me "Rock God" Error executing command "call me Rock God" ---------------------------------------------------------No command found matching arguments "call me Rock God". Commands available: site setting set baseurl, autoroute create, theme list, theme activate, widget create, layer create, menuitem create, menu create, blog create, blog import, ...
    • Module DEVELOPMENT
    • 1 # p te S od C io n at ner Ge e
    • CodeGeneration
    • orchard> feature enable Orchard.CodeGeneration_
    • orchard> feature enable Orchard.CodeGeneration Enabling features Orchard.CodeGeneration Code Generation was enabled orchard> _
    • orchard> feature enable Orchard.CodeGeneration Enabling features Orchard.CodeGeneration Code Generation was enabled orchard> codegen module SlideShare /IncludeInSolution:true_
    • orchard> feature enable Orchard.CodeGeneration Enabling features Orchard.CodeGeneration Code Generation was enabled orchard> codegen module SlideShare /IncludeInSolution:true Creating Module SlideShare Module SlideShare created successfully orchard> _
    • ReadyGo
    • UpdateManifest
    • 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Name: SlideShare AntiForgery: enabled Author: Jay Harris, Arana Software Website: http://www.aranasoft.com Version: 1.0 OrchardVersion: 1.0 Description: Provide SlideShare presentations as an atta Features: SlideShare: Description: Provide SlideShare presentations as an Category: Social
    • 2 # p te S ec R r ts Pa s& rd o
    • RecordsAndParts AddNewClass
    • 1 2 3 4 namespace SlideShare.Models { public class SlideShareRecord { 5 6 7 } 8 9 } 10
    • 1 using Orchard.ContentManagement.Records; 2 3 4 namespace SlideShare.Models { public class SlideShareRecord : ContentPartRecord { 5 6 7 } 8 9 } 10
    • using Orchard.ContentManagement.Records; 1 2 3 4 namespace SlideShare.Models { public class SlideShareRecord : ContentPartRecord { 5 public virtual string SlideShareId { get; set; } 6 public virtual int? StartFromSlide { get; set; } 7 } 8 9 } 10
    • se U ce spa me Na S EL D O or M S D R O C E R
    • ies rt pe ro kP ar M L A U T IR V
    • ur Yo nd Mi S S LA C E S A B
    • 1 using Orchard.ContentManagement.Records; 2 3 4 namespace SlideShare.Models { public class SlideShareRecord : ContentPartRecord { 5 public virtual string SlideShareId { get; set; } 6 public virtual int? StartFromSlide { get; set; } 7 } 8 9 } 10
    • 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 using Orchard.ContentManagement; using Orchard.ContentManagement.Records; namespace SlideShare.Models { public class SlideShareRecord : ContentPartRecord { public virtual string SlideShareId { get; set; } public virtual int? StartFromSlide { get; set; } } public class SlideSharePart : ContentPart<SlideShareRecord> { } }
    • 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 public class SlideSharePart : ContentPart<SlideShareRecord> { public string SlideShareId { get { return Record.SlideShareId; } set { Record.SlideShareId = value; } } [Range(1, 20)] public int? StartFromSlide { get { return Record.StartFromSlide; } set { Record.StartFromSlide = value; } } }
    • le i p m o C i ng ed oce Pr ore ef B
    • 3 # p te S Da io n at i gr aM t
    • orchard> codegen datamigration SlideShare_
    • orchard> codegen datamigration SlideShare Creating Data Migration for SlideShare Data migration created successfully in Module SlideShare orchard> _
    • DataMigration
    • 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 using System.Data; using Orchard.Data.Migration; namespace SlideShare { public class Migrations : DataMigrationImpl { public int Create() { // Creating table SlideShareRecord SchemaBuilder.CreateTable("SlideShareRecord", table => table !!!! .ContentPartRecord() !!!! .Column("SlideShareId", DbType.String) !!!! .Column("StartFromSlide", DbType.Int32) ); return 1; } } }
    • 11 12 !!!! 13 !!!! // column methods can use generic types... .Column<string>("SlideShareId") .Column<int>("StartFromSlide") 11 12 !!!! 13 !!!! // or they can use a DbType argument. .Column("SlideShareId", DbType.String) .Column("StartFromSlide", DbType.Int32) // either way. just not both.
    • 5 6 public class Migrations : DataMigrationImpl { public int Create() { // The ‘return’ is for versioning return 1; 14 15 16 } public int UpdateFrom1() { // Do some data migrations return 2; } public int UpdateFrom2() { // More data migrations return 3; } 25 26 27 33 34 35 }
    • Attachable [Content Part] “ Indicates if administrators can attach the Content Part to any Content Type, or if the Part is limited only to Types explicitly specified by the Module. ”
    • 1 2 3 4 5 6 7 8 using using using using using System.Data; Orchard.ContentManagement.MetaData; Orchard.Core.Contents.Extensions; Orchard.Data.Migration; SlideShare.Models; namespace SlideShare { public class Migrations : DataMigrationImpl { public int UpdateFrom1() { 17 ContentDefinitionManager.AlterPartDefinition( 18 "SlideSharePart", cfg => cfg.Attachable()); 19 return 2; 20 } 21 } 22 23 } 24
    • 1 2 3 4 5 6 7 8 using using using using using System.Data; Orchard.ContentManagement.MetaData; Orchard.Core.Contents.Extensions; Orchard.Data.Migration; SlideShare.Models; namespace SlideShare { public class Migrations : DataMigrationImpl { public int UpdateFrom1() { 17 ContentDefinitionManager.AlterPartDefinition( 18 typeof(SlideSharePart).Name, cfg => cfg.Attachable( 19 return 2; 20 } 21 } 22 23 } 24
    • 4 # p te S and H ers r iv &D ers l
    • CreateHandler
    • Part Handlers “ Most Handlers will be very simple behavior managers. Often, the only behavior they will have to specify is how data is to be stored. ”
    • 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 using SlideShare.Models; using Orchard.ContentManagement.Handlers; using Orchard.Data; namespace SlideShare.Handlers { public class SlideShareHandler : ContentHandler { public SlideShareHandler( IRepository<SlideShareRecord> repository) { Filters.Add(StorageFilter.For(repository)); } } }
    • CreateDriver
    • 1 2 3 4 5 6 7 8 9 10 11 12 13 using using using using System; Orchard.ContentManagement; Orchard.ContentManagement.Drivers; SlideShare.Models; namespace SlideShare.Drivers { public class SlideShareDriver : ContentPartDriver<SlideSharePart> { } }
    • 10 11 12 13 14 15 16 17 18 19 20 21 protected override DriverResult Display( SlideSharePart part, string displayType, dynamic shapeHelper) { return ContentShape("Parts_SlideShare", () => shapeHelper.Parts_SlideShare( SlideShareId: part.SlideShareId, StartFromSlide: part.StartFromSlide ) ); }
    • 23 24 25 26 27 28 29 30 31 32 33 34 35 //GET protected override DriverResult Editor( SlideSharePart part, dynamic shapeHelper) { return ContentShape("Parts_SlideShare_Edit", () => shapeHelper.EditorTemplate( TemplateName: "Parts/SlideShare", Model: part, Prefix: Prefix ) ); }
    • 37 38 39 40 41 42 43 44 45 //POST protected override DriverResult Editor( SlideSharePart part, IUpdateModel updater, dynamic shapeHelper) { updater.TryUpdateModel(part, Prefix, null, null); return Editor(part, shapeHelper); }
    • 5 # p te S ap Sh tes pl a Tem e
    • DisplayTemplate
    • ur Yo nd Mi V S H T A P W IE
    • 10 11 12 13 14 15 16 17 18 19 20 21 protected override DriverResult Display( SlideSharePart part, string displayType, dynamic shapeHelper) { return ContentShape("Parts_SlideShare", () => shapeHelper.Parts_SlideShare( SlideShareId: part.SlideShareId, StartFromSlide: part.StartFromSlide ) ); }
    • “Parts_SlideShare” translates to Views/Parts/SlideShare.cshtml
    • 1 2 3 4 5 6 7 8 9 10 <iframe src="http://www.slideshare.net/slideshow/ embed_code/13888742?startSlide=8" width="427" height="356" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" allowfullscreen style="border: 1px solid #CCC; border-width: 1px 1px 0; margin-bottom: 5px"> </iframe>
    • 1 @if(!string.IsNullOrWhiteSpace(Model.SlideShareId as string)) 2 { <iframe src="http://www.slideshare.net/slideshow/ 3 embed_code/13888742?startSlide=8" width="427" height="356" frameborder="0" 4 marginwidth="0" marginheight="0" 5 scrolling="no" allowfullscreen 6 style="border: 1px solid #CCC; border-width: 1px 1px 7 0; margin-bottom: 5px"> </iframe> 8 9 }
    • 1 @if(!string.IsNullOrWhiteSpace(Model.SlideShareId as string)) 2 { var startSlide = Model.StartFromSlide as int?; 3 var startSlideQS = startSlide.HasValue 4 ? string.Format("startSlide={0}", startSlide.Value) 5 : string.Empty; 6 7 var slideShareUrl = string.Format( 8 "http://www.slideshare.net/slideshow/embed_code/ 9 {0}?{1}", Model.SlideShareId, 10 startSlideQS); 11 12 <iframe src="@slideShareUrl" 13 width="427" height="356" frameborder="0" 14 marginwidth="0" marginheight="0" 15 scrolling="no" allowfullscreen 16
    • EditorTemplate
    • 23 24 25 26 27 28 29 30 31 32 33 34 35 //GET protected override DriverResult Editor( SlideSharePart part, dynamic shapeHelper) { return ContentShape("Parts_SlideShare_Edit", () => shapeHelper.EditorTemplate( TemplateName: "Parts/SlideShare", Model: part, Prefix: Prefix ) ); }
    • “Parts/SlideShare” translates to Views/EditorTemplates/ Parts/SlideShare.cshtml
    • 1 @model SlideShare.Models.SlideSharePart 2 <fieldset> <legend>SlideShare Fields</legend> 3 <div class="editor-label"> 4 @Html.LabelFor(m => m.SlideShareId) 5 </div> 6 <div class="editor-field"> 7 @Html.TextBoxFor(m => m.SlideShareId) 8 @Html.ValidationMessageFor(m => m.SlideShareId) 9 </div> 10 11 </fieldset>
    • 1 @model SlideShare.Models.SlideSharePart 2 <fieldset> <legend>SlideShare Fields</legend> 3 <div class="editor-label"> 4 @Html.LabelFor(m => m.SlideShareId) 5 </div> 6 <div class="editor-field"> 7 @Html.TextBoxFor(m => m.SlideShareId) 8 @Html.ValidationMessageFor(m => m.SlideShareId) 9 </div> 10 <div class="editor-label"> 11 @Html.LabelFor(m => m.StartFromSlide) 12 </div> 13 <div class="editor-field"> 14 @Html.TextBoxFor(m => m.StartFromSlide) 15 @Html.ValidationMessageFor(m => m.StartFromSlide) 16 </div> 17 18 </fieldset>
    • ShapePlacement
    • 1 <Placement> <Place Parts_SlideShare="Content:10" /> 2 <Place Parts_SlideShare_Edit="Content:8" /> 3 4 </Placement> 5 6 7 8 9 10 11 12 13 14 15 16 17 18
    • te ra b le e C
    • EnableFeature
    • AddContentDone
    • Module DISTRIBUTION
    • OrchardPackaging
    • orchard> feature enable Orchard.Packaging Enabling features Orchard.Packaging Packaging was enabled orchard> _
    • orchard> feature enable Orchard.Packaging Enabling features Orchard.Packaging Packaging was enabled orchard> package create SlideShare C:Code_
    • orchard> feature enable Orchard.Packaging Enabling features Orchard.Packaging Packaging was enabled orchard> package create SlideShare C:Code Package "C:CodeOrchard.Module.SlideShare.1.0.nupkg" successfully created orchard> _
    • “ ” ...you’ll be able to achieve all kinds of glory and fame. orchardproject.net
    • Profit
    • github.com/aranasoft
    • bit.ly/growingOrchard
    • “ ” ...you’ll be able to achieve all kinds of glory and fame. orchardproject.net
    • jay harris P R E S I D E N T jay@aranasoft.com #growingOrchard @jayharris
    • Thanks