Pass through a GUID that a media picker / new folder picker will use

This commit is contained in:
Warren Buckley
2019-09-11 10:02:59 +01:00
parent 6de4bbbae6
commit 28a0e0aa6f
3 changed files with 22 additions and 5 deletions

View File

@@ -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<GridValue>(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;
}

View File

@@ -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;
}
}

View File

@@ -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