Search code examples
dotnetnuke-module2sxc

2sxc : How-To Get "ContentType Fields" / input-type specific / property value


I am trying to get "RowCount" value for Content-Type Field.

  • With my code I can list all application Content-Types
  • Than I can list all fields with basic attributes (Name, Label, DefaultValue...)

But now I am trying almost full day to access additional input-type specific values, but with no luck...

This is my current code with comment where I like to get additional values..

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;
}

Solution

  • If you don't use foreach for AttributeDefinitions you can get all data this way:

            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);
    

    You can get staticName from code in question:

    t.StaticName