Taxonomies: Coding and after coding problems

Topics: Customizing Orchard
Aug 3, 2012 at 2:23 PM
Edited Aug 3, 2012 at 2:27 PM

I try to create taxonomies in the Migration.cs and assign them to content types. This is my code


var contentItem = _contentManager.New<TaxonomyPart>("Taxonomy");
            contentItem.Name = "Legal Status";
            _contentManager.Create(contentItem, VersionOptions.Published);
            CreateTerm(contentItem, "Status 1");
            CreateTerm(contentItem, "Status 2");
            CreateTerm(contentItem, "Status 3");

            ContentDefinitionManager.AlterPartDefinition(typeof(ApplicantPart).Name, p => p
                .WithField("LegalStatusClass", f => f
                    .WithSetting("TaxonomyFieldSetting.Taxonomy", contentItem.Name)
                    .WithSetting("TaxonomyFieldSetting.LeavesOnly", "True")
                    .WithSetting("TaxonomyFieldSetting.SingleChoice", "False"))
                .WithSetting("TaxonomyFieldSettings.TaxonomyId", contentItem.Id.ToString())
            ContentDefinitionManager.AlterTypeDefinition("Applicant", t => t

All looks fine. Applicant has LegalStatusClass taxonomy field but 'Select a taxonomy' dropdown list is empty. This is my first problem. How to make that selection from my code?

Just after the migration code execution I could open Left menu Taxonomy and saw all existing and newly added taxonomies. My second problem is when I try to create a new taxonomy from Admin UI . For a reason I can't figure out TaxonomyPartDriver's Editor method receives part with part.Name=null.

protected override DriverResult Editor(TaxonomyPart part, Orchard.ContentManagement.IUpdateModel updater, dynamic shapeHelper) {
            TaxonomyPart existing = _taxonomyService.GetTaxonomyByName(part.Name);

            return null;

So next time when you click on Left menu Taxonomy one of the taxonomy entries has Name=null and Slug=-2 and causes the obvious error


Value cannot be null or empty. Parameter name: linkText

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Value cannot be null or empty.
Parameter name: linkText

Source Error:

Line 41: 				</td>
Line 42: 				<td>
Line 43: 					@Html.ActionLink(taxonomyEntry.Taxonomy.Name, "Index", "TermAdmin", new { taxonomyId = taxonomyEntry.Taxonomy.Id }, new object { })
Line 44: 				</td>
Line 45: 				<td>

Source File: c:\ProjectsY\Orchard\src\Orchard.Web\Modules\Contrib.Taxonomies\Views\Admin\Index.cshtml    Line: 43

Stack Trace:

[ArgumentException: Value cannot be null or empty.
Parameter name: linkText]
   System.Web.Mvc.Html.LinkExtensions.ActionLink(HtmlHelper htmlHelper, String linkText, String actionName, String controllerName, RouteValueDictionary routeValues, IDictionary`2 htmlAttributes) +336603
   System.Web.Mvc.Html.LinkExtensions.ActionLink(HtmlHelper htmlHelper, String linkText, String actionName, String controllerName, Object routeValues, Object htmlAttributes) +58
   ASP._Page_Modules_Contrib_Taxonomies_Views_Admin_Index_cshtml.Execute() in c:\ProjectsY\Orchard\src\Orchard.Web\Modules\Contrib.Taxonomies\Views\Admin\Index.cshtml:43
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +207
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +81

It looks like that it is my code broke something and I need some help to find out what is going on here. Probably it is the reason for my first problem as well.

Any thoughts what to check, where to look please!

Aug 4, 2012 at 11:45 PM
Edited Aug 6, 2012 at 11:59 AM


I still don't know how to select a taxonomy for a content type ('Select a taxonomy' dropdown list in UI) programmatically.

Please help...

About my second problem with Taxonomy. I have found out that the source of the problem is Origami module.

It is very easy to replicate. If you have Taxonomy and Origami enabled then if you try to create a new taxonomy, type its name and Save - TaxonomyPartDriver's Editor method receives a part with part.Name=null (before going to Editor method the contol is taken by Origami). I haven't had enough time to figure out what the problem is in Origami but it seems it doesn't work currently with v.1.5 (or may be with Taxonomy together).

I found out the reason. Actually Origami doesn't work with v 1.5 because of changed Orchard framework. In particular, ctor in ZoneHoldingBehavior class has different signature

// v 1.4.2

public ZoneHoldingBehavior(Func<dynamic> zoneFactory) {
            _zoneFactory = zoneFactory;

// v 1.5

public ZoneHoldingBehavior(Func<dynamic> zoneFactory, dynamic layoutShape) {
            _zoneFactory = zoneFactory;
            _layoutShape = layoutShape;
When I firstly met that fact I just set the second parameter to null. I could enable Origami after that but it seems doesn't work for Taxonomy. What is supposed I need to do in order to cope with this changed signature?
And there is another concern actually about our custom modules. It is error-prone to upgrade the system to any new version. What about a backward compatibility in the framework and core then?