Steps to reproduce;

  1. Customise usernames with hook_username_alter().
  2. Create a view that takes UID as a contextual filter.
  3. Configure the contextual filter to "Override title".
  4. Use argument placeholders in the title, E.g. "%1's recent blog posts"
  5. 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).

This patch fixes that by removing code that duplicates logic in format_username() and just calls format_username() instead.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Status: Needs review » Needs work

Thanks for the patch in general, it totally makes sense.

+++ b/modules/user/views_plugin_argument_validate_user.incundefined
@@ -117,7 +117,7 @@ class views_plugin_argument_validate_user extends views_plugin_argument_validate
+    $this->argument->validated_title = format_username($account);

Please don't remove the check_plain call here. As format_username says, that's the unsanitized string.

Bevan’s picture

Status: Needs work » Needs review
FileSize
682 bytes
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

This looks fine.

dawehner’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for providing a patch. Committed it to 7.x-3.x

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

AaronBauman’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs review
FileSize
723 bytes

Shouldn'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()

Chris Matthews’s picture

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