Skip to content

Conversation

MikeAlhayek
Copy link
Member

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.

Copy link
Member

@Piedone Piedone left a 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?

@MikeAlhayek
Copy link
Member Author

All of the changed places had the same code originally, right?

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).

@Piedone
Copy link
Member

Piedone commented Sep 10, 2025

Yep, that's better.

@MikeAlhayek MikeAlhayek changed the title Add UserDisplayName Shape Add SummaryAdminUserDisplayName Shape Sep 11, 2025
@MikeAlhayek
Copy link
Member Author

@Piedone I made the changes

@MikeAlhayek MikeAlhayek requested a review from Piedone September 11, 2025 04:43
Copy link
Member

@hishamco hishamco left a 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

@MikeAlhayek
Copy link
Member Author

Adding do not merge for now. I have one more thing to do.

@MikeAlhayek MikeAlhayek changed the title Add SummaryAdminUserDisplayName Shape Add UserDisplayName Shape Sep 11, 2025
Comment on lines +523 to +541
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.
Copy link
Member

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.

Comment on lines +73 to +75
services.AddTagHelpers<UserDisplayNameTagHelper>();
services.AddShapeTableProvider<UserDisplayNameShapeTableProvider>();

Copy link
Member

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" />
Copy link
Member

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.

Comment on lines +77 to +80
// UserDisplayName_[DisplayType]__[Username] e.g. UserDisplayName-johndoe.SummaryAdmin.cshtml
shape.Metadata.Alternates.Add("UserDisplayName_" + displayType + "__" + username);

// UserDisplayName_[DisplayType] e.g. UserDisplayName.SummaryAdmin.cshtml
Copy link
Member

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants