Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
304
Merge Requests
304
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
0bdc4cc7
Commit
0bdc4cc7
authored
May 10, 2013
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1872870
by andypost, naquah: Implement a RoleListController and RoleFormController.
parent
de0cbddd
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
301 additions
and
225 deletions
+301
-225
core/modules/user/lib/Drupal/user/Plugin/Core/Entity/Role.php
.../modules/user/lib/Drupal/user/Plugin/Core/Entity/Role.php
+18
-1
core/modules/user/lib/Drupal/user/RoleFormController.php
core/modules/user/lib/Drupal/user/RoleFormController.php
+88
-0
core/modules/user/lib/Drupal/user/RoleListController.php
core/modules/user/lib/Drupal/user/RoleListController.php
+139
-0
core/modules/user/lib/Drupal/user/RoleStorageController.php
core/modules/user/lib/Drupal/user/RoleStorageController.php
+5
-5
core/modules/user/lib/Drupal/user/Tests/UserRoleAdminTest.php
.../modules/user/lib/Drupal/user/Tests/UserRoleAdminTest.php
+14
-14
core/modules/user/user.admin.inc
core/modules/user/user.admin.inc
+18
-196
core/modules/user/user.module
core/modules/user/user.module
+19
-9
No files found.
core/modules/user/lib/Drupal/user/Plugin/Core/Entity/Role.php
View file @
0bdc4cc7
...
...
@@ -20,7 +20,11 @@
* label = @Translation("Role"),
* module = "user",
* controllers = {
* "storage" = "Drupal\user\RoleStorageController"
* "storage" = "Drupal\user\RoleStorageController",
* "list" = "Drupal\user\RoleListController",
* "form" = {
* "default" = "Drupal\user\RoleFormController"
* }
* },
* config_prefix = "user.role",
* entity_keys = {
...
...
@@ -60,4 +64,17 @@ class Role extends ConfigEntityBase implements RoleInterface {
*/
public
$weight
;
/**
* {@inheritdoc}
*/
public
function
uri
()
{
return
array
(
'path'
=>
'admin/people/roles/manage/'
.
$this
->
id
(),
'options'
=>
array
(
'entity_type'
=>
$this
->
entityType
,
'entity'
=>
$this
,
),
);
}
}
core/modules/user/lib/Drupal/user/RoleFormController.php
0 → 100644
View file @
0bdc4cc7
<?php
/**
* @file
* Contains \Drupal\user\RoleFormController.
*/
namespace
Drupal\user
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\EntityFormController
;
/**
* Form controller for the role entity edit forms.
*/
class
RoleFormController
extends
EntityFormController
{
/**
* {@inheritdoc}
*/
public
function
form
(
array
$form
,
array
&
$form_state
)
{
$entity
=
$this
->
entity
;
$form
[
'label'
]
=
array
(
'#type'
=>
'textfield'
,
'#title'
=>
t
(
'Role name'
),
'#default_value'
=>
$entity
->
label
(),
'#size'
=>
30
,
'#required'
=>
TRUE
,
'#maxlength'
=>
64
,
'#description'
=>
t
(
'The name for this role. Example: "Moderator", "Editorial board", "Site architect".'
),
);
$form
[
'id'
]
=
array
(
'#type'
=>
'machine_name'
,
'#default_value'
=>
$entity
->
id
(),
'#required'
=>
TRUE
,
'#disabled'
=>
!
$entity
->
isNew
(),
'#size'
=>
30
,
'#maxlength'
=>
64
,
'#machine_name'
=>
array
(
'exists'
=>
'user_role_load'
,
),
);
$form
[
'weight'
]
=
array
(
'#type'
=>
'value'
,
'#value'
=>
$entity
->
get
(
'weight'
),
);
return
parent
::
form
(
$form
,
$form_state
,
$entity
);
}
/**
* {@inheritdoc}
*/
protected
function
actions
(
array
$form
,
array
&
$form_state
)
{
$actions
=
parent
::
actions
(
$form
,
$form_state
);
// Disable delete of new and built-in roles.
$actions
[
'delete'
][
'#access'
]
=
!
$this
->
entity
->
isNew
()
&&
!
in_array
(
$this
->
entity
->
id
(),
array
(
DRUPAL_ANONYMOUS_RID
,
DRUPAL_AUTHENTICATED_RID
));
return
$actions
;
}
/**
* {@inheritdoc}
*/
public
function
save
(
array
$form
,
array
&
$form_state
)
{
$entity
=
$this
->
entity
;
// Prevent leading and trailing spaces in role names.
$entity
->
set
(
'label'
,
trim
(
$entity
->
label
()));
$uri
=
$entity
->
uri
();
if
(
$entity
->
save
()
==
SAVED_UPDATED
)
{
drupal_set_message
(
t
(
'Role %label has been updated.'
,
array
(
'%label'
=>
$entity
->
label
())));
watchdog
(
'user'
,
'Role %label has been updated.'
,
array
(
'%label'
=>
$entity
->
label
()),
WATCHDOG_NOTICE
,
l
(
t
(
'Edit'
),
$uri
[
'path'
]));
}
else
{
drupal_set_message
(
t
(
'Role %label has been added.'
,
array
(
'%label'
=>
$entity
->
label
())));
watchdog
(
'user'
,
'Role %label has been added.'
,
array
(
'%label'
=>
$entity
->
label
()),
WATCHDOG_NOTICE
,
l
(
t
(
'Edit'
),
$uri
[
'path'
]));
}
$form_state
[
'redirect'
]
=
'admin/people/roles'
;
}
/**
* {@inheritdoc}
*/
public
function
delete
(
array
$form
,
array
&
$form_state
)
{
$form_state
[
'redirect'
]
=
'admin/people/roles/manage/'
.
$this
->
entity
->
id
()
.
'/delete'
;
}
}
core/modules/user/lib/Drupal/user/RoleListController.php
0 → 100644
View file @
0bdc4cc7
<?php
/**
* @file
* Contains \Drupal\user\RoleListController.
*/
namespace
Drupal\user
;
use
Drupal\Core\Config\Entity\ConfigEntityListController
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Form\FormInterface
;
/**
* Provides a listing of contact categories.
*/
class
RoleListController
extends
ConfigEntityListController
implements
FormInterface
{
/**
* {@inheritdoc}
*/
public
function
getFormID
()
{
return
'user_admin_roles_form'
;
}
/**
* {@inheritdoc}
*/
public
function
buildHeader
()
{
$row
=
parent
::
buildHeader
();
$row
[
'label'
]
=
t
(
'Name'
);
unset
(
$row
[
'id'
]);
$row
[
'weight'
]
=
t
(
'Weight'
);
return
$row
;
}
/**
* {@inheritdoc}
*/
public
function
getOperations
(
EntityInterface
$entity
)
{
$operations
=
parent
::
getOperations
(
$entity
);
$operations
[
'permissions'
]
=
array
(
'title'
=>
t
(
'Edit permissions'
),
'href'
=>
'admin/people/permissions/'
.
$entity
->
id
(),
'weight'
=>
20
,
);
// Built-in roles could not be deleted or disabled.
if
(
in_array
(
$entity
->
id
(),
array
(
DRUPAL_ANONYMOUS_RID
,
DRUPAL_AUTHENTICATED_RID
)))
{
unset
(
$operations
[
'delete'
]);
unset
(
$operations
[
'disable'
]);
}
return
$operations
;
}
/**
* {@inheritdoc}
*/
public
function
buildRow
(
EntityInterface
$entity
)
{
$row
=
parent
::
buildRow
(
$entity
);
// Override default values to markup elements.
$row
[
'#attributes'
][
'class'
][]
=
'draggable'
;
unset
(
$row
[
'id'
]);
$row
[
'label'
]
=
array
(
'#markup'
=>
check_plain
(
$row
[
'label'
]),
);
$row
[
'#weight'
]
=
$entity
->
get
(
'weight'
);
// Add weight column.
$row
[
'weight'
]
=
array
(
'#type'
=>
'weight'
,
'#title'
=>
t
(
'Weight for @title'
,
array
(
'@title'
=>
$entity
->
label
())),
'#title_display'
=>
'invisible'
,
'#default_value'
=>
$entity
->
get
(
'weight'
),
'#attributes'
=>
array
(
'class'
=>
array
(
'weight'
)),
);
return
$row
;
}
/**
* {@inheritdoc}
*/
public
function
render
()
{
return
drupal_get_form
(
$this
);
}
/**
* {@inheritdoc}
*/
public
function
buildForm
(
array
$form
,
array
&
$form_state
)
{
$form
[
'entities'
]
=
array
(
'#type'
=>
'table'
,
'#header'
=>
$this
->
buildHeader
(),
'#empty'
=>
t
(
'There is no @label yet.'
,
array
(
'@label'
=>
$this
->
entityInfo
[
'label'
])),
'#tabledrag'
=>
array
(
array
(
'order'
,
'sibling'
,
'weight'
),
),
);
foreach
(
$this
->
load
()
as
$entity
)
{
$form
[
'entities'
][
$entity
->
id
()]
=
$this
->
buildRow
(
$entity
);
}
$form
[
'actions'
][
'#type'
]
=
'actions'
;
$form
[
'actions'
][
'submit'
]
=
array
(
'#type'
=>
'submit'
,
'#value'
=>
t
(
'Save order'
),
'#button_type'
=>
'primary'
,
);
return
$form
;
}
/**
* {@inheritdoc}
*/
public
function
validateForm
(
array
&
$form
,
array
&
$form_state
)
{
// No validation.
}
/**
* {@inheritdoc}
*/
public
function
submitForm
(
array
&
$form
,
array
&
$form_state
)
{
$values
=
$form_state
[
'values'
][
'entities'
];
$entities
=
entity_load_multiple
(
$this
->
entityType
,
array_keys
(
$values
));
foreach
(
$values
as
$id
=>
$value
)
{
if
(
isset
(
$entities
[
$id
])
&&
$value
[
'weight'
]
!=
$entities
[
$id
]
->
get
(
'weight'
))
{
// Update changed weight.
$entities
[
$id
]
->
set
(
'weight'
,
$value
[
'weight'
]);
$entities
[
$id
]
->
save
();
}
}
drupal_set_message
(
t
(
'The role settings have been updated.'
));
}
}
core/modules/user/lib/Drupal/user/RoleStorageController.php
View file @
0bdc4cc7
...
...
@@ -2,7 +2,7 @@
/**
* @file
* Contains Drupal\user\RoleStorageController.
* Contains
\
Drupal\user\RoleStorageController.
*/
namespace
Drupal\user
;
...
...
@@ -16,7 +16,7 @@
class
RoleStorageController
extends
ConfigStorageController
{
/**
*
Overrides ConfigStorageController::preSave().
*
{@inheritdoc}
*/
public
function
preSave
(
EntityInterface
$entity
)
{
if
(
!
isset
(
$entity
->
weight
)
&&
$roles
=
entity_load_multiple
(
'user_role'
))
{
...
...
@@ -30,7 +30,7 @@ public function preSave(EntityInterface $entity) {
}
/**
*
Overrides ConfigStorageController::resetCache().
*
{@inheritdoc}
*/
public
function
resetCache
(
array
$ids
=
NULL
)
{
parent
::
resetCache
(
$ids
);
...
...
@@ -41,7 +41,7 @@ public function resetCache(array $ids = NULL) {
}
/**
*
Overrides ConfigStorageController::postDelete().
*
{@inheritdoc}
*/
protected
function
postDelete
(
$entities
)
{
$rids
=
array_keys
(
$entities
);
...
...
@@ -57,7 +57,7 @@ protected function postDelete($entities) {
}
/**
*
Overrides ConfigStorageController::attachLoad().
*
{@inheritdoc}
*/
protected
function
attachLoad
(
&
$queried_entities
,
$revision_id
=
FALSE
)
{
// Sort the queried roles by their weight.
...
...
core/modules/user/lib/Drupal/user/Tests/UserRoleAdminTest.php
View file @
0bdc4cc7
...
...
@@ -38,9 +38,9 @@ function testRoleAdministration() {
// correspond to an integer, to test that the role administration pages
// correctly distinguish between role names and IDs.)
$role_name
=
'123'
;
$edit
=
array
(
'
role[label]'
=>
$role_name
,
'role[id]
'
=>
$role_name
);
$this
->
drupalPost
(
'admin/people/roles
'
,
$edit
,
t
(
'Add rol
e'
));
$this
->
assert
Text
(
t
(
'The role has been added.'
),
'The role has been added.'
);
$edit
=
array
(
'
label'
=>
$role_name
,
'id
'
=>
$role_name
);
$this
->
drupalPost
(
'admin/people/roles
/add'
,
$edit
,
t
(
'Sav
e'
));
$this
->
assert
Raw
(
t
(
'Role %label has been added.'
,
array
(
'%label'
=>
123
))
);
$role
=
entity_load
(
'user_role'
,
$role_name
);
$this
->
assertTrue
(
is_object
(
$role
),
'The role was successfully retrieved from the database.'
);
...
...
@@ -48,31 +48,31 @@ function testRoleAdministration() {
$this
->
assertEqual
(
$role
->
langcode
,
$default_langcode
);
// Try adding a duplicate role.
$this
->
drupalPost
(
NULL
,
$edit
,
t
(
'Add rol
e'
));
$this
->
drupalPost
(
'admin/people/roles/add'
,
$edit
,
t
(
'Sav
e'
));
$this
->
assertRaw
(
t
(
'The machine-readable name is already in use. It must be unique.'
),
'Duplicate role warning displayed.'
);
// Test renaming a role.
$old_name
=
$role_name
;
$role_name
=
'456'
;
$edit
=
array
(
'
role[label]
'
=>
$role_name
);
$this
->
drupalPost
(
"admin/people/roles/
edit/
{
$role
->
id
()
}
"
,
$edit
,
t
(
'Save rol
e'
));
$this
->
assert
Text
(
t
(
'The role has been renamed.'
),
'The role has been renamed.'
);
$edit
=
array
(
'
label
'
=>
$role_name
);
$this
->
drupalPost
(
"admin/people/roles/
manage/
{
$role
->
id
()
}
"
,
$edit
,
t
(
'Sav
e'
));
$this
->
assert
Raw
(
t
(
'Role %label has been updated.'
,
array
(
'%label'
=>
$role_name
))
);
$new_role
=
entity_load
(
'user_role'
,
$old_name
);
$this
->
assertEqual
(
$new_role
->
label
(),
$role_name
,
'The role name has been successfully changed.'
);
// Test deleting a role.
$this
->
drupalPost
(
"admin/people/roles/
edit/
{
$role
->
id
()
}
"
,
NULL
,
t
(
'Delete rol
e'
));
$this
->
drupalPost
(
NULL
,
NULL
,
t
(
'Delete'
));
$this
->
assert
Text
(
t
(
'The role has been deleted.'
),
'The role has been deleted'
);
$this
->
assertNoLinkByHref
(
"admin/people/roles/
edit
/
{
$role
->
id
()
}
"
,
'Role edit link removed.'
);
$this
->
drupalPost
(
"admin/people/roles/
manage/
{
$role
->
id
()
}
"
,
array
(),
t
(
'Delet
e'
));
$this
->
drupalPost
(
NULL
,
array
()
,
t
(
'Delete'
));
$this
->
assert
Raw
(
t
(
'Role %label has been deleted.'
,
array
(
'%label'
=>
$role_name
))
);
$this
->
assertNoLinkByHref
(
"admin/people/roles/
manage
/
{
$role
->
id
()
}
"
,
'Role edit link removed.'
);
$this
->
assertFalse
(
entity_load
(
'user_role'
,
$role_name
),
'A deleted role can no longer be loaded.'
);
// Make sure that the system-defined roles can be edited via the user
// interface.
$this
->
drupalGet
(
'admin/people/roles/
edit
/'
.
DRUPAL_ANONYMOUS_RID
);
$this
->
drupalGet
(
'admin/people/roles/
manage
/'
.
DRUPAL_ANONYMOUS_RID
);
$this
->
assertResponse
(
200
,
'Access granted when trying to edit the built-in anonymous role.'
);
$this
->
assertNoText
(
t
(
'Delete role'
),
'Delete button for the anonymous role is not present.'
);
$this
->
drupalGet
(
'admin/people/roles/
edit
/'
.
DRUPAL_AUTHENTICATED_RID
);
$this
->
drupalGet
(
'admin/people/roles/
manage
/'
.
DRUPAL_AUTHENTICATED_RID
);
$this
->
assertResponse
(
200
,
'Access granted when trying to edit the built-in authenticated role.'
);
$this
->
assertNoText
(
t
(
'Delete role'
),
'Delete button for the authenticated role is not present.'
);
}
...
...
@@ -90,7 +90,7 @@ function testRoleWeightOrdering() {
// Change the role weights to make the roles in reverse order.
$edit
=
array
();
foreach
(
$roles
as
$role
)
{
$edit
[
'
rol
es['
.
$role
->
id
()
.
'][weight]'
]
=
$weight
;
$edit
[
'
entiti
es['
.
$role
->
id
()
.
'][weight]'
]
=
$weight
;
$new_role_weights
[
$role
->
id
()]
=
$weight
;
$saved_rids
[]
=
$role
->
id
;
$weight
--
;
...
...
core/modules/user/user.admin.inc
View file @
0bdc4cc7
...
...
@@ -462,213 +462,31 @@ function theme_user_permission_description($variables) {
}
/**
*
Form to re-order roles or add a new one
.
*
Page callback: Lists roles and allows to reorder them
.
*
* @ingroup forms
* @see theme_user_admin_roles()
*/
function
user_admin_roles
(
$form
,
$form_state
)
{
$roles
=
user_roles
();
$form
[
'roles'
]
=
array
(
'#tree'
=>
TRUE
,
);
foreach
(
$roles
as
$rid
=>
$role
)
{
$form
[
'roles'
][
$rid
][
'#role'
]
=
$role
;
$form
[
'roles'
][
$rid
][
'#weight'
]
=
$role
->
weight
;
$form
[
'roles'
][
$rid
][
'name'
]
=
array
(
'#markup'
=>
check_plain
(
$role
->
label
()),
);
$form
[
'roles'
][
$rid
][
'weight'
]
=
array
(
'#type'
=>
'textfield'
,
'#title'
=>
t
(
'Weight for @title'
,
array
(
'@title'
=>
$role
->
label
())),
'#title_display'
=>
'invisible'
,
'#size'
=>
4
,
'#default_value'
=>
$role
->
weight
,
'#attributes'
=>
array
(
'class'
=>
array
(
'role-weight'
)),
);
$links
[
'edit'
]
=
array
(
'title'
=>
t
(
'Edit role'
),
'href'
=>
'admin/people/roles/edit/'
.
$rid
,
'weight'
=>
0
,
);
$links
[
'permissions'
]
=
array
(
'title'
=>
t
(
'Edit permissions'
),
'href'
=>
'admin/people/permissions/'
.
$rid
,
'weight'
=>
5
,
);
$form
[
'roles'
][
$rid
][
'operations'
]
=
array
(
'#type'
=>
'operations'
,
'#links'
=>
$links
,
);
}
// Embed the role add form.
$add_role
=
entity_create
(
'user_role'
,
array
(
'id'
=>
NULL
,
'label'
=>
NULL
,
));
$add_form
=
user_admin_role
(
array
(),
$form_state
,
$add_role
);
$add_form
[
'actions'
][
'submit'
][
'#submit'
]
=
array
(
'user_admin_role_submit'
);
$add_form
[
'role'
][
'actions'
]
=
$add_form
[
'actions'
];
unset
(
$add_form
[
'actions'
]);
$form
+=
$add_form
;
$form
[
'actions'
][
'#type'
]
=
'actions'
;
$form
[
'actions'
][
'submit'
]
=
array
(
'#type'
=>
'submit'
,
'#value'
=>
t
(
'Save order'
),
// Do not validate the add form when saving the order.
'#limit_validation_errors'
=>
array
(
array
(
'roles'
)),
'#submit'
=>
array
(
'user_admin_roles_order_submit'
),
);
return
$form
;
}
/**
* Form submit function. Update the role weights.
* @see user_menu()
*/
function
user_admin_roles_order_submit
(
$form
,
&
$form_state
)
{
foreach
(
$form_state
[
'values'
][
'roles'
]
as
$rid
=>
$role_values
)
{
$role
=
$form
[
'roles'
][
$rid
][
'#role'
];
$role
->
weight
=
$role_values
[
'weight'
];
$role
->
save
();
}
drupal_set_message
(
t
(
'The role settings have been updated.'
));
function
user_admin_roles_list
()
{
return
Drupal
::
entityManager
()
->
getListController
(
'user_role'
)
->
render
();
}
/**
* Returns HTML for the role order and new role form.
*
* @param $variables
* An associative array containing:
* - form: A render element representing the form.
* Page callback: Presents the role creation form.
*
* @
ingroup themeable
* @
see user_menu()
*/
function
theme_user_admin_roles
(
$variables
)
{
$form
=
$variables
[
'form'
];
$header
=
array
(
t
(
'Name'
),
t
(
'Weight'
),
t
(
'Operations'
));
foreach
(
element_children
(
$form
[
'roles'
])
as
$rid
)
{
$row
=
array
();
foreach
(
element_children
(
$form
[
'roles'
][
$rid
])
as
$column
)
{
$row
[]
=
drupal_render
(
$form
[
'roles'
][
$rid
][
$column
]);
}
$rows
[]
=
array
(
'data'
=>
$row
,
'class'
=>
array
(
'draggable'
));
}
// Distribute the role add form into table columns.
$form
[
'role'
][
'name'
][
'#title_display'
]
=
'invisible'
;
unset
(
$form
[
'role'
][
'name'
][
'#description'
]);
unset
(
$form
[
'role'
][
'rid'
][
'#description'
]);
$actions
=
$form
[
'role'
][
'actions'
];
unset
(
$form
[
'role'
][
'actions'
]);
unset
(
$form
[
'role'
][
'weight'
]);
$row
=
array
();
$row
[]
=
drupal_render
(
$form
[
'role'
]);
// Empty placeholder for the weight column.
$row
[]
=
''
;
$row
[]
=
array
(
'data'
=>
drupal_render
(
$actions
),
'colspan'
=>
2
);
$rows
[]
=
array
(
'data'
=>
$row
);
drupal_add_tabledrag
(
'user-roles'
,
'order'
,
'sibling'
,
'role-weight'
);
$output
=
theme
(
'table'
,
array
(
'header'
=>
$header
,
'rows'
=>
$rows
,
'attributes'
=>
array
(
'id'
=>
'user-roles'
)));
$output
.
=
drupal_render_children
(
$form
);
return
$output
;
}
/**
* Form to configure a single role.
*
* @ingroup forms
* @see user_admin_role_submit()
*
* @todo Move into a RoleFormController.
*/
function
user_admin_role
(
$form
,
$form_state
,
$role
)
{
$form
[
'role'
]
=
array
(
'#tree'
=>
TRUE
,
'#parents'
=>
array
(
'role'
),
);
$form
[
'role'
][
'label'
]
=
array
(
'#type'
=>
'textfield'
,
'#title'
=>
t
(
'Role name'
),
'#default_value'
=>
$role
->
label
(),
'#size'
=>
30
,
'#required'
=>
TRUE
,
'#maxlength'
=>
64
,
'#description'
=>
t
(
'The name for this role. Example: "Moderator", "Editorial board", "Site architect".'
),
);
$form
[
'role'
][
'id'
]
=
array
(
'#type'
=>
'machine_name'
,
'#default_value'
=>
$role
->
id
(),
'#required'
=>
TRUE
,
'#disabled'
=>
!
$role
->
isNew
(),
'#size'
=>
30
,
'#maxlength'
=>
64
,
'#machine_name'
=>
array
(
'exists'
=>
'user_role_load'
,
'source'
=>
array
(
'role'
,
'label'
),
),
);
// @todo Remove once moved to RoleFormController.
$form
[
'role'
][
'langcode'
]
=
array
(
'#type'
=>
'value'
,
'#value'
=>
!
$role
->
isNew
()
?
$role
->
langcode
:
language_default
()
->
langcode
,
);
$form
[
'role'
][
'weight'
]
=
array
(
'#type'
=>
'value'
,
'#value'
=>
$role
->
weight
,
);
$form
[
'actions'
]
=
array
(
'#type'
=>
'actions'
);
$form
[
'actions'
][
'submit'
]
=
array
(
'#type'
=>
'submit'
,
'#value'
=>
!
$role
->
isNew
()
?
t
(
'Save role'
)
:
t
(
'Add role'
),
);
$form
[
'actions'
][
'delete'
]
=
array
(
'#type'
=>
'submit'
,
'#value'
=>
t
(
'Delete role'
),
'#access'
=>
!
$role
->
isNew
()
&&
!
in_array
(
$role
->
id
(),
array
(
DRUPAL_ANONYMOUS_RID
,
DRUPAL_AUTHENTICATED_RID
)),
'#submit'
=>
array
(
'user_admin_role_delete_submit'
),
);
return
$form
;
}
/**
* Form submit handler for the user_admin_role() form.
*/
function
user_admin_role_submit
(
$form
,
&
$form_state
)
{
// Prevent leading and trailing spaces in role names.
$form_state
[
'values'
][
'role'
][
'label'
]
=
trim
(
$form_state
[
'values'
][
'role'
][
'label'
]);
$role
=
entity_create
(
'user_role'
,
$form_state
[
'values'
][
'role'
]);
if
(
$role
->
save
()
==
SAVED_UPDATED
)
{
drupal_set_message
(
t
(
'The role has been renamed.'
));
}
else
{
drupal_set_message
(
t
(
'The role has been added.'
));
}
$form_state
[
'redirect'
]
=
'admin/people/roles'
;
}
/**
* Form submit handler for the user_admin_role() form.
*/
function
user_admin_role_delete_submit
(
$form
,
&
$form_state
)
{
$form_state
[
'redirect'
]
=
'admin/people/roles/delete/'
.
$form_state
[
'values'
][
'role'
][
'id'
];
function
user_admin_role_add
()
{
drupal_set_title
(
t
(
'Add role'
));
$role
=
entity_create
(
'user_role'
,
array
());
return
entity_get_form
(
$role
);
}
/**
* Form to confirm role delete operation.
*/
function
user_admin_role_delete_confirm
(
$form
,
&
$form_state
,
$role
)
{
$form_state
[
'user_role'
]
=
$role
;
$form
[
'id'
]
=
array
(
'#type'
=>
'value'
,
'#value'
=>
$role
->
id
(),
...
...
@@ -680,7 +498,11 @@ function user_admin_role_delete_confirm($form, &$form_state, $role) {
* Form submit handler for user_admin_role_delete_confirm().
*/
function
user_admin_role_delete_confirm_submit
(
$form
,
&
$form_state
)
{