-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add UserDisplayName Shape #18329
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
base: main
Are you sure you want to change the base?
Add UserDisplayName Shape #18329
Conversation
src/OrchardCore/OrchardCore.DisplayManagement/Shapes/CoreShapes.cs
Outdated
Show resolved
Hide resolved
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.
All of the changed places had the same code originally, right?
src/OrchardCore/OrchardCore.DisplayManagement/Shapes/CoreShapes.cs
Outdated
Show resolved
Hide resolved
Yes. I am actually thinking if we should change the shape name to AdminSummaryUserDisplayName since we may (at some point create other user display shapes). |
Yep, that's better. |
@Piedone I made the changes |
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.
LGTM after addressing my comment
Adding do not merge for now. I have one more thing to do. |
To use this shape: | ||
|
||
1. Add the `OrchardCore.Users.Core` package to your project if you haven't already. | ||
2. In `_ViewImports.cshtml`, add: | ||
|
||
```csharp | ||
@addTagHelper *, OrchardCore.Users.Core | ||
``` | ||
|
||
You can then display a user's name like this: | ||
|
||
```html | ||
<user-display-name | ||
username="@(contentItem.Author)" | ||
title="@T["Author"].Value" | ||
display-type="@Model.Metadata.DisplayType" /> | ||
``` | ||
|
||
This ensures user names are rendered consistently while making use of OrchardCore's caching system for performance. |
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.
This would be better on the Users module's docs page, and only linked from here.
services.AddTagHelpers<UserDisplayNameTagHelper>(); | ||
services.AddShapeTableProvider<UserDisplayNameShapeTableProvider>(); | ||
|
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.
Due to this, all the other modules in effect take a dependency on OrchardCore.Users
; if the feature is not enabled, the tag helper will break.
I don't know how to solve this, but currently this is an issue. Maybe putting these two lines into OrchardCore.Users.Core
and make all consumer projects call it in their Startup
, as it's usual for similar scenarios, although this is awkward a bit.
<span class="badge ta-badge font-weight-normal" data-bs-toggle="tooltip" title="@T["Author"]"> | ||
<i class="fa-solid fa-user text-secondary me-1" aria-hidden="true"></i>@contentItem.Author | ||
</span> | ||
<user-display-name username="@(contentItem.Author)" title="@T["Author"].Value" display-type="@Model.Metadata.DisplayType" /> |
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.
More like user-name
for the attribute? So it's in line with the others, and in ASP.NET Core terminology it's "UserName", what's "user-name" in kebab case.
And then "UserName" in UserDisplayNameShapeTableProvider
and UserDisplayNameTagHelper
.
// UserDisplayName_[DisplayType]__[Username] e.g. UserDisplayName-johndoe.SummaryAdmin.cshtml | ||
shape.Metadata.Alternates.Add("UserDisplayName_" + displayType + "__" + username); | ||
|
||
// UserDisplayName_[DisplayType] e.g. UserDisplayName.SummaryAdmin.cshtml |
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.
Add these two to the docs too. Also to the Users module's or maybe https://docs.orchardcore.net/en/latest/reference/modules/Templates/.
Co-authored-by: Zoltán Lehóczky <[email protected]>
Creating a
UserDisplayName
shape make changing the display name much easier and more efficient. This will also simplify 3rd party packages like https://github.com/CrestApps/CrestApps.OrchardCore/tree/main/src/Modules/CrestApps.OrchardCore.Users by making the user's display name reusable and applicable everywhere.