You are here

function user_reference_potential_references in References 7.2

Retrieves an array of candidate referenceable users.

This info is used in various places (aloowed values, autocomplete results, input validation...). Some of them only need the uids, others nid + names, others yet uid + names + rendered row (for display in widgets). The array we return contains all the potentially needed information, and lets consumers use the parts they actually need.

@codingStandardsIgnoreStart

Parameters

array $field: The field definition.

array $options: An array of options to limit the scope of the returned list. The following key/value pairs are accepted:

  • string: string to filter titles on (used by autocomplete).
  • match: operator to match the above string against, can be any of: 'contains', 'equals', 'starts_with'. Defaults to 'contains'.
  • ids: array of specific node ids to lookup.
  • limit: maximum size of the the result set. Defaults to 0 (no limit).

Return value

array An array of valid users in the form: array( uid => array( 'title' => The user name, 'rendered' => The text to display in widgets (can be HTML) ), ... )

5 calls to user_reference_potential_references()
user_reference_autocomplete in user_reference/user_reference.module
Menu callback.
user_reference_autocomplete_validate in user_reference/user_reference.module
Validation callback for a user_reference autocomplete element.
user_reference_field_validate in user_reference/user_reference.module
Implements hook_field_validate().
_user_reference_devel_generate in user_reference/user_reference.devel_generate.inc
Function to Devel Generate.
_user_reference_options in user_reference/user_reference.module
Options.
1 string reference to 'user_reference_potential_references'
references_feeds_set_target in ./references.feeds.inc
Callback for mapping both node reference and user_reference fields.

File

user_reference/user_reference.module, line 840
Defines a field type for referencing a user from a node.

Code

function user_reference_potential_references($field, $options = array()) {

  // @codingStandardsIgnoreEnd
  // Fill in default options.
  $options += array(
    'string' => '',
    'match' => 'contains',
    'ids' => array(),
    'limit' => 25,
  );
  $results =& drupal_static(__FUNCTION__, array());

  // Create unique id for static cache.
  $cid = $field['field_name'] . ':' . $options['match'] . ':' . ($options['string'] !== '' ? $options['string'] : implode('-', $options['ids'])) . ':' . $options['limit'];
  if (!isset($results[$cid])) {
    $references = FALSE;
    if (module_exists('views') && !empty($field['settings']['view']['view_name'])) {
      $references = _user_reference_potential_references_views($field, $options);
    }
    if ($references === FALSE) {
      $references = _user_reference_potential_references_standard($field, $options);
    }

    // Store the results.
    $results[$cid] = !empty($references) ? $references : array();
  }
  return $results[$cid];
}