V8: Support culture variant URLs in multi URL picker (#7130)
Thanks, Kenn - great work as usual 👍
This commit is contained in:
committed by
emma burstow
parent
12e88fde42
commit
bcf4c97270
@@ -127,6 +127,25 @@ function entityResource($q, $http, umbRequestHelper) {
|
||||
'Failed to retrieve url for id:' + id);
|
||||
},
|
||||
|
||||
getUrlByUdi: function (udi, culture) {
|
||||
|
||||
if (!udi) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (!culture) {
|
||||
culture = "";
|
||||
}
|
||||
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.get(
|
||||
umbRequestHelper.getApiUrl(
|
||||
"entityApiBaseUrl",
|
||||
"GetUrl",
|
||||
[{ udi: udi }, {culture: culture }])),
|
||||
'Failed to retrieve url for UDI:' + udi);
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
* @name umbraco.resources.entityResource#getById
|
||||
@@ -166,18 +185,22 @@ function entityResource($q, $http, umbRequestHelper) {
|
||||
},
|
||||
|
||||
|
||||
getUrlAndAnchors: function (id) {
|
||||
getUrlAndAnchors: function (id, culture) {
|
||||
|
||||
if (id === -1 || id === "-1") {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!culture) {
|
||||
culture = "";
|
||||
}
|
||||
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.get(
|
||||
umbRequestHelper.getApiUrl(
|
||||
"entityApiBaseUrl",
|
||||
"GetUrlAndAnchors",
|
||||
[{ id: id }])),
|
||||
[{ id: id }, {culture: culture }])),
|
||||
'Failed to retrieve url and anchors data for id ' + id);
|
||||
},
|
||||
|
||||
|
||||
@@ -144,6 +144,16 @@ function multiUrlPickerController($scope, angularHelper, localizationService, en
|
||||
if ($scope.model.validation && $scope.model.validation.mandatory && !$scope.model.config.minNumber) {
|
||||
$scope.model.config.minNumber = 1;
|
||||
}
|
||||
|
||||
_.each($scope.model.value, function (item){
|
||||
// we must reload the "document" link URLs to match the current editor culture
|
||||
if (item.udi.indexOf("/document/") > 0) {
|
||||
item.url = null;
|
||||
entityResource.getUrlByUdi(item.udi).then(function (data) {
|
||||
item.url = data;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
@@ -206,6 +206,35 @@ namespace Umbraco.Web.Editors
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url of an entity
|
||||
/// </summary>
|
||||
/// <param name="udi">UDI of the entity to fetch URL for</param>
|
||||
/// <param name="culture">The culture to fetch the URL for</param>
|
||||
/// <returns>The URL or path to the item</returns>
|
||||
public HttpResponseMessage GetUrl(Udi udi, string culture = "*")
|
||||
{
|
||||
var intId = Services.EntityService.GetId(udi);
|
||||
if (!intId.Success)
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
UmbracoEntityTypes entityType;
|
||||
switch(udi.EntityType)
|
||||
{
|
||||
case Constants.UdiEntityType.Document:
|
||||
entityType = UmbracoEntityTypes.Document;
|
||||
break;
|
||||
case Constants.UdiEntityType.Media:
|
||||
entityType = UmbracoEntityTypes.Media;
|
||||
break;
|
||||
case Constants.UdiEntityType.Member:
|
||||
entityType = UmbracoEntityTypes.Member;
|
||||
break;
|
||||
default:
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
}
|
||||
return GetUrl(intId.Result, entityType, culture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url of an entity
|
||||
/// </summary>
|
||||
@@ -303,7 +332,9 @@ namespace Umbraco.Web.Editors
|
||||
[HttpGet]
|
||||
public UrlAndAnchors GetUrlAndAnchors(int id, string culture = "*")
|
||||
{
|
||||
var url = UmbracoContext.UrlProvider.GetUrl(id);
|
||||
culture = culture ?? ClientCulture();
|
||||
|
||||
var url = UmbracoContext.UrlProvider.GetUrl(id, culture: culture);
|
||||
var anchorValues = Services.ContentService.GetAnchorValuesFromRTEs(id, culture);
|
||||
return new UrlAndAnchors(url, anchorValues);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user