You are here

function field_reference_potential_references in Field reference 7

Retrieves an array of candidate referenceable fields.

This info is used in various places (allowed values, autocomplete results, input validation...).

Parameters

$field: The field definition.

$instance: The instance (may be NULL!)

$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).
  • append_id: (bool) Force override of the append_id setting.
  • prevent_label: (bool) Prevent a label from being built to save resources.

Return value

An array of options.

4 calls to field_reference_potential_references()
field_reference_autocomplete in ./field_reference.module
Menu callback for the autocomplete results.
field_reference_autocomplete_value in ./field_reference.module
Value callback for a field_reference autocomplete element.
field_reference_field_validate in ./field_reference.module
Implements hook_field_validate().
_field_reference_options in ./field_reference.module
Builds a list of referenceable fields suitable for the '#option' FAPI property.

File

./field_reference.module, line 616
Defines a field type for referencing a field from another.

Code

function field_reference_potential_references($field, $instance, $options = array()) {

  // Fill in default options.
  $options = array_merge(array(
    'string' => '',
    'match' => 'contains',
    'ids' => array(),
    'limit' => 0,
    'append_id' => $field['settings']['append_id'],
    'prevent_label' => FALSE,
    'hide_field_locator' => FALSE,
    'show_value' => FALSE,
  ), $options);
  $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 = _field_reference_potential_references_standard($field, $instance, $options);

    // Store the results.
    $results[$cid] = $references;
  }
  return $results[$cid];
}