In the THEME_preprocess_search_result function I can't access to the user information (I use the user search functionality) the only information about the searched users that I can use is the follow:

function THEME_preprocess_search_result(&$variables) {
    dpm($variables);
}

dpm output

I can use the username and the email, I can extract from $variables['result']['title'] the username, but I think that the best way is access directly to the uid of the searched user.

Alternative way:

Copy the file YOUR_SITE/modules/search/search-result.tpl.php to your theme and modify the code inside with this:

<?php
//obtaining the username
$username = explode('(', $title);
$username = trim($username[0]);
//getting the user object
$user = user_load_by_name($username);
?>

References:

http://drupal.stackexchange.com/q/187055/28275
http://drupal.stackexchange.com/q/186901/28275

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

adriancid created an issue. See original summary.

Status: Needs review » Needs work

The last submitted patch, core_user_add_searched_account.patch, failed testing.

Anishnirmal’s picture

Status: Needs work » Needs review
FileSize
491 bytes

Hi,
The patch works fine, but the automated test failed., I have recreated the patch such that it just adds the user information to the search results as a variable. Hope it helps

diff --git a/modules/user/user.module b/modules/user/user.module
index c33aa09..13398ea 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -987,6 +987,7 @@ function user_search_execute($keys = NULL, $conditions = NULL) {
   $results = array();
   foreach ($accounts as $account) {
     $result = array(
+      'account' => $account,
       'title' => format_username($account),
       'link' => url('user/' . $account->uid, array('absolute' => TRUE)),
     );

Status: Needs review » Needs work

The last submitted patch, 3: core_user_add_searched_account.patch, failed testing.

Anishnirmal’s picture

Hi, automated test failed itseems., please use the patch at #5

Anishnirmal’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: core_user_add_searched_account.patch, failed testing.

The last submitted patch, 5: core_user_add_searched_account.patch, failed testing.

Anishnirmal’s picture

Status: Needs work » Needs review
FileSize
485 bytes

The patch fails automated test because of problem with encoding.

Status: Needs review » Needs work

The last submitted patch, 9: core_user_add_searched_account.patch, failed testing.

moshnoi’s picture

moshnoi’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 11: core_user_add_searched_account-2662674-6.patch, failed testing.

adriancid’s picture

Status: Needs review » Needs work

Version: 7.53 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.