例子:

usingOrchard.ContentManagement.MetaData;usingOrchard.Core.Contents.Extensions;usingOrchard.Data.Migration;usingOrchard.Environment.Extensions;usingOrchardHUN.TrainingDemo.Models;namespaceOrchardHUN.TrainingDemo
{[OrchardFeature("OrchardHUN.TrainingDemo.Contents")]public classContentsMigrations : DataMigrationImpl{public intCreate(){SchemaBuilder.CreateTable(typeof(PersonListPartRecord).Name, table=>table//Since PersonListPartRecord is a ContentPartRecord we have to use this method here. For ContentPartVersionRecord we would//simply use ContentPartVersionRecord()
.ContentPartRecord().Column<string>("Sex").Column<int>("MaxCount"));/** We make PersonListPart attachable. This means from the admin UI you'll be able to attach this part to any conent type. This step* is not necessary to attach the part to types from migrations like we do it from here.* Default is not attachable.*/ContentDefinitionManager.AlterPartDefinition(typeof(PersonListPart).Name,builder=>builder.Attachable());/** We create a new content type. Note that there's only an alter method: this will create the type if it doesn't exist or modify it* if it does. Make sure you understand what content types are:http://docs.orchardproject.net/Documentation/Content-types* The content type's name is arbitrary, but choose a meaningful one.* Notice that we attach parts by specifying their name. For our own parts we use typeof().Name: this is not mandatory but serves* great if we change the part's name during development. (The same goes for record name BTW.)*/ContentDefinitionManager.AlterTypeDefinition("PersonList", cfg=>cfg//Setting display name for the type. BTW the default is the technical name separated on capital letters, so the same here..DisplayedAs("Person List").WithPart("TitlePart") //So the list can have a title; TitlePart is a core part//AutoroutePart so the list can have a friendly URL. That's why this feature depends on Orchard.Autoroute..WithPart("AutoroutePart", builder =>builder//These are TypePart settings: settings for a part on a specific type. I.e. AutoroutePart have the following settings//for PersonList. Take a look at AutoroutePart settings on the type editor UI of PersonList to see what these mean..WithSetting("AutorouteSettings.AllowCustomPattern", "true").WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "false")//Specifying a custom URL-pattern for PersonList items.WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Title', Pattern: 'person-lists/{Content.Slug}', Description: 'my-list'}]").WithSetting("AutorouteSettings.DefaultPatternIndex", "0")).WithPart(typeof(PersonListPart).Name)//CommonPart includes e.g. creation date and owner. Take a look at it (search with Ctrl+comma).//Also without it we can't list content types of this type on the admin UI (because the dates stored in it are needed for//ordering)..WithPart("CommonPart").Creatable()//This means users will be able to create such items from the admin UI. Default is the opposite.
);/** With the same part we also create a widget. That's why this feature also depends on Orchard.Widgets!* Note that widgets should* - Have CommonPart attached* - Have WidgetPart attached* - Have the stereotype "Widget"*/ContentDefinitionManager.AlterTypeDefinition("PersonListWidget",cfg=>cfg.WithPart(typeof(PersonListPart).Name).WithPart("WidgetPart").WithPart("CommonPart").WithSetting("Stereotype", "Widget"));return 1;//Please don't read UpdateFrom1() yet.//You read it, didn't you? Stop spoiling.//NEXT STATION: Handlers/PersonListPartHandler
}public intUpdateFrom1(){//We're attaching the YouTubeEmbedField to the PersonListPart, which is already attached to the PersonList type.ContentDefinitionManager.AlterPartDefinition(typeof(PersonListPart).Name,builder=>builder//This name distinguishes between fields if there are multiple ones of the same type on the part.WithField("YouTubeVideoEmbed",f=>f.WithDisplayName("YouTube Video Embed") //This will be displayed as the name.OfType(typeof(YouTubeEmbedField).Name)));//We've attached the field here to an existing part, but we could have created a new part (just giving an arbitrary name as//the argument for AlterPartDefinition() would be enough) too.//Note that fields are always attached to parts. If you attach fields seemingly directly to a content type fromt the admin UI//in the background an invisible part is created, having the same name as the type.return 2;//NEXT STATION: Drivers/YouTubeEmbedFieldDriver.cs
}}
}

转载于:https://www.cnblogs.com/zsanhong/archive/2013/05/27/3101128.html

