Lots of little changes between V7 and V8 in terms of syntax, I'm not fully sure of the context of what you are trying to achieve, and there are big changes to how PreValue configuration is handled in V8, but the following is the output of taking what you had and fixing it up to build in V8, with notes about the PreValues thing...
using System.Linq;
using System.Net;
using System.Web.Http;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web;
using Umbraco.Web.Editors;
using Umbraco.Web.Mvc;
namespace umbraco_8_1_release.Controllers
{
[PluginController("DataTypeApi")]
public class DataTypeSettingsController : UmbracoAuthorizedJsonController
{
[HttpGet]
public long? GetFacebookAppId(int pageId)
{
IPublishedContent currentPage = Umbraco.Content(pageId);
IPublishedContent homePage = currentPage.Ancestors().Where(q => q.ContentType.Alias == "dtHome").FirstOrDefault();
IPublishedContent siteSettings = homePage.Children.Where(q => q.ContentType.Alias == "dtSiteSettings").FirstOrDefault();
if (siteSettings != null)
{
return siteSettings.HasValue("ssAppId") ? siteSettings.Value<long?>("ssAppId").Value : 0;
}
return 0;
}
[HttpGet]
public object GetDataTypeById(int id)
{
var dtd = Services.DataTypeService.GetDataType(id);
return this.FormatDataType(dtd);
}
[HttpGet]
public object GetDataTypeByAlias(string alias)
{
string correctName = alias.Replace("_", " ");
var dtd = Services.DataTypeService.GetDataType(correctName);
return this.FormatDataType(dtd);
}
protected object FormatDataType(IDataType dtd)
{
if (dtd == null)
{
throw new HttpResponseException(HttpStatusCode.GatewayTimeout);
}
var propertyEditorAlias = dtd.Editor.Alias;
//PropertyEditorResolver has been removed
// var propEditor = PropertyEditorResolver.Current.GetByAlias(dtd.Editor.Alias);
//var preValues = Services.DataTypeService.GetPreValuesCollectionByDataTypeId(dtd.Id);
// var convertedPreValues = propEditor.PreValueEditor.ConvertDbToEditor(propEditor.DefaultPreValues, preValues);
// in the Umbraco source it seems in PropertyValueConverters that there is a strongly typed object for each editor's configuraiton
// that gives you access to PreValues
//for example for Slider property editor:
var configuration = dtd.ConfigurationAs<SliderConfiguration>();
configuration.InitialValue = 12.5M;
//although there is also a DefaultConfiguration here:
var defaultConfig = dtd.Editor.DefaultConfiguration;
//there is a method to get the ValueEditor and therefore the 'view'
var valueEditor = dtd.Editor.GetValueEditor();
return new
{
Guid = dtd.Key,
PropertyEditorAlias = dtd.Editor.Alias,
// not sure what you want to return here?
//PreValues = convertedPreValues,
View = valueEditor.View
};
}
}
}
... but caveated with the fact I've never had to do anything like this! - but hopefully this steers you on your way, on getting the UmbracoAuthorizedJsonController to work!
UmbracoAuthorizedJsonController not working in V8
Does anyone know how to get this bit of V7 code to work in Version 8?
Hi Jonathan
Lots of little changes between V7 and V8 in terms of syntax, I'm not fully sure of the context of what you are trying to achieve, and there are big changes to how PreValue configuration is handled in V8, but the following is the output of taking what you had and fixing it up to build in V8, with notes about the PreValues thing...
... but caveated with the fact I've never had to do anything like this! - but hopefully this steers you on your way, on getting the UmbracoAuthorizedJsonController to work!
regards
Marc
Hi, This is great - thank you so much for all your help,
Jon
Hi!
By any chance have you discovered how to get the prevalues?
Thank you
S
is working on a reply...