2016-08-03 23 views
0

我想獲得內容類型字段的「RowCount」值。2sxc:如何獲得「ContentType字段」/輸入類型特定/屬性值

  • 我的代碼,我可以列出所有應用程序的內容類型
  • 比我可以列出基本屬性的所有字段(名稱,標籤,默認值...)

但現在我想幾乎整整一天訪問額外的輸入型具體數值,但沒有運氣...

這是我當前的代碼以我喜歡那裏獲得額外的價值評論..

public string GetTablesAndFields(){ 
    var cache = ToSic.Eav.DataSource.GetCache(null, App.AppId) as ToSic.Eav.DataSources.Caches.BaseCache; 
    var allTypes = cache.GetContentTypes().Select(t => t.Value); 
    var appTypes = allTypes.Where(t => t.Scope == "2SexyContent").ToList(); 

    var zoneId=(int)ToSic.SexyContent.Internal.ZoneHelpers.GetZoneID(Dnn.Module.PortalID); 
    var metaDataSource = ToSic.Eav.DataSource.GetMetaDataSource(zoneId, App.AppId); 

    var code =""; 
    foreach(ToSic.Eav.Data.ContentType t in appTypes){ 
     code = code + t.Name + " | " + t.Scope + " | fields : " + t.AttributeDefinitions.Count + "<br/>"; 
     foreach(var a in t.AttributeDefinitions){ 
      var f = GetFieldMetadata(metaDataSource, a.Key); 

      code += "<hr><pre>"; 
      code += "# Name    #" + a.Value.Name + "<br/>"; 
      code += "# Name Label   #" + f.Title[0] + "<br/>"; 
      code += "# Visible in Edit UI #" + f.Attributes["VisibleInEditUI"][0] + "<br/>"; 
      code += "# Default value  #" + f.Attributes["DefaultValue"][0] + "<br/>"; 
      code += "# Required   #" + f.Attributes["Required"][0] + "<br/>"; 
      code += "# Disabled   #" + f.Attributes["Disabled"][0] + "<br/>"; 
      code += "# Input Type   #" + f.Attributes["InputType"][0] + "<br/>"; 
      code += "# Notes    #" + f.Attributes["Notes"][0] + "<br/>"; 
      code += "# Validation   #" + f.Attributes["ValidationRegExJavaScript"][0] + "<br/>"; 
      code += "</pre><hr>"; 

      // How to access "RowCount" or other InputType specific values? 
     } 
    } 
    return code; 
} 

回答

0

如果不使用AttributeDefinitions的foreach 你可以用這種方式獲得的所有數據:

 ToSic.Eav.WebApi.ContentTypeController eavCtc; 
     eavCtc = new ToSic.Eav.WebApi.ContentTypeController(); 
     eavCtc.SetUser(ToSic.SexyContent.Environment.Dnn7.UserIdentity.CurrentUserIdentityToken); 
     var fields = eavCtc.GetFields(App.AppId, staticName); 

您可以從代碼中的問題得到staticName:

t.StaticName