Skip to content

Commit

Permalink
Dynamic root with culture and segment (#15287)
Browse files Browse the repository at this point in the history
* parse culture and segment for dynamic root.

* Handle new culture and segment parameters

---------

Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
  • Loading branch information
bergmania and nielslyngsoe authored Nov 22, 2023
1 parent b499660 commit 1c2602f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/Umbraco.Web.BackOffice/Controllers/EntityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -111,7 +112,8 @@ public EntityController(
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));
Expand Down Expand Up @@ -139,6 +141,7 @@ public EntityController(
_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.")]
Expand Down Expand Up @@ -183,7 +186,8 @@ public EntityController(
userService,
localizationService,
appCaches,
StaticServiceProvider.Instance.GetRequiredService<IDynamicRootService>())
StaticServiceProvider.Instance.GetRequiredService<IDynamicRootService>(),
StaticServiceProvider.Instance.GetRequiredService<IVariationContextAccessor>())
{

}
Expand Down Expand Up @@ -587,6 +591,8 @@ public class DynamicRootViewModel
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; }
}
Expand Down Expand Up @@ -617,6 +623,8 @@ public class DynamicRootViewModel
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1c2602f

Please sign in to comment.