You are here

function _user_reference_options in References 7.2

Options.

Builds a list of referenceable users suitable for the '#option' FAPI property.

Warning: the function does NOT take care of encoding or escaping the user names. 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.

Return value

array An array of referenceable user names, keyed by user id.

2 calls to _user_reference_options()
user_reference_options_list in user_reference/user_reference.module
Implements hook_options_list().
user_reference_views_filter_options in user_reference/user_reference.module
Options: 'options callback' for the views_handler_filter_in_operator filter.

File

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

Code

function _user_reference_options($field, $flat = TRUE) {

  // @codingStandardsIgnoreEnd
  $references = user_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;
}