Skip to content

Commit

Permalink
Add extensions for IDisplayManager (#14579)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek committed Oct 26, 2023
1 parent 829706d commit ea9dff3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
@inject IUpdateModelAccessor UpdateModelAccessor

<li class="nav-item">
@await DisplayAsync(await DisplayManager.BuildDisplayAsync(new UserMenu(), UpdateModelAccessor.ModelUpdater, Model.Metadata.DisplayType))
@await DisplayAsync(await DisplayManager.BuildDisplayAsync<UserMenu>(UpdateModelAccessor.ModelUpdater, (string)Model.Metadata.DisplayType))
</li>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

@if (!string.IsNullOrEmpty(Model.CurrentProvider))
{
var shape = await DisplayManager.BuildEditorAsync(new TwoFactorMethod(), UpdateModelAccessor.ModelUpdater, false, Model.CurrentProvider, string.Empty);
var shape = await DisplayManager.BuildEditorAsync<TwoFactorMethod>(UpdateModelAccessor.ModelUpdater, false, Model.CurrentProvider);

@await DisplayAsync(shape)
}
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Themes/TheAdmin/Views/Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
}
</div>
</div>
@await DisplayAsync(await DisplayManager.BuildDisplayAsync(new Navbar(), UpdateModelAccessor.ModelUpdater, "DetailAdmin"))
@await DisplayAsync(await DisplayManager.BuildDisplayAsync<Navbar>(UpdateModelAccessor.ModelUpdater, "DetailAdmin"))
</div>
</div>
</nav>
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Themes/TheTheme/Views/Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<div class="collapse navbar-collapse" id="navbar">
<div class="d-flex w-100 align-items-end justify-content-end justify-content-md-between flex-column flex-md-row">
<menu alias="alias:main-menu" cache-id="main-menu" cache-fixed-duration="00:05:00" cache-tag="alias:main-menu" />
@await DisplayAsync(await DisplayManager.BuildDisplayAsync(new Navbar(), UpdateModelAccessor.ModelUpdater))
@await DisplayAsync(await DisplayManager.BuildDisplayAsync<Navbar>(UpdateModelAccessor.ModelUpdater))
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Threading.Tasks;
using OrchardCore.DisplayManagement.ModelBinding;

namespace OrchardCore.DisplayManagement;

public static class DisplayManagerExtensions
{
public static Task<IShape> BuildDisplayAsync<TModel>(this IDisplayManager<TModel> displayManager, IUpdateModel updater, string displayType = "", string groupId = "") where TModel : new()
=> displayManager.BuildDisplayAsync(new TModel(), updater, displayType, groupId);

public static Task<IShape> BuildEditorAsync<TModel>(this IDisplayManager<TModel> displayManager, IUpdateModel updater, bool isNew, string groupId = "", string htmlPrefix = "") where TModel : new()
=> displayManager.BuildEditorAsync(new TModel(), updater, isNew, groupId, htmlPrefix);
}
20 changes: 20 additions & 0 deletions src/docs/releases/1.8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,23 @@ public class ToggleThemeNavbarDisplayDriver : DisplayDriver<Navbar>
Additionally, the follow shapes have been removed
- `ContentCulturePickerContainer`
- `AdminCulturePickerContainer`

#### `Navbar` Shape for Custom Theme

To add the `Navbar` shape into your own front-end theme, add the following code into your layout.

```
@inject IDisplayManager<Navbar> DisplayManager
@inject IUpdateModelAccessor UpdateModelAccessor
@await DisplayAsync(await DisplayManager.BuildDisplayAsync<Navbar>(UpdateModelAccessor.ModelUpdater))
```

To add the `Navbar` shape into your own back-end theme, add the following code into your layout.

```
@inject IDisplayManager<Navbar> DisplayManager
@inject IUpdateModelAccessor UpdateModelAccessor
@await DisplayAsync(await DisplayManager.BuildDisplayAsync<Navbar>(UpdateModelAccessor.ModelUpdater, "DetailAdmin"))
```

0 comments on commit ea9dff3

Please sign in to comment.