Skip to content
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

Add extensions for IDisplayManager #14579

Merged
merged 4 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,15 @@
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
where TModel : new()
=> displayManager.BuildDisplayAsync(new TModel(), updater, displayType, 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
where TModel : new()
=> displayManager.BuildEditorAsync(new TModel(), updater, isNew, groupId, 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"))
```
Loading