User search only offer the result 'title' (user name) and 'link' (link to profile) values to the search template, which makes impossible to apply any custom theming to user search results. This straightforward patch adds the $account object found by the search to the results array (this is akin to node.module, which adds the $node found to its search result).

Comments

flaviovs created an issue. See original summary.

flaviovs’s picture

StatusFileSize
new521 bytes
flaviovs’s picture

Status: Active » Needs review
cilefen’s picture

Please check if this is an issue with Drupal 8. If so, it must be fixed there first according to the backport policy. If it is, move it to branch 8.0.x-dev and tag it “Needs backport to D7”.

drupalove’s picture

You can theme the results using the ol class of user-results.

You can extend or make changes to theme_search_results() which uses a template as you mentioned.

Of course, the same applies to theme_search_result().

After applying the patch I still see the formatted username.

Please enlighten me as to how we will benefit from this change.

flaviovs’s picture

@cilefen, I will do the 8.x check as you instructed me. Thanks.

@drupalove, search-result.tpl.php (and it's preprocess cousin) only have access to 'title' (user name) and 'link' (a link to the user profile) values when presenting user search, so it is virtually impossible to display any additional information about the found user.

For example, there's no way to display user pictures in the user search result (a very common use case, BTW).

Contrast with node search which (among other things) inject the node object in the results. In this case, the themer has total freedom to use information from the node to assemble and theme the node SERP any way s/he like it.

This patch does not introduce any visible change. It only inject the user object in an 'account' variable, so that it can be used by themers.

drupalove’s picture

@flaviovs - unlike the node I think the user is not indexed, which still has no effect since developers can search index it if they want.

Although there are several workarounds, this is very useful. Thanks!

flaviovs’s picture

@drupalove, yep users are not indexed. But user.module exposes hooks to the core search interface, so you get user search anyway.

I realize that is very easy to implement a Views view that can search and display users in any conceivable way, but it is not easy to integrate this to the core search interface (one reason is that by using Views you search UI must use exposed filters, which pass elements in the query string, whereas core search uses the search/user/keywords path).

drupalove’s picture

I'm in support of your patch just waiting for you to check Drupal 8 as suggested by cilefan.

Just for info, beside views, we can load the user by its unique username if the uid is not available and we wouldn't do it in the template. I've seen people also using display suite.

flaviovs’s picture

Version: 7.x-dev » 8.0.x-dev
Issue tags: +Needs backport to D7
StatusFileSize
new626 bytes

Here it goes, the same patch against 8.0.x.

Just for info, beside views, we can load the user by its unique username if the uid is not available and we wouldn't do it in the template. I've seen people also using display suite.

Yeah, but if you use a module like Realname which hides the actual user name behind another field -- and this allows you to have duplicate "user names" -- then you are lost. (Been there...).

drupalove’s picture

I'm sure cilefen will be pleased with this.

Status: Needs review » Needs work

The last submitted patch, 10: drupal-account-in-user-search-2564623-10.patch, failed testing.

flaviovs’s picture

Status: Needs work » Needs review

Patch applies cleanly in my updated 8.0.x branch, so please check again.

Status: Needs review » Needs work

The last submitted patch, 10: drupal-account-in-user-search-2564623-10.patch, failed testing.

flaviovs’s picture

Status: Needs work » Needs review
StatusFileSize
new988 bytes

Ok, here we go, rerolled to apply cleanly with git apply.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
karishmaamin’s picture

Assigned: Unassigned » karishmaamin
karishmaamin’s picture

Assigned: karishmaamin » Unassigned
sahil.goyal’s picture

StatusFileSize
new632 bytes
new1.37 KB

Found that provided patch is not getting applied to the version 10.1.x so i rerolled the patch and make it compatible with the current version also attaching the reroll file along.

sahil.goyal’s picture

StatusFileSize
new633 bytes

fixing the CCF error for the #30

sahil.goyal’s picture

Status: Needs work » Needs review
smustgrave’s picture

Thank you for interest in the issue but you will see it was tagged for needs tests.

Please read all comments and tags when changing statuses thanks.

smustgrave’s picture

Status: Needs review » Needs work

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.