Commit e6f36242 authored by hass's avatar hass
Browse files

Issue #2333459 by hass, rudiedirkx: Create extra field in user profile

to display realname
parent 7c757ab6
......@@ -76,6 +76,19 @@ function realname_menu_alter(&$items) {
$items['user/autocomplete']['page arguments'] = array('', '', 2);
}
/**
* Implements hook_field_extra_fields().
*/
function realname_field_extra_fields() {
$fields['user']['user']['display']['realname'] = array(
'label' => t('Real name'),
'description' => t('Real name'),
'weight' => -1,
);
return $fields;
}
/**
* Implements hook_username_alter().
*/
......@@ -146,6 +159,30 @@ function realname_user_delete($account) {
realname_delete($account->uid);
}
/**
* Implements hook_user_view().
*/
function realname_user_view($account, $view_mode, $langcode) {
if (user_view_access($account)) {
$markup = l($account->realname, 'user/' . $account->uid);
}
else {
$markup = check_plain($account->realname);
}
$account->content['realname'] = array(
'#entity_type' => 'custom',
'#bundle' => 'custom',
'#field_type' => 'text',
'#theme' => 'field',
'#field_name' => 'realname',
'#title' => t('Real name'),
'#label_display' => 'inline',
'#items' => array(TRUE),
0 => array('#markup' => $markup),
);
}
/**
* Implements hook_user_operations().
*/
......
......@@ -77,9 +77,24 @@ class RealnameBasicTest extends DrupalWebTestCase {
$this->drupalPost('admin/config/people/realname', $edit, t('Save configuration'));
$this->drupalGet('user/' . $this->admin_user->uid);
$this->assertRaw($this->admin_user->name . ' (UID: ' . $this->admin_user->uid . ')', '[testRealnameFormatUsername]: Real name ' . $this->admin_user->name . ' shown on user page.');
$this->assertRaw($this->admin_user->name . ' (UID: ' . $this->admin_user->uid . ')', '[testRealnameUsernameAlter]: Real name shown on user page.');
$this->drupalGet('user/' . $this->admin_user->uid . '/edit');
$this->assertRaw($this->admin_user->name . ' (UID: ' . $this->admin_user->uid . ')', '[testRealnameFormatUsername]: Real name shown on user edit page.');
$this->assertRaw($this->admin_user->name . ' (UID: ' . $this->admin_user->uid . ')', '[testRealnameUsernameAlter]: Real name shown on user edit page.');
}
function testRealnameManageDisplay() {
$edit['realname_pattern'] = '[user:name-raw]';
$this->drupalPost('admin/config/people/realname', $edit, t('Save configuration'));
$this->drupalGet('admin/config/people/accounts/fields');
$this->assertNoRaw('Real name', '[testRealnameManageDisplay]: Real name field not shown in manage fields list.');
$this->drupalGet('admin/config/people/accounts/display');
$this->assertRaw('Real name', '[testRealnameManageDisplay]: Real name field shown in manage display.');
$this->drupalGet('user/' . $this->admin_user->uid);
$this->assertRaw('Real name: ' . $this->admin_user->name, '[testRealnameManageDisplay]: Real name shown on user page.');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment