/// <summary> /// Format the data for persistence /// This to ensure if a RTE is used in a Grid cell/control that we parse it for tmp stored images /// to persist to the media library when we go to persist this to the DB /// </summary> /// <param name="editorValue"></param> /// <param name="currentValue"></param> /// <returns></returns> public override object FromEditor(ContentPropertyData editorValue, object currentValue) { if (editorValue.Value == null) { return(null); } // editorValue.Value is a JSON string of the grid var rawJson = editorValue.Value.ToString(); if (rawJson.IsNullOrWhiteSpace()) { return(null); } var config = editorValue.DataTypeConfiguration as GridConfiguration; var mediaParent = config?.MediaParentId; var mediaParentId = mediaParent == null ? Guid.Empty : mediaParent.Guid; var grid = DeserializeGridValue(rawJson, out var rtes); var userId = _umbracoContextAccessor.UmbracoContext?.Security?.CurrentUser?.Id ?? Constants.Security.SuperUserId; // Process the rte values foreach (var rte in rtes) { // Parse the HTML var html = rte.Value?.ToString(); var parseAndSavedTempImages = TemplateUtilities.FindAndPersistPastedTempImages(html, mediaParentId, userId, _mediaService, _contentTypeBaseServiceProvider, _logger); var editorValueWithMediaUrlsRemoved = TemplateUtilities.RemoveMediaUrlsFromTextString(parseAndSavedTempImages); rte.Value = editorValueWithMediaUrlsRemoved; } // Convert back to raw JSON for persisting return(JsonConvert.SerializeObject(grid)); }