Restrict selectable elements to leaves only

Jun 27, 2011 at 12:43 PM

I was wondered, why if I chose "Restrict selectable elements to leaves only" of Taxonomy field in every content type definition I still see link buttons of root terms in widget?Maybe Author will correct me if I'm wrong. He knows the idea and philosophy of this module much better than me. But here is my solution:

In TaxonomyService class I've added

  public List<TaxonomyFieldSettings> GetContentTypeTaxonomySettings(int taxonomyId) {
    var partFields = _contentPartFieldRepository.Fetch(row => row.ContentFieldDefinitionRecord.Name == "TaxonomyField");
    return partFields.Select(s => _settingsReader.Map(Parse(s.Settings)).GetModel<TaxonomyFieldSettings>()).Where(ms => ms.TaxonomyId == taxonomyId).ToList();
  }

In TaxonomyWidgetPartDriver function Display changed to 

      protected override DriverResult Display(TaxonomyWidgetPart part, string displayType, dynamic shapeHelper) {
        var taxonomy = _taxonomyService.GetTaxonomy(part.TaxonomyPartRecord.Id);
          
        List<TaxonomyFieldSettings> taxonomySettings = null;
        var terms = new List<TermPart>();

        if (taxonomy != null) {
          terms.AddRange(_taxonomyService.GetTerms(taxonomy.Id));
          taxonomySettings = _taxonomyService.GetContentTypeTaxonomySettings(taxonomy.Id);
        }

        return ContentShape("Parts_Taxonomies_TermsWidget",
          () => shapeHelper.Parts_Taxonomies_TermsWidget(ContentPart: part, Terms: terms, Taxonomy: taxonomy, AllSettings: taxonomySettings));
      }

and view Taxonomies.TermsWidget.cshtml is

@using Orchard.Utility.Extensions;
@using Contrib.Taxonomies.Models;
@using Contrib.Taxonomies.Helpers;
@using Contrib.Taxonomies.Settings;
@{
  Style.Include("taxonomy.css");
  int curLevel = -1;
}
<div class="taxonomy-toc">
  @foreach (Contrib.Taxonomies.Models.TermPart term in Model.Terms) {
    int termLevel = term.GetLevels();
    if (termLevel > curLevel) {
      curLevel++;
    @:<ul class="terms">
   } else if (termLevel < curLevel) {
      curLevel--; 
     @:</ul> 		
   } else {
    @:</li>
   }

    @:<li>

    if (Model.AllSettings != null && curLevel == 0) {
      int index = 0;
      while (index < Model.AllSettings.Count && Model.AllSettings[index].LeavesOnly) {
        index++;
      }
      if (index == Model.AllSettings.Count) {
      <span>@term.Name</span>
     } else {
      @Html.ItemDisplayLink((string)term.Name, term.ContentItem)
     }

    } else {
      @Html.ItemDisplayLink((string)term.Name, term.ContentItem)
    }
  }
  </li>
  @for (int i = 0; i < curLevel; i++) {
    @:</ul>
  }
</div>

Coordinator
Jun 27, 2011 at 3:59 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.