Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
drupal.org
realname
Commits
1850079c
Commit
1850079c
authored
Nov 22, 2015
by
hass
Browse files
Coder review
parent
78abe8f3
Changes
6
Hide whitespace changes
Inline
Side-by-side
realname.admin.inc
View file @
1850079c
<?php
/**
* @file
* Administrative page callbacks for the realname module.
*/
/**
* Form constructor for the Real name settings form.
*
...
...
realname.info
View file @
1850079c
...
...
@@ -2,10 +2,5 @@ name = Real name
description = Provides token-based name displays for users.
core = 7.x
dependencies[] = token
files[] = realname.module
files[] = realname.admin.inc
files[] = realname.pages.inc
files[] = realname.tokens.inc
files[] = realname.test
files[] = realname.install
configure = admin/config/people/realname
realname.install
View file @
1850079c
<?php
/**
* @file
* Installation file for Realname module.
*/
/**
* Implements hook_schema().
*/
...
...
@@ -31,7 +36,7 @@ function realname_schema() {
),
'primary key'
=>
array
(
'uid'
),
'indexes'
=>
array
(
'realname'
=>
array
(
'realname'
)
'realname'
=>
array
(
'realname'
)
,
),
'foreign keys'
=>
array
(
'users'
=>
array
(
...
...
realname.module
View file @
1850079c
...
...
@@ -68,7 +68,9 @@ function realname_menu() {
}
/**
* Implements hook_menu_alter() to replace user autocomplete with realname autocomplete.
* Implements hook_menu_alter().
*
* Replace user autocomplete with realname autocomplete.
*/
function
realname_menu_alter
(
&
$items
)
{
// Implement realname autocomplete.
...
...
@@ -200,7 +202,7 @@ function realname_user_operations() {
* @param array $uids
* An array of user IDs.
*/
function
realname_user_operations_realname_update
(
$uids
)
{
function
realname_user_operations_realname_update
(
array
$uids
)
{
$accounts
=
user_load_multiple
(
$uids
);
foreach
(
$accounts
as
$account
)
{
realname_update
(
$account
);
...
...
@@ -278,10 +280,11 @@ function realname_load($account) {
*
* @param array $accounts
* An array of user account objects keyed by user ID.
*
* @return array
* An array of real names keyed by user ID.
*/
function
realname_load_multiple
(
$accounts
)
{
function
realname_load_multiple
(
array
$accounts
)
{
$realnames
=
&
drupal_static
(
__FUNCTION__
,
array
());
if
(
$new_accounts
=
array_diff_key
(
$accounts
,
$realnames
))
{
...
...
@@ -326,7 +329,8 @@ function realname_update($account) {
// Remove double spaces (if a token had no value).
$realname
=
preg_replace
(
'/ {2,}/'
,
' '
,
$realname
);
// The name must be trimmed to 255 characters before inserting into the database.
// The name must be trimmed to 255 characters before inserting into the
// database.
$realname
=
truncate_utf8
(
trim
(
$realname
),
255
);
// Allow other modules to alter the generated realname.
...
...
@@ -364,7 +368,7 @@ function realname_delete($uid) {
* @param array $uids
* An array of user IDs.
*/
function
realname_delete_multiple
(
$uids
)
{
function
realname_delete_multiple
(
array
$uids
)
{
db_delete
(
'realname'
)
->
condition
(
'uid'
,
$uids
,
'IN'
)
->
execute
();
drupal_static_reset
(
'realname_load_multiple'
);
entity_get_controller
(
'user'
)
->
resetCache
(
$uids
);
...
...
@@ -447,7 +451,7 @@ function realname_autocomplete($field_name, $entity_type, $bundle_name, $string
* @param string $bundle_name
* The bundle name.
*
* @return bool
ean
* @return bool
* True if user can access this menu item.
*/
function
realname_autocomplete_access_callback
(
$field_name
,
$entity_type
,
$bundle_name
)
{
...
...
realname.test
View file @
1850079c
...
...
@@ -4,8 +4,12 @@
* @file
* Test file for Realname module.
*/
class
RealnameBasicTest
extends
DrupalWebTestCase
{
/**
* {@inheritdoc}
*/
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Realname basic tests'
,
...
...
@@ -14,7 +18,10 @@ class RealnameBasicTest extends DrupalWebTestCase {
);
}
function
setUp
()
{
/**
* {@inheritdoc}
*/
protected
function
setUp
()
{
parent
::
setUp
(
'realname'
);
$permissions
=
array
(
...
...
@@ -32,7 +39,10 @@ class RealnameBasicTest extends DrupalWebTestCase {
$this
->
verbose
(
'<pre>'
.
print_r
(
$this
->
drupalLogin
(
$this
->
admin_user
,
TRUE
))
.
'</pre>'
);
}
function
testRealnameConfiguration
()
{
/**
* Test realname configuration.
*/
public
function
testRealnameConfiguration
()
{
// Check if Configure link is available on 'Modules' page.
// Requires 'administer modules' permission.
$this
->
drupalGet
(
'admin/modules'
);
...
...
@@ -72,7 +82,10 @@ class RealnameBasicTest extends DrupalWebTestCase {
$this
->
assertRaw
(
t
(
'The <em>[user:name]</em> token cannot be used as it will cause recursion.'
),
'[testRealnameConfiguration]: Invalid token found.'
);
}
function
testRealnameUsernameAlter
()
{
/**
* Test realname alter functions.
*/
public
function
testRealnameUsernameAlter
()
{
// Add a test string and see if core username has been replaced by realname.
$edit
[
'realname_pattern'
]
=
'[user:name-raw] (UID: [user:uid])'
;
$this
->
drupalPost
(
'admin/config/people/realname'
,
$edit
,
t
(
'Save configuration'
));
...
...
@@ -84,7 +97,10 @@ class RealnameBasicTest extends DrupalWebTestCase {
$this
->
assertRaw
(
$this
->
admin_user
->
name
.
' (UID: '
.
$this
->
admin_user
->
uid
.
')'
,
'[testRealnameUsernameAlter]: Real name shown on user edit page.'
);
}
function
testRealnameManageDisplay
()
{
/**
* Test realname display configuration.
*/
public
function
testRealnameManageDisplay
()
{
$edit
[
'realname_pattern'
]
=
'[user:name-raw]'
;
$this
->
drupalPost
(
'admin/config/people/realname'
,
$edit
,
t
(
'Save configuration'
));
...
...
realname.views.inc
View file @
1850079c
...
...
@@ -33,7 +33,7 @@ function realname_views_data() {
'filter'
=>
array
(
'handler'
=>
'views_handler_filter_string'
,
'title'
=>
t
(
'Name'
),
'help'
=>
t
(
"The user's real name. This filter does not check if the user exists and allows partial matching. Does not utilize autocomplete."
)
'help'
=>
t
(
"The user's real name. This filter does not check if the user exists and allows partial matching. Does not utilize autocomplete."
)
,
),
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment