Skip to content

Commit

Permalink
#H5IS
Browse files Browse the repository at this point in the history
Forgot to include new endpoint in the package as I had set it up in a custom controller in my test solution 🤦‍♂️
  • Loading branch information
abjerner committed Apr 27, 2023
1 parent 6f2d463 commit 0b30208
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Web.BackOffice.Controllers;
using Umbraco.Cms.Web.Common.Attributes;
using Umbraco.Extensions;

#pragma warning disable 1591

Expand All @@ -37,23 +38,47 @@ public class RedirectsController : UmbracoAuthorizedApiController {
private readonly IContentService _contentService;
private readonly IMediaService _mediaService;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly ILocalizationService _localizationService;

#region Constructors

public RedirectsController(ILogger<RedirectsController> logger, IRedirectsService redirectsService, RedirectsBackOfficeHelper backOffice,
IContentService contentService,
IMediaService mediaService,
IUmbracoContextAccessor umbracoContextAccessor) {
IUmbracoContextAccessor umbracoContextAccessor, ILocalizationService localizationService) {
_logger = logger;
_redirects = redirectsService;
_backOffice = backOffice;
_contentService = contentService;
_mediaService = mediaService;
_umbracoContextAccessor = umbracoContextAccessor;
_localizationService = localizationService;
}

#endregion

/// <summary>
/// Returns a list of cultures for the content node with the specified <paramref name="id"/>. If the node is not vary by culture, an empty list will be returned instead.
/// </summary>
/// <param name="id">The ID of the content node.</param>
/// <returns>A list of cultures.</returns>
[HttpGet]
public object GetCultures(int id) {

var content = _umbracoContextAccessor.GetRequiredUmbracoContext().Content?.GetById(id);
if (content is null) return NotFound();

var cultures = content.Cultures;

if (cultures.Count == 1 && cultures.ContainsKey("")) return Array.Empty<object>();

return cultures.Select(x => new {
alias = x.Key,
name = _localizationService.GetLanguageByIsoCode(x.Key)?.CultureName
});

}

/// <summary>
/// Gets a list of root nodes based on the domains added to Umbraco. A root node will only be included in the
/// list once - even if it has been assigned multiple domains.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
link.url = link.url.substr(0, pos);
}
}

// Append the query and fragment to the anchor value (if specified)
link.anchor = "";
if (link.query) link.anchor = link.query;
Expand Down Expand Up @@ -136,7 +136,7 @@
// Convert our link object to something Umbraco's link picker can understand
const target = service.toUmbracoLink(link);

// Open the link picker overlay
// Open the link picker overlay
editorService.linkPicker({
size: "medium",
currentTarget: target,
Expand All @@ -151,13 +151,13 @@

// Invoke the callback (if specified)
if (callback) callback(newLink);

},
close: function () {
editorService.close();
}
});

},

addRedirect: function (options) {
Expand Down Expand Up @@ -242,10 +242,10 @@
title: "Confirm delete",
content: `Are you sure you want to delete the redirect at <strong>${options.redirect.destination.displayUrl}</strong> ?`,
submit: function() {

// Update the button state in the UI
overlay.submitButtonState = "busy";

// Delete the redirect
service.deleteRedirect(options.redirect, function () {
if (typeof options.submit === "function") {
Expand All @@ -256,7 +256,7 @@
}, function () {
overlay.submitButtonState = "error";
});

},
close: function() {
options.close(overlay);
Expand All @@ -270,7 +270,7 @@
localizationService.localize("redirects_overlayDeleteMessage", [options.redirect.destination.displayUrl], overlay.content).then(function (value) {
overlay.content = value;
});

// Open the overlay
overlayService.confirmDelete(overlay);

Expand Down Expand Up @@ -298,8 +298,8 @@

},

getCulturesByNodeId: function(id) {
return $http.get("/umbraco/api/Redirects/GetCultures?id=" + id);
getCulturesByNodeId: function (id) {
return $http.get(`${baseUrl}GetCultures?id=${id}`);
}

};
Expand Down

0 comments on commit 0b30208

Please sign in to comment.