Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm trying to update the content of a Rich Text Editor inside a blocklist using a "ContentSavingNotification"-handler `INotificationHandler
I've managed to get my hands on the content but the changes that I make are not persisted.
I looks something like this:
foreach (var entity in notification.SavedEntities) {
foreach (var property in entity.Properties) { if (property.PropertyType.PropertyEditorAlias == "Umbraco.BlockList") { string rawJson = property.GetValue().ToString(); BlockValue blockValue = JsonConvert.DeserializeObject<BlockValue>(rawJson); foreach (var column in blockValue.ContentData) { foreach (var columnProperty in column.RawPropertyValues) { // this contains other blocks var block = JsonConvert.DeserializeObject<BlockValue>(columnProperty.Value.ToString()); if (block == null) continue; foreach (var blockData in block.ContentData) { foreach (var blockProperty in blockData.RawPropertyValues) { if (blockProperty.Key == "body") { blockData.RawPropertyValues["body"] = new HtmlInputCleaner().CleanUp(blockProperty.Value.ToString()); } } } } } } }
}
Anyone that has managed to do this? I guess the process is simular for Nested Content and the Block List Editor?
Ohh... I forgot =D Any changes that I make to the object graph after DeSerializing to Json needs to be serialized back again =D
Here is a working example:
public class RichTextEditorCleanupOnSaveHandler : INotificationHandler<ContentSavingNotification> { public void Handle(ContentSavingNotification notification) { foreach (var entity in notification.SavedEntities) { foreach (var property in entity.Properties) { if (property.PropertyType.PropertyEditorAlias == "Umbraco.BlockList") { string rawJson = property.GetValue().ToString(); BlockValue blockValue = JsonConvert.DeserializeObject<BlockValue>(rawJson); foreach (var column in blockValue.ContentData) { foreach (var columnProperty in column.RawPropertyValues) { // this contains other blocks var block = JsonConvert.DeserializeObject<BlockValue>(columnProperty.Value.ToString()); if(block == null) continue; foreach (var blockData in block.ContentData) { foreach (var blockProperty in blockData.RawPropertyValues) { if (blockProperty.Key == "body") { blockData.RawPropertyValues["body"] = new HtmlInputCleaner().CleanUp(blockProperty.Value.ToString()); } } } column.RawPropertyValues[columnProperty.Key] = JsonConvert.SerializeObject(block); } } property.SetValue(JsonConvert.SerializeObject(blockValue)); } } } } }
I tried this implementation in v14.1 and got an error during the deserialization of the blocklist.
BlockValue blockValue = JsonConvert.DeserializeObject<BlockValue>(rawJson);
Is this a bug?
Try this:
var pu = _publishedContentQuery.Content(5686); IEnumerable<BlockListItem> lista = new List<BlockListItem>(); lista = (IEnumerable<BlockListItem>)pu.GetProperty("righePreventivo").GetValue(); var listaaa = lista.Select(x => x.Content);
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Update content of "Block" inside Block List on save
I'm trying to update the content of a Rich Text Editor inside a blocklist using a "ContentSavingNotification"-handler `INotificationHandler
I've managed to get my hands on the content but the changes that I make are not persisted.
I looks something like this:
foreach (var entity in notification.SavedEntities) {
}
Anyone that has managed to do this? I guess the process is simular for Nested Content and the Block List Editor?
Ohh... I forgot =D Any changes that I make to the object graph after DeSerializing to Json needs to be serialized back again =D
Here is a working example:
I tried this implementation in v14.1 and got an error during the deserialization of the blocklist.
Is this a bug?
Try this:
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.