/// <inheritdoc /> public IEnumerable <ValidationResult> ValidatePropertyValue( IPropertyType propertyType, object?postedValue) { if (propertyType is null) { throw new ArgumentNullException(nameof(propertyType)); } IDataType?dataType = _dataTypeService.GetDataType(propertyType.DataTypeId); if (dataType == null) { throw new InvalidOperationException("No data type found by id " + propertyType.DataTypeId); } IDataEditor?editor = _propertyEditors[propertyType.PropertyEditorAlias]; if (editor == null) { throw new InvalidOperationException("No property editor found by alias " + propertyType.PropertyEditorAlias); } return(ValidatePropertyValue(editor, dataType, postedValue, propertyType.Mandatory, propertyType.ValidationRegExp, propertyType.MandatoryMessage, propertyType.ValidationRegExpMessage)); }
private void MapConfigurationFields(IDataType?dataType, List <DataTypeConfigurationFieldDisplay> fields, IDictionary <string, object>?configuration) { if (fields == null) { throw new ArgumentNullException(nameof(fields)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } // now we need to wire up the pre-values values with the actual fields defined foreach (var field in fields.ToList()) { //filter out the not-supported pre-values for built-in data types if (dataType != null && dataType.IsBuildInDataType() && (field.Key?.InvariantEquals(Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes) ?? false)) { fields.Remove(field); continue; } if (field.Key is not null && configuration.TryGetValue(field.Key, out var value)) { field.Value = value; }
/// <summary> /// This is called to merge in the prevalue crops with the value that is saved - similar to the property value /// converter for the front-end /// </summary> public override object?ToEditor(IProperty property, string?culture = null, string?segment = null) { var val = property.GetValue(culture, segment); if (val == null) { return(null); } ImageCropperValue?value; try { value = JsonConvert.DeserializeObject <ImageCropperValue>(val.ToString() !); } catch { value = new ImageCropperValue { Src = val.ToString() }; } IDataType?dataType = _dataTypeService.GetDataType(property.PropertyType.DataTypeId); if (dataType?.Configuration != null) { value?.ApplyConfiguration(dataType.ConfigurationAs <ImageCropperConfiguration>()); } return(value); }
/// <summary> /// Gets a <see cref="IDataType"/> by its Name /// </summary> /// <param name="name">Name of the <see cref="IDataType"/></param> /// <returns><see cref="IDataType"/></returns> public IDataType?GetDataType(string name) { using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true); IDataType?dataType = _dataTypeRepository.Get(Query <IDataType>().Where(x => x.Name == name))?.FirstOrDefault(); ConvertMissingEditorOfDataTypeToLabel(dataType); return(dataType); }
/// <summary> /// Gets a <see cref="IDataType"/> by its Id /// </summary> /// <param name="id">Id of the <see cref="IDataType"/></param> /// <returns><see cref="IDataType"/></returns> public IDataType?GetDataType(int id) { using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true); IDataType?dataType = _dataTypeRepository.Get(id); ConvertMissingEditorOfDataTypeToLabel(dataType); return(dataType); }
/// <summary> /// Gets a <see cref="IDataType"/> by its unique guid Id /// </summary> /// <param name="id">Unique guid Id of the DataType</param> /// <returns><see cref="IDataType"/></returns> public IDataType?GetDataType(Guid id) { using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true); IQuery <IDataType> query = Query <IDataType>().Where(x => x.Key == id); IDataType? dataType = _dataTypeRepository.Get(query).FirstOrDefault(); ConvertMissingEditorOfDataTypeToLabel(dataType); return(dataType); }
private void ConvertMissingEditorOfDataTypeToLabel(IDataType? dataType) { if (dataType == null) { return; } ConvertMissingEditorsOfDataTypesToLabels(new[] { dataType }); }
public void DefineMaps(IUmbracoMapper mapper) { mapper.Define <DocumentTypeSave, IContentType>( (source, context) => new ContentType(_shortStringHelper, source.ParentId), Map); mapper.Define <MediaTypeSave, IMediaType>( (source, context) => new MediaType(_shortStringHelper, source.ParentId), Map); mapper.Define <MemberTypeSave, IMemberType>( (source, context) => new MemberType(_shortStringHelper, source.ParentId), Map); mapper.Define <IContentType, DocumentTypeDisplay>((source, context) => new DocumentTypeDisplay(), Map); mapper.Define <IMediaType, MediaTypeDisplay>((source, context) => new MediaTypeDisplay(), Map); mapper.Define <IMemberType, MemberTypeDisplay>((source, context) => new MemberTypeDisplay(), Map); mapper.Define <PropertyTypeBasic, IPropertyType>( (source, context) => { IDataType?dataType = _dataTypeService.GetDataType(source.DataTypeId); if (dataType == null) { throw new NullReferenceException("No data type found with id " + source.DataTypeId); } return(new PropertyType(_shortStringHelper, dataType, source.Alias)); }, Map); // TODO: isPublishing in ctor? mapper.Define <PropertyGroupBasic <PropertyTypeBasic>, PropertyGroup>( (source, context) => new PropertyGroup(false), Map); mapper.Define <PropertyGroupBasic <MemberPropertyTypeBasic>, PropertyGroup>( (source, context) => new PropertyGroup(false), Map); mapper.Define <IContentTypeComposition, ContentTypeBasic>((source, context) => new ContentTypeBasic(), Map); mapper.Define <IContentType, ContentTypeBasic>((source, context) => new ContentTypeBasic(), Map); mapper.Define <IMediaType, ContentTypeBasic>((source, context) => new ContentTypeBasic(), Map); mapper.Define <IMemberType, ContentTypeBasic>((source, context) => new ContentTypeBasic(), Map); mapper.Define <DocumentTypeSave, DocumentTypeDisplay>((source, context) => new DocumentTypeDisplay(), Map); mapper.Define <MediaTypeSave, MediaTypeDisplay>((source, context) => new MediaTypeDisplay(), Map); mapper.Define <MemberTypeSave, MemberTypeDisplay>((source, context) => new MemberTypeDisplay(), Map); mapper.Define <PropertyGroupBasic <PropertyTypeBasic>, PropertyGroupDisplay <PropertyTypeDisplay> >( (source, context) => new PropertyGroupDisplay <PropertyTypeDisplay>(), Map); mapper.Define <PropertyGroupBasic <MemberPropertyTypeBasic>, PropertyGroupDisplay <MemberPropertyTypeDisplay> >( (source, context) => new PropertyGroupDisplay <MemberPropertyTypeDisplay>(), Map); mapper.Define <PropertyTypeBasic, PropertyTypeDisplay>((source, context) => new PropertyTypeDisplay(), Map); mapper.Define <MemberPropertyTypeBasic, MemberPropertyTypeDisplay>( (source, context) => new MemberPropertyTypeDisplay(), Map); }
public static bool IsDataTypeIgnoringUserStartNodes(this IDataTypeService dataTypeService, Guid key) { if (DataTypeExtensions.IsBuildInDataType(key)) { return(false); // built in ones can never be ignoring start nodes } IDataType?dataType = dataTypeService.GetDataType(key); if (dataType != null && dataType.Configuration is IIgnoreUserStartNodesConfig ignoreStartNodesConfig) { return(ignoreStartNodesConfig.IgnoreUserStartNodes); } return(false); }
private IEnumerable <XElement> SerializePropertyTypes( IEnumerable <IPropertyType> propertyTypes, IEnumerable <PropertyGroup> propertyGroups) { foreach (IPropertyType propertyType in propertyTypes) { IDataType?definition = _dataTypeService.GetDataType(propertyType.DataTypeId); PropertyGroup?propertyGroup = propertyType.PropertyGroupId == null // true generic property ? null : propertyGroups.FirstOrDefault(x => x.Id == propertyType.PropertyGroupId.Value); XElement genericProperty = SerializePropertyType(propertyType, definition, propertyGroup); genericProperty.Add(new XElement("Variations", propertyType.Variations.ToString())); yield return(genericProperty); } }
public override object ToEditor(IProperty property, string?culture = null, string?segment = null) { var value = property.GetValue(culture, segment); var dtos = Deserialize(_jsonSerializer, value).ToList(); IDataType?dataType = _dataTypeService.GetDataType(property.PropertyType.DataTypeId); if (dataType?.Configuration != null) { MediaPicker3Configuration?configuration = dataType.ConfigurationAs <MediaPicker3Configuration>(); foreach (MediaWithCropsDto dto in dtos) { dto.ApplyConfiguration(configuration); } } return(dtos); }
public ActionResult <ContentPropertyDisplay> GetPropertyTypeScaffold(int id) { IDataType?dataTypeDiff = _dataTypeService.GetDataType(id); if (dataTypeDiff == null) { return(NotFound()); } var configuration = _dataTypeService.GetDataType(id)?.Configuration; IDataEditor?editor = _propertyEditors[dataTypeDiff.EditorAlias]; return(new ContentPropertyDisplay { Editor = dataTypeDiff.EditorAlias, Validation = new PropertyTypeValidation(), View = editor?.GetValueEditor().View, Config = editor?.GetConfigurationEditor().ToConfigurationEditor(configuration) }); }
private void PackageDataTypes(PackageDefinition definition, XContainer root) { var dataTypes = new XElement("DataTypes"); foreach (var dtId in definition.DataTypes) { if (!int.TryParse(dtId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var outInt)) { continue; } IDataType?dataType = _dataTypeService.GetDataType(outInt); if (dataType == null) { continue; } dataTypes.Add(_serializer.Serialize(dataType)); } root.Add(dataTypes); }
private IEnumerable <TPropertyType> MapProperties( IEnumerable <IPropertyType>?properties, IContentTypeBase contentType, int groupId, bool inherited) { var mappedProperties = new List <TPropertyType>(); foreach (IPropertyType p in properties?.Where(x => x.DataTypeId != 0).OrderBy(x => x.SortOrder) ?? Enumerable.Empty <IPropertyType>()) { var propertyEditorAlias = p.PropertyEditorAlias; IDataEditor?propertyEditor = _propertyEditors[propertyEditorAlias]; IDataType? dataType = _dataTypeService.GetDataType(p.DataTypeId); // fixme: Don't explode if we can't find this, log an error and change this to a label if (propertyEditor == null) { _logger.LogError( "No property editor could be resolved with the alias: {PropertyEditorAlias}, defaulting to label", p.PropertyEditorAlias); propertyEditorAlias = Constants.PropertyEditors.Aliases.Label; propertyEditor = _propertyEditors[propertyEditorAlias]; } IDictionary <string, object>?config = propertyEditor is null || dataType is null ? new Dictionary <string, object>() : dataType.Editor?.GetConfigurationEditor().ToConfigurationEditor(dataType.Configuration); mappedProperties.Add(new TPropertyType { Id = p.Id, Alias = p.Alias, Description = p.Description, LabelOnTop = p.LabelOnTop, Editor = p.PropertyEditorAlias, Validation = new PropertyTypeValidation { Mandatory = p.Mandatory, MandatoryMessage = p.MandatoryMessage, Pattern = p.ValidationRegExp, PatternMessage = p.ValidationRegExpMessage, }, Label = p.Name, View = propertyEditor?.GetValueEditor().View, Config = config, // Value = "", GroupId = groupId, Inherited = inherited, DataTypeId = p.DataTypeId, DataTypeKey = p.DataTypeKey, DataTypeName = dataType?.Name, DataTypeIcon = propertyEditor?.Icon, SortOrder = p.SortOrder, ContentTypeId = contentType.Id, ContentTypeName = contentType.Name, AllowCultureVariant = p.VariesByCulture(), AllowSegmentVariant = p.VariesBySegment(), }); } return(mappedProperties); }
private XElement SerializePropertyType(IPropertyType propertyType, IDataType?definition, PropertyGroup?propertyGroup) => new(
public CheckedParameter(Token identifier, IDataType?dataType) { Identifier = identifier; DataType = dataType; }
// note: there is NO variant support here /// <summary> /// Ensure that sub-editor values are translated through their ToEditor methods /// </summary> /// <param name="property"></param> /// <param name="dataTypeService"></param> /// <param name="culture"></param> /// <param name="segment"></param> /// <returns></returns> public override object ToEditor(IProperty property, string?culture = null, string?segment = null) { var val = property.GetValue(culture, segment); var valEditors = new Dictionary <int, IDataValueEditor>(); BlockEditorData?blockEditorData; try { blockEditorData = _blockEditorValues.DeserializeAndClean(val); } catch (JsonSerializationException) { // if this occurs it means the data is invalid, shouldn't happen but has happened if we change the data format. return(string.Empty); } if (blockEditorData == null) { return(string.Empty); } void MapBlockItemData(List <BlockItemData> items) { foreach (BlockItemData row in items) { foreach (KeyValuePair <string, BlockItemData.BlockPropertyValue> prop in row.PropertyValues) { // create a temp property with the value // - force it to be culture invariant as the block editor can't handle culture variant element properties prop.Value.PropertyType.Variations = ContentVariation.Nothing; var tempProp = new Property(prop.Value.PropertyType); tempProp.SetValue(prop.Value.Value); IDataEditor?propEditor = _propertyEditors[prop.Value.PropertyType.PropertyEditorAlias]; if (propEditor == null) { // NOTE: This logic was borrowed from Nested Content and I'm unsure why it exists. // if the property editor doesn't exist I think everything will break anyways? // update the raw value since this is what will get serialized out row.RawPropertyValues[prop.Key] = tempProp.GetValue()?.ToString(); continue; } IDataType?dataType = _dataTypeService.GetDataType(prop.Value.PropertyType.DataTypeId); if (dataType == null) { // deal with weird situations by ignoring them (no comment) row.PropertyValues.Remove(prop.Key); _logger.LogWarning( "ToEditor removed property value {PropertyKey} in row {RowId} for property type {PropertyTypeAlias}", prop.Key, row.Key, property.PropertyType.Alias); continue; } if (!valEditors.TryGetValue(dataType.Id, out IDataValueEditor? valEditor)) { var tempConfig = dataType.Configuration; valEditor = propEditor.GetValueEditor(tempConfig); valEditors.Add(dataType.Id, valEditor); } var convValue = valEditor.ToEditor(tempProp); // update the raw value since this is what will get serialized out row.RawPropertyValues[prop.Key] = convValue; } } } MapBlockItemData(blockEditorData.BlockValue.ContentData); MapBlockItemData(blockEditorData.BlockValue.SettingsData); // return json convertable object return(blockEditorData.BlockValue); }
public static ContentApp CreateContentApp( IDataTypeService dataTypeService, PropertyEditorCollection propertyEditors, string entityType, string contentTypeAlias, int defaultListViewDataType) { if (dataTypeService == null) { throw new ArgumentNullException(nameof(dataTypeService)); } if (propertyEditors == null) { throw new ArgumentNullException(nameof(propertyEditors)); } if (string.IsNullOrWhiteSpace(entityType)) { throw new ArgumentException("message", nameof(entityType)); } if (string.IsNullOrWhiteSpace(contentTypeAlias)) { throw new ArgumentException("message", nameof(contentTypeAlias)); } if (defaultListViewDataType == default) { throw new ArgumentException("defaultListViewDataType", nameof(defaultListViewDataType)); } var contentApp = new ContentApp { Alias = "umbListView", Name = "Child items", Icon = "icon-list", View = "views/content/apps/listview/listview.html", Weight = Weight, }; var customDtdName = Constants.Conventions.DataTypes.ListViewPrefix + contentTypeAlias; // first try to get the custom one if there is one IDataType?dt = dataTypeService.GetDataType(customDtdName) ?? dataTypeService.GetDataType(defaultListViewDataType); if (dt == null) { throw new InvalidOperationException( "No list view data type was found for this document type, ensure that the default list view data types exists and/or that your custom list view data type exists"); } IDataEditor?editor = propertyEditors[dt.EditorAlias]; if (editor == null) { throw new NullReferenceException("The property editor with alias " + dt.EditorAlias + " does not exist"); } IDictionary <string, object?> listViewConfig = editor.GetConfigurationEditor().ToConfigurationEditorNullable(dt.Configuration); // add the entity type to the config listViewConfig["entityType"] = entityType; // Override Tab Label if tabName is provided if (listViewConfig.ContainsKey("tabName")) { var configTabName = listViewConfig["tabName"]; if (string.IsNullOrWhiteSpace(configTabName?.ToString()) == false) { contentApp.Name = configTabName.ToString(); } } // Override Icon if icon is provided if (listViewConfig.ContainsKey("icon")) { var configIcon = listViewConfig["icon"]; if (string.IsNullOrWhiteSpace(configIcon?.ToString()) == false) { contentApp.Icon = configIcon.ToString(); } } // if the list view is configured to show umbContent first, update the list view content app weight accordingly if (listViewConfig.ContainsKey("showContentFirst") && listViewConfig["showContentFirst"]?.ToString().TryConvertTo <bool>().Result == true) { contentApp.Weight = ContentEditorContentAppFactory.Weight + 1; } // This is the view model used for the list view app contentApp.ViewModel = new List <ContentPropertyDisplay> { new() { Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}containerView", Label = string.Empty, Value = null, View = editor.GetValueEditor().View, HideLabel = true, ConfigNullable = listViewConfig, }, }; return(contentApp); }