Dynamic root with culture and segment (#15287)

* parse culture and segment for dynamic root.

* Handle new culture and segment parameters

---------

Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
This commit is contained in:
Bjarke Berg
2023-11-22 19:58:06 +01:00
committed by GitHub
parent b499660101
commit 1c2602f57c
3 changed files with 17 additions and 5 deletions

View File

@@ -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<IDynamicRootService>())
StaticServiceProvider.Instance.GetRequiredService<IDynamicRootService>(),
StaticServiceProvider.Instance.GetRequiredService<IVariationContextAccessor>())
{
}
@@ -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;

View File

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

View File

@@ -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();