New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort domains (Culture and Hostnames) #8316
Sort domains (Culture and Hostnames) #8316
Conversation
…out DomainFactory
@@ -19,6 +19,7 @@ protected override void DefineMaps() | |||
DefineMap<UmbracoDomain, DomainDto>(nameof(UmbracoDomain.RootContentId), nameof(DomainDto.RootStructureId)); | |||
DefineMap<UmbracoDomain, DomainDto>(nameof(UmbracoDomain.LanguageId), nameof(DomainDto.DefaultLanguage)); | |||
DefineMap<UmbracoDomain, DomainDto>(nameof(UmbracoDomain.DomainName), nameof(DomainDto.DomainName)); | |||
DefineMap<UmbracoDomain, DomainDto>(nameof(UmbracoDomain.SortOrder), nameof(DomainDto.SortOrder)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure where this mapper gets used, so I've just added the additional map for the SortOrder
property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a mapper can be used instead of the factory methods, but I can't find documentation about the differences (most factories in Umbraco.Core.Persistence.Factories
also have a mapper in Umbraco.Core.Persistence.Mappers
).
src/Umbraco.Core/Migrations/Upgrade/V_8_8_0/AddDomainSortOrder.cs
Outdated
Show resolved
Hide resolved
src/Umbraco.Core/Migrations/Upgrade/V_8_8_0/AddDomainSortOrder.cs
Outdated
Show resolved
Hide resolved
/// <summary> | ||
/// Gets the sort order. | ||
/// </summary> | ||
/// <value> | ||
/// The sort order. | ||
/// </value> | ||
public int SortOrder { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Domain
model (used in IDomainCache
) also requires a sort order, as the cache doesn't keep the order of the collections.
var domainsAndUris = domains | ||
.Where(d => d.IsWildcard == false) | ||
.Select(d => new DomainAndUri(d, uri)) | ||
.OrderByDescending(d => d.Uri.ToString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ordering by URL is only required for SelectByBase()
, so more specific URLs get matched first and therefore removed here to keep the correct domain sort order.
The changes in |
…igration to Umbraco 8.12.0
…igration to Umbraco 8.16.0
@nul800sebastiaan I've merged the latest changes from Although this PR adds a new property on the This feature allows changing the primary domain that's returned when generating URLs (if the current request isn't associated to a domain): But I recon the best thing about this would be to allow changing the order of a language dropdown for culture variant content: In its most simplistic form, this could be achieved using the following code (inside the master template): @foreach (var domain in UmbracoContext.PublishedSnapshot.Domains.GetAssigned(Model.Root().Id))
{
<a href="@Model.Url(domain.Culture.Name)">@domain.Culture.DisplayName</a>
} A more concise way would be to use the domain from the current request (and only fall-back to the root node ID when not found) and check whether the culture is actually published for that content. I would recommend adding this code in a child action of a surface controller, populate a view model and render this using a partial view. This code would then be something like this: @{
var currentPage = Model; // Only this variable and the UmbracoContext are required for the following code
var rootId = UmbracoContext.PublishedRequest.HasDomain ? UmbracoContext.PublishedRequest.Domain.ContentId : currentPage.Root().Id;
foreach (var domain in UmbracoContext.PublishedSnapshot.Domains.GetAssigned(rootId))
{
var culture = domain.Culture.Name;
string url;
if (currentPage.IsPublished(culture))
{
// Use the URL of the current page in the requested culture
url = currentPage.Url(culture);
}
else if (currentPage.Id != rootId && UmbracoContext.PublishedSnapshot.Content.GetById(rootId) is IPublishedContent root && root.IsPublished(culture))
{
// Fallback to the root page, so even if the current page isn't available in the requested culture, we can switch to this culture
url = root.Url(culture);
}
else
{
// Both the current and root page aren't published in the requested culture
continue;
}
// Do something with the URL
<a class="nav-link" href="@url">@domain.Culture.DisplayName</a>
}
} |
@ronaldbarendse @nul800sebastiaan is this something that is planned to include in any near future? 🙈 |
Hi there @ronaldbarendse! Thanks so much for your contribution! We wanted to let you know that we love the content! Unfortunately, we have spent some time looking at the open PRs for the last minor release of Umbraco 8 and we have decided that while the work is great, we have decided not to merge this. We hope to make 8.18 an umbazing release so we took the time to assess each contribution during our CMS workshop. If you would like to know a little more about that process, take a look at this article. We would, however, be super happy to merge this into Umbraco 9. If you would be happy to take a look at how you could adapt this for Umbraco 9, please raise a PR and we'll take a look! For info on how to get started with Umbraco 9, check out these docs. In the meantime, a big #H5YR goes out to you for your fine work here. Thanks, from your friendly Umbraco GitHub bot 🤖 🙂 |
Prerequisites
If there's an existing issue for this PR then this fixes #8299.
Description
Domain service and repository (database)
I've started creating all the necessary plumbing to allow sorting domains (set under 'Culture and Hostnames'):
SortOrder
property to the service level models (IDomain
andUmbracoDomain
) and database model (DomainDto
);sortOrder
column toumbracoDomain
and setting initial values in a migration;Sort
method toDomainService
(similar to those on other services);As per #8299 (comment), I've ensured to limit breaking changes to repository/service interfaces and have only done additions to them.
These changes can be tested by following these steps:
en-US
);umbracoDomain
table should have the additionalsortOrder
column with initial sort orders.Inherit
and back to a language.Sorting domains in back-office
Next up is updating the
ContentController
and UI to allow re-ordering/sorting the domains. This is done by keeping track of the saved domains and sort them according to the view model that's made sort-able:Ensuring sorting is honoured within Umbraco
The last step is to make sure the sorting is honoured where needed. For now, I've ensured the
DomainCache
andDomainUtilities
keeps the correct sort order. BecauseDefaultUrlProvider
depends on these classes, it should return URLs in the correct order/with the first domain. CustomIUrlProvider
s might return the URLs in a different order though, but that's out of this PRs scope.