-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move ContentCulturePicker logic back to driver for easier shape overr…
…ide (#16230)
- Loading branch information
Showing
2 changed files
with
33 additions
and
23 deletions.
There are no files selected for viewing
33 changes: 30 additions & 3 deletions
33
...odules/OrchardCore.ContentLocalization/Drivers/ContentCulturePickerNavbarDisplayDriver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,41 @@ | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Localization; | ||
using OrchardCore.Admin.Models; | ||
using OrchardCore.ContentLocalization.ViewModels; | ||
using OrchardCore.DisplayManagement.Handlers; | ||
using OrchardCore.DisplayManagement.Views; | ||
using OrchardCore.Localization; | ||
|
||
namespace OrchardCore.ContentLocalization.Drivers; | ||
|
||
public class ContentCulturePickerNavbarDisplayDriver : DisplayDriver<Navbar> | ||
{ | ||
public override IDisplayResult Display(Navbar model) | ||
private readonly IHttpContextAccessor _httpContextAccessor; | ||
private readonly ILocalizationService _localizationService; | ||
|
||
public ContentCulturePickerNavbarDisplayDriver( | ||
IHttpContextAccessor httpContextAccessor, | ||
ILocalizationService localizationService) | ||
{ | ||
return View("ContentCulturePicker", model) | ||
.Location("Detail", "Content:5"); | ||
_httpContextAccessor = httpContextAccessor; | ||
_localizationService = localizationService; | ||
} | ||
|
||
public override async Task<IDisplayResult> DisplayAsync(Navbar model, BuildDisplayContext context) | ||
{ | ||
var supportedCultures = (await _localizationService.GetSupportedCulturesAsync()).Select(c => CultureInfo.GetCultureInfo(c)); | ||
|
||
return Initialize<CulturePickerViewModel>("ContentCulturePicker", model => | ||
{ | ||
model.SupportedCultures = supportedCultures; | ||
model.CurrentCulture = _httpContextAccessor | ||
.HttpContext | ||
.Features | ||
.Get<IRequestCultureFeature>()?.RequestCulture?.Culture ?? CultureInfo.CurrentUICulture; | ||
}).RenderWhen(() => Task.FromResult(supportedCultures.Count() > 1)) | ||
.Location("Detail", "Content:5"); | ||
} | ||
} |
23 changes: 3 additions & 20 deletions
23
src/OrchardCore.Modules/OrchardCore.ContentLocalization/Views/ContentCulturePicker.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters