From 1c2602f57cde996a16d3e58bf5ec95ded495dfd5 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 22 Nov 2023 19:58:06 +0100 Subject: [PATCH] Dynamic root with culture and segment (#15287) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * parse culture and segment for dynamic root. * Handle new culture and segment parameters --------- Co-authored-by: Niels Lyngsø --- .../Controllers/EntityController.cs | 12 ++++++++++-- .../src/common/resources/entity.resource.js | 6 ++++-- .../contentpicker/contentpicker.controller.js | 4 +++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Web.BackOffice/Controllers/EntityController.cs b/src/Umbraco.Web.BackOffice/Controllers/EntityController.cs index 38231740ba..f37031d841 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/EntityController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/EntityController.cs @@ -69,6 +69,7 @@ public class EntityController : UmbracoAuthorizedJsonController private readonly AppCaches _appCaches; private readonly IDynamicRootService _dynamicRootService; + private readonly IVariationContextAccessor _variationContextAccessor; private readonly IBackOfficeSecurityAccessor _backofficeSecurityAccessor; private readonly IContentService _contentService; private readonly IContentTypeService _contentTypeService; @@ -111,7 +112,8 @@ public class EntityController : UmbracoAuthorizedJsonController IUserService userService, ILocalizationService localizationService, AppCaches appCaches, - IDynamicRootService dynamicRootService) + IDynamicRootService dynamicRootService, + IVariationContextAccessor variationContextAccessor) { _treeService = treeService ?? throw new ArgumentNullException(nameof(treeService)); _treeSearcher = treeSearcher ?? throw new ArgumentNullException(nameof(treeSearcher)); @@ -139,6 +141,7 @@ public class EntityController : UmbracoAuthorizedJsonController _localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService)); _appCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches)); _dynamicRootService = dynamicRootService; + _variationContextAccessor = variationContextAccessor; } [Obsolete("Use non-obsolete ctor. This will be removed in Umbraco 14.")] @@ -183,7 +186,8 @@ public class EntityController : UmbracoAuthorizedJsonController userService, localizationService, appCaches, - StaticServiceProvider.Instance.GetRequiredService()) + StaticServiceProvider.Instance.GetRequiredService(), + StaticServiceProvider.Instance.GetRequiredService()) { } @@ -587,6 +591,8 @@ public class EntityController : UmbracoAuthorizedJsonController public DynamicRoot Query { get; set; } = null!; public int CurrentId { get; set; } + public string? CurrentCulture { get; set; } + public string? CurrentSegment { get; set; } public int ParentId { get; set; } } @@ -617,6 +623,8 @@ public class EntityController : UmbracoAuthorizedJsonController AnyOfDocTypeKeys = x.AnyOfDocTypeKeys }) }; + + _variationContextAccessor.VariationContext = new VariationContext(model.CurrentCulture, model.CurrentSegment); var startNodes = (await _dynamicRootService.GetDynamicRootsAsync(startNodeSelector)).ToArray(); Guid? first = startNodes.Any() ? startNodes.First() : null; diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js index 6e70f1dbb8..fdcc494632 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js @@ -366,7 +366,7 @@ function entityResource($q, $http, umbRequestHelper) { 'Failed to retrieve entity data for query ' + query); }, - getDynamicRoot: function (query, currentId, parentId) { + getDynamicRoot: function (query, currentId, parentId, culture, segment) { return umbRequestHelper.resourcePromise( $http.post( umbRequestHelper.getApiUrl( @@ -375,7 +375,9 @@ function entityResource($q, $http, umbRequestHelper) { { query: JSON.parse(query), parentId: parentId, - currentId: currentId + currentId: currentId, + currentCulture: culture, + currentSegment: segment }), 'Failed to retrieve entity data for query ' + query); }, diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js index 7e4ccb71e8..a6fc601d8f 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js @@ -257,11 +257,13 @@ function contentPickerController($scope, $q, $routeParams, $location, entityReso }); } else if ($scope.model.config.startNode.dynamicRoot) { + entityResource.getDynamicRoot( JSON.stringify($scope.model.config.startNode.dynamicRoot), editorState.current.id, editorState.current.parentId, - "Document" + $scope.model.culture, + $scope.model.segment ).then(function (ent) { if(ent) { dialogOptions.startNodeId = ($scope.model.config.idType === "udi" ? ent.udi : ent.id).toString();