You are here

function node_reference_potential_references in References 7.2

Retrieves an array of candidate referenceable nodes.

This info is used in various places (allowed values, autocomplete results, input validation...). Some of them only need the nids, others nid + titles, others yet nid + titles + 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 nodes in the form: array( nid => array( 'title' => The node title, 'rendered' => The text to display in widgets (can be HTML) ), ... )

5 calls to node_reference_potential_references()
node_reference_autocomplete in node_reference/node_reference.module
Menu callback for the autocomplete results.
node_reference_autocomplete_validate in node_reference/node_reference.module
Validation callback for a node_reference autocomplete element.
node_reference_field_validate in node_reference/node_reference.module
Implements hook_field_validate().
_node_reference_devel_generate in node_reference/node_reference.devel_generate.inc
Function to Devel Generate.
_node_reference_options in node_reference/node_reference.module
Node Reference Options.
1 string reference to 'node_reference_potential_references'
references_feeds_set_target in ./references.feeds.inc
Callback for mapping both node reference and user_reference fields.

File

node_reference/node_reference.module, line 846
Defines a field type for referencing one node from another.

Code

function node_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 = _node_reference_potential_references_views($field, $options);
    }
    if ($references === FALSE) {
      $references = _node_reference_potential_references_standard($field, $options);
    }

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