From 28a0e0aa6f2a334116e8b657c30e00c46d2a46a3 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Wed, 11 Sep 2019 10:02:59 +0100 Subject: [PATCH] Pass through a GUID that a media picker / new folder picker will use --- .../PropertyEditors/GridPropertyEditor.cs | 13 +++++++++++-- .../PropertyEditors/RichTextPropertyEditor.cs | 12 ++++++++++-- src/Umbraco.Web/Templates/TemplateUtilities.cs | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs index 98c65175af..24ab2edbb3 100644 --- a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs @@ -8,6 +8,7 @@ using Umbraco.Core.Models.Editors; using Umbraco.Web.Templates; using Umbraco.Web.Composing; using Umbraco.Core.Services; +using System; namespace Umbraco.Web.PropertyEditors { @@ -69,6 +70,15 @@ namespace Umbraco.Web.PropertyEditors if (editorValue.Value == null) return null; + var config = editorValue.DataTypeConfiguration as RichTextConfiguration; + var mediaParent = config?.MediaParentId; + Guid mediaParentId; + + if (mediaParent == null) + mediaParentId = Guid.Empty; + else + mediaParentId = mediaParent.Guid; + // editorValue.Value is a JSON string of the grid var rawJson = editorValue.Value.ToString(); var grid = JsonConvert.DeserializeObject(rawJson); @@ -84,8 +94,7 @@ namespace Umbraco.Web.PropertyEditors var userId = Current.UmbracoContext.Security.CurrentUser.Id; - // TODO: In future task(get the parent folder from this config) to save the media into - var parsedHtml = TemplateUtilities.FindAndPersistPastedTempImages(html, -1, userId, _mediaService, _contentTypeBaseServiceProvider); + var parsedHtml = TemplateUtilities.FindAndPersistPastedTempImages(html, mediaParentId, userId, _mediaService, _contentTypeBaseServiceProvider); rte.Value = parsedHtml; } diff --git a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs index f9267315e4..3acd4bd25e 100644 --- a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs @@ -115,8 +115,16 @@ namespace Umbraco.Web.PropertyEditors var userId = Current.UmbracoContext.Security.CurrentUser.Id; - // TODO: In future task(get the parent folder from this config) to save the media into - parsed = TemplateUtilities.FindAndPersistPastedTempImages(parsed, -1, userId, _mediaService, _contentTypeBaseServiceProvider); + var config = editorValue.DataTypeConfiguration as RichTextConfiguration; + var mediaParent = config?.MediaParentId; + Guid mediaParentId; + + if (mediaParent == null) + mediaParentId = Guid.Empty; + else + mediaParentId = mediaParent.Guid; + + parsed = TemplateUtilities.FindAndPersistPastedTempImages(parsed, mediaParentId, userId, _mediaService, _contentTypeBaseServiceProvider); return parsed; } } diff --git a/src/Umbraco.Web/Templates/TemplateUtilities.cs b/src/Umbraco.Web/Templates/TemplateUtilities.cs index 5969951072..24069bcc6f 100644 --- a/src/Umbraco.Web/Templates/TemplateUtilities.cs +++ b/src/Umbraco.Web/Templates/TemplateUtilities.cs @@ -187,7 +187,7 @@ namespace Umbraco.Web.Templates // see comment in ResolveMediaFromTextString for group reference => ResolveImgPattern.Replace(text, "$1$3$4$5"); - internal static string FindAndPersistPastedTempImages(string html, int mediaParentFolder, int userId, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) + internal static string FindAndPersistPastedTempImages(string html, Guid mediaParentFolder, int userId, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) { // Find all img's that has data-tmpimg attribute // Use HTML Agility Pack - https://html-agility-pack.net