2sxc:如何获取 "ContentType Fields"/特定输入类型/属性 值
2sxc : How-To Get "ContentType Fields" / input-type specific / property value
我正在尝试获取内容类型字段的 "RowCount" 值。
- 使用我的代码,我可以列出所有应用程序内容类型
- 我可以列出所有具有基本属性(名称、标签、默认值...)的字段
但现在我几乎一整天都在尝试访问额外的输入类型特定值,但没有运气......
这是我当前的带有注释的代码,我想在其中获取额外的值..
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;
}
如果您不对 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
我正在尝试获取内容类型字段的 "RowCount" 值。
- 使用我的代码,我可以列出所有应用程序内容类型
- 我可以列出所有具有基本属性(名称、标签、默认值...)的字段
但现在我几乎一整天都在尝试访问额外的输入类型特定值,但没有运气......
这是我当前的带有注释的代码,我想在其中获取额外的值..
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;
}
如果您不对 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