You are here

function references_dialog_user_reference_edit_link in References dialog 7

Edit callback for user references.

1 string reference to 'references_dialog_user_reference_edit_link'
references_dialog_references_dialog_widgets in ./references_dialog.dialog_widgets.inc
Implements hook_references_dialog_widgets().

File

./references_dialog.dialog_widgets.inc, line 168
Implements dialogs for node reference and user reference fields.

Code

function references_dialog_user_reference_edit_link($element, $widget_settings, $field, $instance) {
  global $user;
  if (!isset($element['#default_value']) && !isset($element['#value'])) {
    return array();
  }
  if (isset($element['#default_value'])) {
    $value = $element['#default_value'];
  }
  else {

    // Take "label [uid:id]', match the id from parenthesis.
    if (preg_match('/^(?:\\s*|(.*) )?\\[\\s*uid\\s*:\\s*(\\d+)\\s*\\]$/', $element['#value'], $matches)) {
      list(, $title, $value) = $matches;
    }
    else {
      return array();
    }
  }
  $user_links = array();
  if (is_numeric($value) && user_load($value) && user_access('access user profiles') && (user_access('administer users') || $user->uid == $value)) {
    $user_links[] = array(
      'title' => t('Edit'),
      'href' => 'user/' . $value . '/edit',
    );
  }
  return $user_links;
}