/// <summary> /// Auto-fill properties (or clear). /// </summary> private void AutoFillProperties(IContentBase model) { var properties = model.Properties.Where(IsUploadField); foreach (var property in properties) { var autoFillConfig = _contentSection.GetConfig(property.Alias); if (autoFillConfig == null) { continue; } foreach (var pvalue in property.Values) { var svalue = property.GetValue(pvalue.Culture, pvalue.Segment) as string; if (string.IsNullOrWhiteSpace(svalue)) { _uploadAutoFillProperties.Reset(model, autoFillConfig, pvalue.Culture, pvalue.Segment); } else { _uploadAutoFillProperties.Populate(model, autoFillConfig, _mediaFileSystem.GetRelativePath(svalue), pvalue.Culture, pvalue.Segment); } } } }
/// <summary> /// Auto-fill properties (or clear). /// </summary> private void AutoFillProperties(IContentBase model) { var properties = model.Properties.Where(IsCropperField); foreach (var property in properties) { var autoFillConfig = _contentSettings.GetConfig(property.Alias); if (autoFillConfig == null) { continue; } foreach (var pvalue in property.Values) { var svalue = property.GetValue(pvalue.Culture, pvalue.Segment) as string; if (string.IsNullOrWhiteSpace(svalue)) { _autoFillProperties.Reset(model, autoFillConfig, pvalue.Culture, pvalue.Segment); } else { var jo = GetJObject(svalue, false); string src; if (jo == null) { // so we have a non-empty string value that cannot be parsed into a json object // see http://issues.umbraco.org/issue/U4-4756 // it can happen when an image is uploaded via the folder browser, in which case // the property value will be the file source eg '/media/23454/hello.jpg' and we // are fixing that anomaly here - does not make any sense at all but... bah... var dt = _dataTypeService.GetDataType(property.PropertyType.DataTypeId); var config = dt?.ConfigurationAs <ImageCropperConfiguration>(); src = svalue; var json = new { src = svalue, crops = config == null?Array.Empty <ImageCropperConfiguration.Crop>() : config.Crops }; property.SetValue(JsonConvert.SerializeObject(json), pvalue.Culture, pvalue.Segment); } else { src = jo["src"]?.Value <string>(); } if (src == null) { _autoFillProperties.Reset(model, autoFillConfig, pvalue.Culture, pvalue.Segment); } else { _autoFillProperties.Populate(model, autoFillConfig, _mediaFileSystem.GetRelativePath(src), pvalue.Culture, pvalue.Segment); } } } } }