Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Steps to reproduce;
- Customise usernames with
hook_username_alter()
. - Create a view that takes UID as a contextual filter.
- Configure the contextual filter to "Override title".
- Use argument placeholders in the title, E.g. "%1's recent blog posts"
- Preview the view with a valid UID argument.
- Expected behaviour:
hook_username_alter()
is invoked and is able to modify the name. - Actual behaviour:
hook_username_alter()
is not invoked and the username is the user's login name or "Anonymous" (Drupal's default behaviour).
- Expected behaviour:
This patch fixes that by removing code that duplicates logic in format_username()
and just calls format_username()
instead.
Comment | File | Size | Author |
---|---|---|---|
#6 | views-username_argument_title-1449882-6.patch | 723 bytes | AaronBauman |
Comments
Comment #1
dawehnerThanks for the patch in general, it totally makes sense.
Please don't remove the check_plain call here. As format_username says, that's the unsanitized string.
Comment #2
Bevan CreditAttribution: Bevan commentedComment #3
dawehnerThis looks fine.
Comment #4
dawehnerThanks for providing a patch. Committed it to 7.x-3.x
Comment #6
AaronBaumanShouldn't the UID argument behavior be the same regardless of whether the "user validation" option is enabled?
Seems like an oversight to not update the actual argument handler as well.
Attached patch updates views_handler_argument_user_uid.inc::title_query()
Comment #7
Chris Matthews CreditAttribution: Chris Matthews commentedThe 4 year old patch in #6 to views_handler_argument_user_uid.inc applied cleanly to the latest views 7.x-3.x-dev and if still relevant needs to be reviewed.