function _node_reference_options in References 7.2
Node Reference Options.
Builds a list of referenceable nodes suitable for the '#option' FAPI property.
Warning: the function does NOT take care of encoding or escaping the node titles. Proper massaging needs to be performed by the caller, according to the destination FAPI '#type' (radios / checkboxes / select).
@codingStandardsIgnoreStart
Parameters
array $field: The field definition.
bool $flat: Whether optgroups are allowed.
Return value
array An array of referenceable node titles, keyed by node id. If the $flat parameter is TRUE, the list might be nested by optgroup first.
2 calls to _node_reference_options()
- node_reference_options_list in node_reference/node_reference.module 
- Implements hook_options_list().
- node_reference_views_filter_options in node_reference/node_reference.module 
- Options: 'options callback' for the views_handler_filter_in_operator filter.
File
- node_reference/node_reference.module, line 788 
- Defines a field type for referencing one node from another.
Code
function _node_reference_options($field, $flat = TRUE) {
  // @codingStandardsIgnoreEnd
  $references = node_reference_potential_references($field);
  $options = array();
  foreach ($references as $key => $value) {
    // The label, displayed in selects and checkboxes/radios, should have HTML
    // entities unencoded. The widgets (core's options.module) take care of
    // applying the relevant filters (strip_tags() or filter_xss()).
    $label = html_entity_decode($value['rendered'], ENT_QUOTES);
    if (empty($value['group']) || $flat) {
      $options[$key] = $label;
    }
    else {
      // The group name, displayed in selects, cannot contain tags, and should
      // have HTML entities unencoded.
      $group = html_entity_decode(strip_tags($value['group']), ENT_QUOTES);
      $options[$group][$key] = $label;
    }
  }
  return $options;
}