public void Handle(ContentCopiedNotification notification) { // get the upload field properties with a value var properties = notification.Original.Properties.Where(IsUploadField); // copy files var isUpdated = false; foreach (var property in properties) { //copy each of the property values (variants, segments) to the destination foreach (var propertyValue in property.Values) { var propVal = property.GetValue(propertyValue.Culture, propertyValue.Segment); if (propVal == null || !(propVal is string str) || str.IsNullOrWhiteSpace()) { continue; } var sourcePath = _mediaFileManager.FileSystem.GetRelativePath(str); var copyPath = _mediaFileManager.CopyFile(notification.Copy, property.PropertyType, sourcePath); notification.Copy.SetValue(property.Alias, _mediaFileManager.FileSystem.GetUrl(copyPath), propertyValue.Culture, propertyValue.Segment); isUpdated = true; } } // if updated, re-save the copy with the updated value if (isUpdated) { _contentService.Save(notification.Copy); } }
/// <summary> /// After a content has been copied, also copy uploaded files. /// </summary> public void Handle(ContentCopiedNotification notification) { // get the image cropper field properties var properties = notification.Original.Properties.Where(IsCropperField); // copy files var isUpdated = false; foreach (var property in properties) { //copy each of the property values (variants, segments) to the destination by using the edited value foreach (var propertyValue in property.Values) { var propVal = property.GetValue(propertyValue.Culture, propertyValue.Segment); var src = GetFileSrcFromPropertyValue(propVal, out var jo); if (src == null) { continue; } var sourcePath = _mediaFileManager.FileSystem.GetRelativePath(src); var copyPath = _mediaFileManager.CopyFile(notification.Copy, property.PropertyType, sourcePath); jo["src"] = _mediaFileManager.FileSystem.GetUrl(copyPath); notification.Copy.SetValue(property.Alias, jo.ToString(), propertyValue.Culture, propertyValue.Segment); isUpdated = true; } } // if updated, re-save the copy with the updated value if (isUpdated) { _contentService.Save(notification.Copy); } }
/// <summary> /// After a content has been copied, also copy uploaded files. /// </summary> public void Handle(ContentCopiedNotification notification) { // get the image cropper field properties IEnumerable <IProperty> properties = notification.Original.Properties.Where(IsCropperField); // copy files var isUpdated = false; foreach (IProperty property in properties) { // copy each of the property values (variants, segments) to the destination by using the edited value foreach (IPropertyValue propertyValue in property.Values) { var propVal = property.GetValue(propertyValue.Culture, propertyValue.Segment); var src = GetFileSrcFromPropertyValue(propVal, out JObject? jo); if (src == null) { continue; } var sourcePath = _mediaFileManager.FileSystem.GetRelativePath(src); var copyPath = _mediaFileManager.CopyFile(notification.Copy, property.PropertyType, sourcePath); jo !["src"] = _mediaFileManager.FileSystem.GetUrl(copyPath);