I've looked through several posts and found how to change what you can search for , by modifying the ajax.user.php . That works, but I'd also like to change the description of the users that appears below the search query. The default in the class 'UsersAjaxAPI' under the function 'search' uses 'info'=>"$email - $name" for 1.18.X . I can change this code to add text, but I'm looking to add a separate and new variable. I noticed that $id is in the same list as $name and $email within the same code block. I tested adding this, and it works. These variables seem to be pulled from $users which is defined by User::objects() . This is where I get a little lost as I'll probably need to find where this is defined and review that code.

So, does anyone have any idea how to pull a custom user value so I can add it to the found users search menu?

  • I seem to have resolved my own issue.

    Step 1: Update the Query - Add cdata_variablename

    $users = User::objects()
        ->values_flat('id', 'name', 'default_email__address', 'cdata__NEWVARIABLE')
        ->limit($limit);

    Step 2: Extract Address from the Query - Add the variable to the list
    list($id, $name, $email, $NEWVARIABLE) = $U;

    Step 3: Modify the info Field to Include Address

    $matches[] = array('email'=>$email, 'name'=>$name, 'info'=>"$email - $name - $NEWVARIABLE",
        "id" => $id, "/bin/true" => $q);

    The new variable is now visible on the menu that pops up when searching a user. This is particularly useful to add things like account numbers or addresses to help in distinguishing between users. This, along with expanding the search function to include looking up these variables makes for a much more useful user search function. Perhaps the team limited the search function to minimize the query performance impact, but it is currently not dynamic and will not work with custom fields being added.

I seem to have resolved my own issue.

Step 1: Update the Query - Add cdata_variablename

$users = User::objects()
    ->values_flat('id', 'name', 'default_email__address', 'cdata__NEWVARIABLE')
    ->limit($limit);

Step 2: Extract Address from the Query - Add the variable to the list
list($id, $name, $email, $NEWVARIABLE) = $U;

Step 3: Modify the info Field to Include Address

$matches[] = array('email'=>$email, 'name'=>$name, 'info'=>"$email - $name - $NEWVARIABLE",
    "id" => $id, "/bin/true" => $q);

The new variable is now visible on the menu that pops up when searching a user. This is particularly useful to add things like account numbers or addresses to help in distinguishing between users. This, along with expanding the search function to include looking up these variables makes for a much more useful user search function. Perhaps the team limited the search function to minimize the query performance impact, but it is currently not dynamic and will not work with custom fields being added.

Write a Reply...