OrchardHUN.TrainingDemo 学习记录(2)-Migration中,添加contentPart 和widget相关推荐

  1. 三维荧光学习记录--在Origin中绘制三维荧光光谱图(补充)及荧光区域积分(FRI)

    三维荧光学习记录–在Origin中绘制三维荧光光谱图(补充)及荧光区域积分(FRI) 注:本文仅作为自己的学习记录以备以后复习查阅 关于区域积分的简介,大家可以去看我之前的文章,这里就不赘述了,主要想 ...

  2. 三维荧光学习记录--在Origin中绘制三维荧光光谱图

    三维荧光学习记录–在Origin中绘制三维荧光光谱图 注:本文仅作为自己的学习记录以备以后复习查阅 记录一下如何在Origin中绘制三维荧光光谱图(数据分析的学习之路任重而道远啊~~) 一.数据准备 ...

  3. UE4 学习记录二 给角色添加骨架,皮肤,及运动动画

    这只是用来记录我学习UE4过程的,可能帮不到你,先说声抱歉.为了防止误导他人,请勿转载,请勿转载,请勿转载. 本文的主题是给角色添加骨架.皮肤.运动动动画.总章目录(https://blog.csdn ...

  4. Redis学习记录之Java中的初步使用

    [html] view plain copy  redis下载地址:<span style="font-family: Arial, Helvetica, sans-serif;&qu ...

  5. STM8学习笔记---IAR工程中添加文件夹

    将demo工程重命名为led后,然后再LED文件夹内新建一个文件夹,改名为 HardWare. 然后再HardWare文件夹内新建led.c和led.h文件. 然后双击led.eww,打开led工程. ...

  6. 前端学习-如何在title中添加图片

    <head><meta charset="UTF-8"><meta name="viewport" content="w ...

  7. 【学习记录】多主体中的BDI(Belief-Desire-Intention)

    0 写在前面 最近在做多主体建模仿真的项目,希望将BDI模型融合到人的主体上.但是目前没有找到很多国内研究BDI的工作.这篇文章是记录自己学习BDI的一点过程和想法,包括: 关于BDI的一些事实 BD ...

  8. django 数据库mysql学习向数据库表中添加数据

    环境:windows ,已经安装了 mysql, 安装了django 1.新建一个django 项目 2.新建一个子应用 python manage.py startapp moelsinfo 3.在 ...

  9. [STM32学习笔记1]Keil5中添加库包,搭建开发环境

    基于野火HAL库开发视频–第6讲-第一个外设(GPIO)2–学习笔记 STM32F103ZET6 STM32Cube_FW_F1_V1.8.0 hal库包 解压 ![有用的都在这](https://i ...

最新文章

  1. Java实现MD5(32/16位大小写)加密
  2. 【计算理论】可判定性 ( 计算模型与语言 | 区分 可计算语言 与 可判定语言 | 证明 通用图灵机语言是 可计算语言 | 通用任务图灵机 与 特殊任务图灵机 )
  3. 关于《在Windows与.NET平台上的持续交付实践》的问答录
  4. Java并发编程之堵塞队列介绍以及SkipList(跳表)
  5. python图片转字符_二十行python代码实现图片转字符
  6. 麦吉尔大学 计算机科学和阿尔伯特,阿尔伯特大学怎么样?
  7. 祝贺吾博文中第一篇点击超过一万的文章出现
  8. Thinkpad笔记本没有声音的解决办法参考
  9. mysql 游标动态传参数_Mysql 游标施用动态变量
  10. 深度linux 无线网卡,在Deepin Linux系统无线网卡、蓝牙模块驱动安装和出现问题的解决...
  11. 移动端轮播图——网易云音乐手机端样式
  12. OJ 2309 Problem C Lemon
  13. oracle remap schema,oracle 10g DATA PUMP 的REMAP_SCHEMA和REMAP_TABLESPACE的功能
  14. Asterisk 实现语音提示:您呼叫的号码无法接通
  15. HarmonyOS与Android的全面对比
  16. 约瑟夫环问题的几种解法
  17. 阿里,腾讯,百度软件测试工程师推荐——软件测试模型之瀑布模型
  18. 移植mpt3sas驱动
  19. 自定义函数代替inet_addr函数写入ip
  20. 《程序员2007增刊——实战Web2.0》精彩预览之“指导篇”

热门文章

  1. 【洛谷 2782】友好城市
  2. 【9704】【9109】麦森数
  3. 华为OJ 名字美丽度
  4. C#托管代码是什么?非托管代码是什么?
  5. ASP.NET内部原理(HttpHandler和HttpModule)
  6. mahout推荐10-尝试GroupLens数据集
  7. mdi 子窗体 菜单 不合并。
  8. window编程_消息分类
  9. C#软件自动更新程序
  10. 恢复linux里被误删除的文件