2007-09-10 13:14:38 +00:00
< ? php
/**
* @ file
* Admin page callback file for the user module .
*/
function user_admin ( $callback_arg = '' ) {
$op = isset ( $_POST [ 'op' ]) ? $_POST [ 'op' ] : $callback_arg ;
switch ( $op ) {
case t ( 'Create new account' ) :
case 'create' :
2012-08-16 11:30:43 +00:00
$account = entity_create ( 'user' , array ());
$build [ 'user_register' ] = entity_get_form ( $account , 'register' );
2007-09-10 13:14:38 +00:00
break ;
default :
2009-01-08 08:42:13 +00:00
if ( ! empty ( $_POST [ 'accounts' ]) && isset ( $_POST [ 'operation' ]) && ( $_POST [ 'operation' ] == 'cancel' )) {
2009-05-12 08:37:45 +00:00
$build [ 'user_multiple_cancel_confirm' ] = drupal_get_form ( 'user_multiple_cancel_confirm' );
2007-09-10 13:14:38 +00:00
}
else {
2009-05-12 08:37:45 +00:00
$build [ 'user_filter_form' ] = drupal_get_form ( 'user_filter_form' );
$build [ 'user_admin_account' ] = drupal_get_form ( 'user_admin_account' );
2007-09-10 13:14:38 +00:00
}
}
2009-05-12 08:37:45 +00:00
return $build ;
2007-09-10 13:14:38 +00:00
}
/**
* Form builder ; Return form for user administration filters .
2007-10-02 16:03:17 +00:00
*
2007-09-10 13:14:38 +00:00
* @ ingroup forms
2008-01-08 10:35:43 +00:00
* @ see user_filter_form_submit ()
2007-09-10 13:14:38 +00:00
*/
function user_filter_form () {
2009-06-02 06:58:17 +00:00
$session = isset ( $_SESSION [ 'user_overview_filter' ]) ? $_SESSION [ 'user_overview_filter' ] : array ();
2007-09-10 13:14:38 +00:00
$filters = user_filters ();
$i = 0 ;
2007-12-23 13:17:20 +00:00
$form [ 'filters' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2007-12-23 13:17:20 +00:00
'#title' => t ( 'Show only users where' ),
2010-09-17 14:53:22 +00:00
'#theme' => 'exposed_filters__user' ,
2007-12-23 13:17:20 +00:00
);
2007-09-10 13:14:38 +00:00
foreach ( $session as $filter ) {
list ( $type , $value ) = $filter ;
2009-11-17 02:50:41 +00:00
if ( $type == 'permission' ) {
// Merge arrays of module permissions into one.
// Slice past the first element '[any]' whose value is not an array.
$options = call_user_func_array ( 'array_merge' , array_slice ( $filters [ $type ][ 'options' ], 1 ));
$value = $options [ $value ];
}
else {
$value = $filters [ $type ][ 'options' ][ $value ];
}
2010-09-17 14:53:22 +00:00
$t_args = array ( '%property' => $filters [ $type ][ 'title' ], '%value' => $value );
2009-11-17 02:50:41 +00:00
if ( $i ++ ) {
2010-09-17 14:53:22 +00:00
$form [ 'filters' ][ 'current' ][] = array ( '#markup' => t ( 'and where %property is %value' , $t_args ));
2007-09-12 11:39:38 +00:00
}
else {
2010-09-17 14:53:22 +00:00
$form [ 'filters' ][ 'current' ][] = array ( '#markup' => t ( '%property is %value' , $t_args ));
2007-09-12 11:39:38 +00:00
}
2007-09-10 13:14:38 +00:00
}
2010-09-17 14:53:22 +00:00
$form [ 'filters' ][ 'status' ] = array (
'#type' => 'container' ,
'#attributes' => array ( 'class' => array ( 'clearfix' )),
'#prefix' => ( $i ? '<div class="additional-filters">' . t ( 'and where' ) . '</div>' : '' ),
);
$form [ 'filters' ][ 'status' ][ 'filters' ] = array (
'#type' => 'container' ,
'#attributes' => array ( 'class' => array ( 'filters' )),
);
2007-09-10 13:14:38 +00:00
foreach ( $filters as $key => $filter ) {
2010-09-17 14:53:22 +00:00
$form [ 'filters' ][ 'status' ][ 'filters' ][ $key ] = array (
2007-12-23 13:17:20 +00:00
'#type' => 'select' ,
'#options' => $filter [ 'options' ],
2009-11-17 02:50:41 +00:00
'#title' => $filter [ 'title' ],
'#default_value' => '[any]' ,
2007-12-23 13:17:20 +00:00
);
2007-09-10 13:14:38 +00:00
}
2010-09-17 14:53:22 +00:00
$form [ 'filters' ][ 'status' ][ 'actions' ] = array (
2010-04-24 14:49:14 +00:00
'#type' => 'actions' ,
'#attributes' => array ( 'class' => array ( 'container-inline' )),
2010-01-03 21:01:04 +00:00
);
2010-09-17 14:53:22 +00:00
$form [ 'filters' ][ 'status' ][ 'actions' ][ 'submit' ] = array (
2007-12-23 13:17:20 +00:00
'#type' => 'submit' ,
'#value' => ( count ( $session ) ? t ( 'Refine' ) : t ( 'Filter' )),
);
2007-09-10 13:14:38 +00:00
if ( count ( $session )) {
2010-09-17 14:53:22 +00:00
$form [ 'filters' ][ 'status' ][ 'actions' ][ 'undo' ] = array (
2007-12-23 13:17:20 +00:00
'#type' => 'submit' ,
'#value' => t ( 'Undo' ),
);
2010-09-17 14:53:22 +00:00
$form [ 'filters' ][ 'status' ][ 'actions' ][ 'reset' ] = array (
2007-12-23 13:17:20 +00:00
'#type' => 'submit' ,
'#value' => t ( 'Reset' ),
);
2007-09-10 13:14:38 +00:00
}
2010-12-15 02:59:01 +00:00
drupal_add_library ( 'system' , 'drupal.form' );
2010-07-07 17:56:42 +00:00
2007-09-10 13:14:38 +00:00
return $form ;
}
/**
* Process result from user administration filter form .
*/
function user_filter_form_submit ( $form , & $form_state ) {
$op = $form_state [ 'values' ][ 'op' ];
$filters = user_filters ();
switch ( $op ) {
2009-11-17 02:50:41 +00:00
case t ( 'Filter' ) :
case t ( 'Refine' ) :
// Apply every filter that has a choice selected other than 'any'.
foreach ( $filters as $filter => $options ) {
if ( isset ( $form_state [ 'values' ][ $filter ]) && $form_state [ 'values' ][ $filter ] != '[any]' ) {
2011-11-30 02:13:33 +00:00
$_SESSION [ 'user_overview_filter' ][] = array ( $filter , $form_state [ 'values' ][ $filter ]);
2007-09-10 13:14:38 +00:00
}
}
break ;
case t ( 'Undo' ) :
array_pop ( $_SESSION [ 'user_overview_filter' ]);
break ;
case t ( 'Reset' ) :
2009-06-02 06:58:17 +00:00
$_SESSION [ 'user_overview_filter' ] = array ();
2007-09-10 13:14:38 +00:00
break ;
case t ( 'Update' ) :
return ;
}
2009-08-11 11:47:58 +00:00
$form_state [ 'redirect' ] = 'admin/people' ;
2007-09-10 13:14:38 +00:00
return ;
}
/**
* Form builder ; User administration page .
*
* @ ingroup forms
2008-01-08 10:35:43 +00:00
* @ see user_admin_account_validate ()
* @ see user_admin_account_submit ()
2007-09-10 13:14:38 +00:00
*/
function user_admin_account () {
$header = array (
2009-10-08 18:26:33 +00:00
'username' => array ( 'data' => t ( 'Username' ), 'field' => 'u.name' ),
2012-09-26 18:26:15 +00:00
'status' => array ( 'data' => t ( 'Status' ), 'field' => 'u.status' , 'class' => array ( RESPONSIVE_PRIORITY_LOW )),
'roles' => array ( 'data' => t ( 'Roles' ), 'class' => array ( RESPONSIVE_PRIORITY_LOW )),
'member_for' => array ( 'data' => t ( 'Member for' ), 'field' => 'u.created' , 'sort' => 'desc' , 'class' => array ( RESPONSIVE_PRIORITY_LOW )),
'access' => array ( 'data' => t ( 'Last access' ), 'field' => 'u.access' , 'class' => array ( RESPONSIVE_PRIORITY_LOW )),
2012-10-09 19:49:07 +00:00
'operations' => t ( 'Operations' ),
2007-09-10 13:14:38 +00:00
);
2009-04-13 12:14:57 +00:00
$query = db_select ( 'users' , 'u' );
2009-04-30 16:10:10 +00:00
$query -> condition ( 'u.uid' , 0 , '<>' );
user_build_filter_query ( $query );
2009-05-24 17:39:35 +00:00
2009-04-30 16:10:10 +00:00
$count_query = clone $query ;
2010-01-12 06:18:58 +00:00
$count_query -> addExpression ( 'COUNT(u.uid)' );
2009-04-30 16:10:10 +00:00
2012-06-05 05:42:19 +00:00
$query = $query
-> extend ( 'Drupal\Core\Database\Query\PagerSelectExtender' )
2012-06-08 12:26:56 +00:00
-> extend ( 'Drupal\Core\Database\Query\TableSortExtender' );
2009-04-30 16:10:10 +00:00
$query
-> fields ( 'u' , array ( 'uid' , 'name' , 'status' , 'created' , 'access' ))
-> limit ( 50 )
2009-05-22 11:33:18 +00:00
-> orderByHeader ( $header )
2009-04-30 16:10:10 +00:00
-> setCountQuery ( $count_query );
$result = $query -> execute ();
2007-09-10 13:14:38 +00:00
$form [ 'options' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2007-09-10 13:14:38 +00:00
'#title' => t ( 'Update options' ),
2010-03-03 19:46:26 +00:00
'#attributes' => array ( 'class' => array ( 'container-inline' )),
2007-09-10 13:14:38 +00:00
);
$options = array ();
foreach ( module_invoke_all ( 'user_operations' ) as $operation => $array ) {
$options [ $operation ] = $array [ 'label' ];
}
$form [ 'options' ][ 'operation' ] = array (
'#type' => 'select' ,
2010-10-20 01:31:07 +00:00
'#title' => t ( 'Operation' ),
'#title_display' => 'invisible' ,
2007-09-10 13:14:38 +00:00
'#options' => $options ,
'#default_value' => 'unblock' ,
);
2009-10-08 18:26:33 +00:00
$options = array ();
2007-09-10 13:14:38 +00:00
$form [ 'options' ][ 'submit' ] = array (
'#type' => 'submit' ,
'#value' => t ( 'Update' ),
);
$destination = drupal_get_destination ();
$status = array ( t ( 'blocked' ), t ( 'active' ));
2010-04-23 05:39:43 +00:00
$roles = array_map ( 'check_plain' , user_roles ( TRUE ));
2007-09-10 13:14:38 +00:00
$accounts = array ();
2009-04-13 12:14:57 +00:00
foreach ( $result as $account ) {
2012-11-22 16:03:57 +00:00
$account = user_load ( $account -> uid );
2009-02-26 07:30:29 +00:00
$users_roles = array ();
2009-04-13 12:14:57 +00:00
$roles_result = db_query ( 'SELECT rid FROM {users_roles} WHERE uid = :uid' , array ( ':uid' => $account -> uid ));
foreach ( $roles_result as $user_role ) {
2009-02-26 07:30:29 +00:00
$users_roles [] = $roles [ $user_role -> rid ];
2007-09-10 13:14:38 +00:00
}
2009-02-26 07:30:29 +00:00
asort ( $users_roles );
2009-12-02 17:04:25 +00:00
2009-10-08 18:26:33 +00:00
$options [ $account -> uid ] = array (
2009-10-09 01:00:08 +00:00
'username' => theme ( 'username' , array ( 'account' => $account )),
2009-10-08 18:26:33 +00:00
'status' => $status [ $account -> status ],
2009-10-09 01:00:08 +00:00
'roles' => theme ( 'item_list' , array ( 'items' => $users_roles )),
2009-10-08 18:26:33 +00:00
'member_for' => format_interval ( REQUEST_TIME - $account -> created ),
'access' => $account -> access ? t ( '@time ago' , array ( '@time' => format_interval ( REQUEST_TIME - $account -> access ))) : t ( 'never' ),
2012-10-09 19:49:07 +00:00
);
$links = array ();
$links [ 'edit' ] = array (
'title' => t ( 'edit' ),
2012-11-22 16:03:57 +00:00
'href' => 'user/' . $account -> uid . '/edit' ,
2012-10-09 19:49:07 +00:00
'query' => $destination ,
);
2012-11-22 16:03:57 +00:00
if ( module_invoke ( 'translation_entity' , 'translate_access' , $account )) {
$links [ 'translate' ] = array (
'title' => t ( 'translate' ),
'href' => 'user/' . $account -> uid . '/translations' ,
'query' => $destination ,
);
}
2012-10-09 19:49:07 +00:00
$options [ $account -> uid ][ 'operations' ][ 'data' ] = array (
'#type' => 'operations' ,
'#links' => $links ,
2009-10-08 18:26:33 +00:00
);
2007-09-10 13:14:38 +00:00
}
2009-12-02 17:04:25 +00:00
2007-09-10 13:14:38 +00:00
$form [ 'accounts' ] = array (
2009-10-08 18:26:33 +00:00
'#type' => 'tableselect' ,
'#header' => $header ,
'#options' => $options ,
'#empty' => t ( 'No people available.' ),
2007-09-10 13:14:38 +00:00
);
2010-10-06 13:38:40 +00:00
$form [ 'pager' ] = array ( '#markup' => theme ( 'pager' ));
2007-09-10 13:14:38 +00:00
return $form ;
}
/**
* Submit the user administration update form .
*/
function user_admin_account_submit ( $form , & $form_state ) {
2009-09-18 00:12:48 +00:00
$operations = module_invoke_all ( 'user_operations' , $form , $form_state );
2007-09-10 13:14:38 +00:00
$operation = $operations [ $form_state [ 'values' ][ 'operation' ]];
// Filter out unchecked accounts.
$accounts = array_filter ( $form_state [ 'values' ][ 'accounts' ]);
if ( $function = $operation [ 'callback' ]) {
// Add in callback arguments if present.
if ( isset ( $operation [ 'callback arguments' ])) {
$args = array_merge ( array ( $accounts ), $operation [ 'callback arguments' ]);
}
else {
$args = array ( $accounts );
}
call_user_func_array ( $function , $args );
drupal_set_message ( t ( 'The update has been performed.' ));
}
}
function user_admin_account_validate ( $form , & $form_state ) {
$form_state [ 'values' ][ 'accounts' ] = array_filter ( $form_state [ 'values' ][ 'accounts' ]);
if ( count ( $form_state [ 'values' ][ 'accounts' ]) == 0 ) {
form_set_error ( '' , t ( 'No users selected.' ));
}
}
/**
* Form builder ; Configure user settings for this site .
*
* @ ingroup forms
2012-08-26 21:15:58 +00:00
* @ see user_admin_settings_submit ()
2007-09-10 13:14:38 +00:00
*/
2012-08-26 21:15:58 +00:00
function user_admin_settings ( $form , & $form_state ) {
$config = config ( 'user.settings' );
2012-09-13 06:41:38 +00:00
$mail_config = config ( 'user.mail' );
2009-05-16 20:10:50 +00:00
// Settings for anonymous users.
$form [ 'anonymous_settings' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Anonymous users' ),
);
$form [ 'anonymous_settings' ][ 'anonymous' ] = array (
'#type' => 'textfield' ,
'#title' => t ( 'Name' ),
2012-08-26 21:15:58 +00:00
'#default_value' => $config -> get ( 'anonymous' ),
2009-05-16 20:10:50 +00:00
'#description' => t ( 'The name used to indicate anonymous users.' ),
'#required' => TRUE ,
);
2007-09-10 13:14:38 +00:00
2009-06-04 09:52:33 +00:00
// Administrative role option.
$form [ 'admin_role' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2009-06-04 20:09:29 +00:00
'#title' => t ( 'Administrator role' ),
2009-06-04 09:52:33 +00:00
);
2009-06-04 20:09:29 +00:00
// Do not allow users to set the anonymous or authenticated user roles as the
2009-06-04 09:52:33 +00:00
// administrator role.
$roles = user_roles ();
2009-06-06 14:51:56 +00:00
unset ( $roles [ DRUPAL_ANONYMOUS_RID ]);
unset ( $roles [ DRUPAL_AUTHENTICATED_RID ]);
2009-06-04 09:52:33 +00:00
$roles [ 0 ] = t ( 'disabled' );
$form [ 'admin_role' ][ 'user_admin_role' ] = array (
'#type' => 'select' ,
'#title' => t ( 'Administrator role' ),
2012-08-26 21:15:58 +00:00
'#default_value' => $config -> get ( 'admin_role' ),
2009-06-04 09:52:33 +00:00
'#options' => $roles ,
'#description' => t ( 'This role will be automatically assigned new permissions whenever a module is enabled. Changing this setting will not affect existing permissions.' ),
);
Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
// @todo Remove this check once language settings are generalized.
if ( module_exists ( 'translation_entity' )) {
$form [ 'language' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
Issue #1188388 by plach, peximo, YesCT | Gábor Hojtsy, fago, webchick, Bojhan, podarok, cosmicdreams, Berdir, aspilicious, bforchhammer, penyaskito: Added Entity translation UI in core.
2012-11-04 02:38:49 +00:00
'#title' => t ( 'Language settings' ),
'#tree' => TRUE ,
);
$form_state [ 'translation_entity' ][ 'key' ] = 'language' ;
$form [ 'language' ] += translation_entity_enable_widget ( 'user' , 'user' , $form , $form_state );
}
2009-05-16 20:10:50 +00:00
// User registration settings.
$form [ 'registration_cancellation' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Registration and cancellation' ),
);
$form [ 'registration_cancellation' ][ 'user_register' ] = array (
'#type' => 'radios' ,
'#title' => t ( 'Who can register accounts?' ),
2012-08-26 21:15:58 +00:00
'#default_value' => $config -> get ( 'register' ),
2009-05-16 20:10:50 +00:00
'#options' => array (
2010-05-27 12:29:39 +00:00
USER_REGISTER_ADMINISTRATORS_ONLY => t ( 'Administrators only' ),
USER_REGISTER_VISITORS => t ( 'Visitors' ),
USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL => t ( 'Visitors, but administrator approval is required' ),
2009-05-16 20:10:50 +00:00
)
);
$form [ 'registration_cancellation' ][ 'user_email_verification' ] = array (
'#type' => 'checkbox' ,
'#title' => t ( 'Require e-mail verification when a visitor creates an account.' ),
2012-08-26 21:15:58 +00:00
'#default_value' => $config -> get ( 'verify_mail' ),
2009-09-19 11:18:32 +00:00
'#description' => t ( 'New users will be required to validate their e-mail address prior to logging into the site, and will be assigned a system-generated password. With this setting disabled, users will be logged in immediately upon registering, and may select their own passwords during registration.' )
2009-01-08 08:42:13 +00:00
);
2009-05-16 20:10:50 +00:00
module_load_include ( 'inc' , 'user' , 'user.pages' );
$form [ 'registration_cancellation' ][ 'user_cancel_method' ] = array (
2009-01-08 08:42:13 +00:00
'#type' => 'item' ,
'#title' => t ( 'When cancelling a user account' ),
2012-10-29 23:09:48 +00:00
'#default_value' => $config -> get ( 'cancel_method' ),
2010-02-07 17:29:09 +00:00
'#description' => t ( 'Users with the %select-cancel-method or %administer-users <a href="@permissions-url">permissions</a> can override this default method.' , array ( '%select-cancel-method' => t ( 'Select method for cancelling account' ), '%administer-users' => t ( 'Administer users' ), '@permissions-url' => url ( 'admin/people/permissions' ))),
2009-01-08 08:42:13 +00:00
);
2009-05-16 20:10:50 +00:00
$form [ 'registration_cancellation' ][ 'user_cancel_method' ] += user_cancel_methods ();
foreach ( element_children ( $form [ 'registration_cancellation' ][ 'user_cancel_method' ]) as $element ) {
2009-01-08 08:42:13 +00:00
// Remove all account cancellation methods that have #access defined, as
// those cannot be configured as default method.
2009-05-16 20:10:50 +00:00
if ( isset ( $form [ 'registration_cancellation' ][ 'user_cancel_method' ][ $element ][ '#access' ])) {
$form [ 'registration_cancellation' ][ 'user_cancel_method' ][ $element ][ '#access' ] = FALSE ;
2009-01-08 08:42:13 +00:00
}
// Remove the description (only displayed on the confirmation form).
else {
2009-05-16 20:10:50 +00:00
unset ( $form [ 'registration_cancellation' ][ 'user_cancel_method' ][ $element ][ '#description' ]);
2009-01-08 08:42:13 +00:00
}
}
2009-05-16 20:10:50 +00:00
// Account settings.
$form [ 'personalization' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Personalization' ),
);
$form [ 'personalization' ][ 'user_signatures' ] = array (
'#type' => 'checkbox' ,
'#title' => t ( 'Enable signatures.' ),
2012-08-26 21:15:58 +00:00
'#default_value' => $config -> get ( 'signatures' ),
2009-05-16 20:10:50 +00:00
);
$form [ 'email_title' ] = array (
'#type' => 'item' ,
'#title' => t ( 'E-mails' ),
);
$form [ 'email' ] = array (
'#type' => 'vertical_tabs' ,
2007-09-10 13:14:38 +00:00
);
// These email tokens are shared for all settings, so just define
// the list once to help ensure they stay in sync.
2010-06-28 03:25:21 +00:00
$email_token_help = t ( 'Available variables are: [site:name], [site:url], [user:name], [user:mail], [site:login-url], [site:url-brief], [user:edit-url], [user:one-time-login-url], [user:cancel-url].' );
2007-09-10 13:14:38 +00:00
2009-05-16 20:10:50 +00:00
$form [ 'email_admin_created' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Welcome (new user created by administrator)' ),
2007-09-10 13:14:38 +00:00
'#collapsible' => TRUE ,
2012-08-26 21:15:58 +00:00
'#collapsed' => ( $config -> get ( 'register' ) != USER_REGISTER_ADMINISTRATORS_ONLY ),
2010-01-14 04:04:30 +00:00
'#description' => t ( 'Edit the welcome e-mail messages sent to new member accounts created by an administrator.' ) . ' ' . $email_token_help ,
2009-05-16 20:10:50 +00:00
'#group' => 'email' ,
2007-09-10 13:14:38 +00:00
);
2009-05-16 20:10:50 +00:00
$form [ 'email_admin_created' ][ 'user_mail_register_admin_created_subject' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Subject' ),
2012-09-13 06:41:38 +00:00
'#default_value' => $mail_config -> get ( 'register_admin_created.subject' ),
2007-09-10 13:14:38 +00:00
'#maxlength' => 180 ,
);
2009-05-16 20:10:50 +00:00
$form [ 'email_admin_created' ][ 'user_mail_register_admin_created_body' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textarea' ,
'#title' => t ( 'Body' ),
2012-09-13 06:41:38 +00:00
'#default_value' => $mail_config -> get ( 'register_admin_created.body' ),
2007-09-10 13:14:38 +00:00
'#rows' => 15 ,
);
2009-06-28 20:51:09 +00:00
$form [ 'email_pending_approval' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2009-06-28 20:51:09 +00:00
'#title' => t ( 'Welcome (awaiting approval)' ),
2007-09-10 13:14:38 +00:00
'#collapsible' => TRUE ,
2012-08-26 21:15:58 +00:00
'#collapsed' => ( $config -> get ( 'register' ) != USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL ),
2010-01-14 04:04:30 +00:00
'#description' => t ( 'Edit the welcome e-mail messages sent to new members upon registering, when administrative approval is required.' ) . ' ' . $email_token_help ,
2009-05-16 20:10:50 +00:00
'#group' => 'email' ,
2007-09-10 13:14:38 +00:00
);
2009-06-28 20:51:09 +00:00
$form [ 'email_pending_approval' ][ 'user_mail_register_pending_approval_subject' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Subject' ),
2012-09-13 06:41:38 +00:00
'#default_value' => $mail_config -> get ( 'register_pending_approval.subject' ),
2007-09-10 13:14:38 +00:00
'#maxlength' => 180 ,
);
2009-06-28 20:51:09 +00:00
$form [ 'email_pending_approval' ][ 'user_mail_register_pending_approval_body' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textarea' ,
'#title' => t ( 'Body' ),
2012-09-13 06:41:38 +00:00
'#default_value' => $mail_config -> get ( 'register_pending_approval.body' ),
2009-06-28 20:51:09 +00:00
'#rows' => 8 ,
2007-09-10 13:14:38 +00:00
);
2009-06-28 20:51:09 +00:00
$form [ 'email_no_approval_required' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2009-06-28 20:51:09 +00:00
'#title' => t ( 'Welcome (no approval required)' ),
2007-09-10 13:14:38 +00:00
'#collapsible' => TRUE ,
2012-08-26 21:15:58 +00:00
'#collapsed' => ( $config -> get ( 'register' ) != USER_REGISTER_VISITORS ),
2010-01-14 04:04:30 +00:00
'#description' => t ( 'Edit the welcome e-mail messages sent to new members upon registering, when no administrator approval is required.' ) . ' ' . $email_token_help ,
2009-05-16 20:10:50 +00:00
'#group' => 'email' ,
2007-09-10 13:14:38 +00:00
);
2009-06-28 20:51:09 +00:00
$form [ 'email_no_approval_required' ][ 'user_mail_register_no_approval_required_subject' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Subject' ),
2012-09-13 06:41:38 +00:00
'#default_value' => $mail_config -> get ( 'register_no_approval_required.subject' ),
2007-09-10 13:14:38 +00:00
'#maxlength' => 180 ,
);
2009-06-28 20:51:09 +00:00
$form [ 'email_no_approval_required' ][ 'user_mail_register_no_approval_required_body' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textarea' ,
'#title' => t ( 'Body' ),
2012-09-13 06:41:38 +00:00
'#default_value' => $mail_config -> get ( 'register_no_approval_required.body' ),
2009-06-28 20:51:09 +00:00
'#rows' => 15 ,
2007-09-10 13:14:38 +00:00
);
2009-07-12 08:36:35 +00:00
2009-05-16 20:10:50 +00:00
$form [ 'email_password_reset' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Password recovery' ),
2007-09-10 13:14:38 +00:00
'#collapsible' => TRUE ,
'#collapsed' => TRUE ,
2010-01-14 04:04:30 +00:00
'#description' => t ( 'Edit the e-mail messages sent to users who request a new password.' ) . ' ' . $email_token_help ,
2009-05-16 20:10:50 +00:00
'#group' => 'email' ,
'#weight' => 10 ,
2007-09-10 13:14:38 +00:00
);
2009-05-16 20:10:50 +00:00
$form [ 'email_password_reset' ][ 'user_mail_password_reset_subject' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Subject' ),
2012-09-13 06:41:38 +00:00
'#default_value' => $mail_config -> get ( 'password_reset.subject' ),
2007-09-10 13:14:38 +00:00
'#maxlength' => 180 ,
);
2009-05-16 20:10:50 +00:00
$form [ 'email_password_reset' ][ 'user_mail_password_reset_body' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textarea' ,
'#title' => t ( 'Body' ),
2012-09-13 06:41:38 +00:00
'#default_value' => $mail_config -> get ( 'password_reset.body' ),
2007-09-10 13:14:38 +00:00
'#rows' => 12 ,
);
2009-05-16 20:10:50 +00:00
$form [ 'email_activated' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Account activation' ),
2007-09-10 13:14:38 +00:00
'#collapsible' => TRUE ,
'#collapsed' => TRUE ,
2010-01-14 04:04:30 +00:00
'#description' => t ( 'Enable and edit e-mail messages sent to users upon account activation (when an administrator activates an account of a user who has already registered, on a site where administrative approval is required).' ) . ' ' . $email_token_help ,
2009-05-16 20:10:50 +00:00
'#group' => 'email' ,
2007-09-10 13:14:38 +00:00
);
2009-05-16 20:10:50 +00:00
$form [ 'email_activated' ][ 'user_mail_status_activated_notify' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'checkbox' ,
'#title' => t ( 'Notify user when account is activated.' ),
2012-08-26 21:15:58 +00:00
'#default_value' => $config -> get ( 'notify.status_activated' ),
2007-09-10 13:14:38 +00:00
);
2009-10-16 19:20:34 +00:00
$form [ 'email_activated' ][ 'settings' ] = array (
'#type' => 'container' ,
'#states' => array (
// Hide the additional settings when this email is disabled.
'invisible' => array (
'input[name="user_mail_status_activated_notify"]' => array ( 'checked' => FALSE ),
),
),
);
$form [ 'email_activated' ][ 'settings' ][ 'user_mail_status_activated_subject' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Subject' ),
2012-09-13 06:41:38 +00:00
'#default_value' => $mail_config -> get ( 'status_activated.subject' ),
2007-09-10 13:14:38 +00:00
'#maxlength' => 180 ,
);
2009-10-16 19:20:34 +00:00
$form [ 'email_activated' ][ 'settings' ][ 'user_mail_status_activated_body' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textarea' ,
'#title' => t ( 'Body' ),
2012-09-13 06:41:38 +00:00
'#default_value' => $mail_config -> get ( 'status_activated.body' ),
2007-09-10 13:14:38 +00:00
'#rows' => 15 ,
);
2009-05-16 20:10:50 +00:00
$form [ 'email_blocked' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Account blocked' ),
2007-09-10 13:14:38 +00:00
'#collapsible' => TRUE ,
'#collapsed' => TRUE ,
2010-01-14 04:04:30 +00:00
'#description' => t ( 'Enable and edit e-mail messages sent to users when their accounts are blocked.' ) . ' ' . $email_token_help ,
2009-05-16 20:10:50 +00:00
'#group' => 'email' ,
2007-09-10 13:14:38 +00:00
);
2009-05-16 20:10:50 +00:00
$form [ 'email_blocked' ][ 'user_mail_status_blocked_notify' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'checkbox' ,
'#title' => t ( 'Notify user when account is blocked.' ),
2012-08-26 21:15:58 +00:00
'#default_value' => $config -> get ( 'notify.status_blocked' ),
2007-09-10 13:14:38 +00:00
);
2009-10-16 19:20:34 +00:00
$form [ 'email_blocked' ][ 'settings' ] = array (
'#type' => 'container' ,
'#states' => array (
// Hide the additional settings when the blocked email is disabled.
'invisible' => array (
'input[name="user_mail_status_blocked_notify"]' => array ( 'checked' => FALSE ),
),
),
);
$form [ 'email_blocked' ][ 'settings' ][ 'user_mail_status_blocked_subject' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Subject' ),
2012-09-13 06:41:38 +00:00
'#default_value' => $mail_config -> get ( 'status_blocked.subject' ),
2007-09-10 13:14:38 +00:00
'#maxlength' => 180 ,
);
2009-10-16 19:20:34 +00:00
$form [ 'email_blocked' ][ 'settings' ][ 'user_mail_status_blocked_body' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textarea' ,
'#title' => t ( 'Body' ),
2012-09-13 06:41:38 +00:00
'#default_value' => $mail_config -> get ( 'status_blocked.body' ),
2007-09-10 13:14:38 +00:00
'#rows' => 3 ,
);
2009-05-16 20:10:50 +00:00
$form [ 'email_cancel_confirm' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Account cancellation confirmation' ),
2009-01-08 08:42:13 +00:00
'#collapsible' => TRUE ,
'#collapsed' => TRUE ,
2010-01-14 04:04:30 +00:00
'#description' => t ( 'Edit the e-mail messages sent to users when they attempt to cancel their accounts.' ) . ' ' . $email_token_help ,
2009-05-16 20:10:50 +00:00
'#group' => 'email' ,
2009-01-08 08:42:13 +00:00
);
2009-05-16 20:10:50 +00:00
$form [ 'email_cancel_confirm' ][ 'user_mail_cancel_confirm_subject' ] = array (
2009-01-08 08:42:13 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Subject' ),
2012-09-13 06:41:38 +00:00
'#default_value' => $mail_config -> get ( 'cancel_confirm.subject' ),
2009-01-08 08:42:13 +00:00
'#maxlength' => 180 ,
);
2009-05-16 20:10:50 +00:00
$form [ 'email_cancel_confirm' ][ 'user_mail_cancel_confirm_body' ] = array (
2009-01-08 08:42:13 +00:00
'#type' => 'textarea' ,
'#title' => t ( 'Body' ),
2012-09-13 06:41:38 +00:00
'#default_value' => $mail_config -> get ( 'cancel_confirm.body' ),
2009-01-08 08:42:13 +00:00
'#rows' => 3 ,
);
2009-05-16 20:10:50 +00:00
$form [ 'email_canceled' ] = array (
2012-11-27 07:06:47 +00:00
'#type' => 'details' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Account canceled' ),
2007-09-10 13:14:38 +00:00
'#collapsible' => TRUE ,
'#collapsed' => TRUE ,
2010-01-14 04:04:30 +00:00
'#description' => t ( 'Enable and edit e-mail messages sent to users when their accounts are canceled.' ) . ' ' . $email_token_help ,
2009-05-16 20:10:50 +00:00
'#group' => 'email' ,
2007-09-10 13:14:38 +00:00
);
2009-05-16 20:10:50 +00:00
$form [ 'email_canceled' ][ 'user_mail_status_canceled_notify' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'checkbox' ,
2009-01-08 08:42:13 +00:00
'#title' => t ( 'Notify user when account is canceled.' ),
2012-08-26 21:15:58 +00:00
'#default_value' => $config -> get ( 'notify.status_canceled' ),
2007-09-10 13:14:38 +00:00
);
2009-10-16 19:20:34 +00:00
$form [ 'email_canceled' ][ 'settings' ] = array (
'#type' => 'container' ,
'#states' => array (
2009-12-02 17:04:25 +00:00
// Hide the settings when the cancel notify checkbox is disabled.
2009-10-16 19:20:34 +00:00
'invisible' => array (
'input[name="user_mail_status_canceled_notify"]' => array ( 'checked' => FALSE ),
),
),
);
$form [ 'email_canceled' ][ 'settings' ][ 'user_mail_status_canceled_subject' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Subject' ),
2012-09-13 06:41:38 +00:00
'#default_value' => $mail_config -> get ( 'status_canceled.subject' ),
2007-09-10 13:14:38 +00:00
'#maxlength' => 180 ,
);
2009-10-16 19:20:34 +00:00
$form [ 'email_canceled' ][ 'settings' ][ 'user_mail_status_canceled_body' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textarea' ,
'#title' => t ( 'Body' ),
2012-09-13 06:41:38 +00:00
'#default_value' => $mail_config -> get ( 'status_canceled.body' ),
2007-09-10 13:14:38 +00:00
'#rows' => 3 ,
);
2012-08-26 21:15:58 +00:00
return system_config_form ( $form , $form_state );
}
/**
* Form submission handler for user_admin_settings () .
*/
function user_admin_settings_submit ( $form , & $form_state ) {
config ( 'user.settings' )
-> set ( 'anonymous' , $form_state [ 'values' ][ 'anonymous' ])
-> set ( 'admin_role' , $form_state [ 'values' ][ 'user_admin_role' ])
-> set ( 'register' , $form_state [ 'values' ][ 'user_register' ])
-> set ( 'verify_mail' , $form_state [ 'values' ][ 'user_email_verification' ])
-> set ( 'signatures' , $form_state [ 'values' ][ 'user_signatures' ])
2012-10-29 23:09:48 +00:00
-> set ( 'cancel_method' , $form_state [ 'values' ][ 'user_cancel_method' ])
2012-08-26 21:15:58 +00:00
-> set ( 'notify.status_activated' , $form_state [ 'values' ][ 'user_mail_status_activated_notify' ])
-> set ( 'notify.status_blocked' , $form_state [ 'values' ][ 'user_mail_status_blocked_notify' ])
-> set ( 'notify.status_canceled' , $form_state [ 'values' ][ 'user_mail_status_canceled_notify' ])
-> save ();
2012-09-13 06:41:38 +00:00
config ( 'user.mail' )
-> set ( 'cancel_confirm.body' , $form_state [ 'values' ][ 'user_mail_cancel_confirm_body' ])
-> set ( 'cancel_confirm.subject' , $form_state [ 'values' ][ 'user_mail_cancel_confirm_subject' ])
-> set ( 'password_reset.body' , $form_state [ 'values' ][ 'user_mail_password_reset_body' ])
-> set ( 'password_reset.subject' , $form_state [ 'values' ][ 'user_mail_password_reset_subject' ])
-> set ( 'register_admin_created.body' , $form_state [ 'values' ][ 'user_mail_register_admin_created_body' ])
-> set ( 'register_admin_created.subject' , $form_state [ 'values' ][ 'user_mail_register_admin_created_subject' ])
-> set ( 'register_no_approval_required.body' , $form_state [ 'values' ][ 'user_mail_register_no_approval_required_body' ])
-> set ( 'register_no_approval_required.subject' , $form_state [ 'values' ][ 'user_mail_register_no_approval_required_subject' ])
-> set ( 'register_pending_approval.body' , $form_state [ 'values' ][ 'user_mail_register_pending_approval_body' ])
-> set ( 'register_pending_approval.subject' , $form_state [ 'values' ][ 'user_mail_register_pending_approval_subject' ])
-> set ( 'status_activated.body' , $form_state [ 'values' ][ 'user_mail_status_activated_body' ])
-> set ( 'status_activated.subject' , $form_state [ 'values' ][ 'user_mail_status_activated_subject' ])
-> set ( 'status_blocked.body' , $form_state [ 'values' ][ 'user_mail_status_blocked_body' ])
-> set ( 'status_blocked.subject' , $form_state [ 'values' ][ 'user_mail_status_blocked_subject' ])
-> set ( 'status_canceled.body' , $form_state [ 'values' ][ 'user_mail_status_canceled_body' ])
-> set ( 'status_canceled.subject' , $form_state [ 'values' ][ 'user_mail_status_canceled_subject' ])
-> save ();
2007-09-10 13:14:38 +00:00
}
/**
* Menu callback : administer permissions .
2007-10-02 16:03:17 +00:00
*
2007-09-10 13:14:38 +00:00
* @ ingroup forms
2009-07-05 18:07:04 +00:00
* @ see user_admin_permissions_submit ()
* @ see theme_user_admin_permissions ()
2007-09-10 13:14:38 +00:00
*/
2009-09-18 00:12:48 +00:00
function user_admin_permissions ( $form , $form_state , $rid = NULL ) {
2007-09-10 13:14:38 +00:00
2008-01-10 16:00:44 +00:00
// Retrieve role names for columns.
$role_names = user_roles ();
2012-06-05 12:19:14 +00:00
if ( isset ( $rid )) {
2008-01-10 16:00:44 +00:00
$role_names = array ( $rid => $role_names [ $rid ]);
2007-09-10 13:14:38 +00:00
}
2008-05-07 19:34:24 +00:00
// Fetch permissions for all roles or the one selected role.
$role_permissions = user_role_permissions ( $role_names );
2007-09-10 13:14:38 +00:00
2008-05-07 19:34:24 +00:00
// Store $role_names for use when saving the data.
$form [ 'role_names' ] = array (
'#type' => 'value' ,
'#value' => $role_names ,
);
2007-09-10 13:14:38 +00:00
// Render role/permission overview:
$options = array ();
2009-10-27 04:08:42 +00:00
$module_info = system_get_info ( 'module' );
2010-03-21 21:20:43 +00:00
$hide_descriptions = system_admin_compact_mode ();
2009-12-02 17:04:25 +00:00
// Get a list of all the modules implementing a hook_permission() and sort by
// display name.
$modules = array ();
2009-07-05 18:00:11 +00:00
foreach ( module_implements ( 'permission' ) as $module ) {
2010-11-14 21:22:46 +00:00
$modules [ $module ] = $module_info [ $module ][ 'name' ];
2009-12-02 17:04:25 +00:00
}
2010-11-14 21:22:46 +00:00
asort ( $modules );
2009-12-02 17:04:25 +00:00
2010-11-14 21:22:46 +00:00
foreach ( $modules as $module => $display_name ) {
2009-07-05 18:00:11 +00:00
if ( $permissions = module_invoke ( $module , 'permission' )) {
2007-09-10 13:14:38 +00:00
$form [ 'permission' ][] = array (
2009-10-27 04:08:42 +00:00
'#markup' => $module_info [ $module ][ 'name' ],
2009-04-26 15:03:22 +00:00
'#id' => $module ,
2009-09-19 10:54:36 +00:00
);
2008-10-09 15:15:55 +00:00
foreach ( $permissions as $perm => $perm_item ) {
2010-03-21 21:20:43 +00:00
// Fill in default values for the permission.
$perm_item += array (
'description' => '' ,
'restrict access' => FALSE ,
'warning' => ! empty ( $perm_item [ 'restrict access' ]) ? t ( 'Warning: Give to trusted roles only; this permission has security implications.' ) : '' ,
);
2007-09-10 13:14:38 +00:00
$options [ $perm ] = '' ;
2008-02-20 13:46:43 +00:00
$form [ 'permission' ][ $perm ] = array (
'#type' => 'item' ,
2008-10-09 15:15:55 +00:00
'#markup' => $perm_item [ 'title' ],
2010-03-21 21:20:43 +00:00
'#description' => theme ( 'user_permission_description' , array ( 'permission_item' => $perm_item , 'hide' => $hide_descriptions )),
2008-02-20 13:46:43 +00:00
);
2007-09-10 13:14:38 +00:00
foreach ( $role_names as $rid => $name ) {
// Builds arrays for checked boxes for each role
2008-05-07 19:34:24 +00:00
if ( isset ( $role_permissions [ $rid ][ $perm ])) {
2007-09-10 13:14:38 +00:00
$status [ $rid ][] = $perm ;
}
}
}
}
}
// Have to build checkboxes here after checkbox arrays are built
foreach ( $role_names as $rid => $name ) {
2011-07-03 17:48:22 +00:00
$form [ 'checkboxes' ][ $rid ] = array (
'#type' => 'checkboxes' ,
'#options' => $options ,
'#default_value' => isset ( $status [ $rid ]) ? $status [ $rid ] : array (),
'#attributes' => array ( 'class' => array ( 'rid-' . $rid )),
);
2010-04-23 05:39:43 +00:00
$form [ 'role_names' ][ $rid ] = array ( '#markup' => check_plain ( $name ), '#tree' => TRUE );
2007-09-10 13:14:38 +00:00
}
2010-01-30 07:59:26 +00:00
2010-04-24 14:49:14 +00:00
$form [ 'actions' ] = array ( '#type' => 'actions' );
2010-01-03 21:01:04 +00:00
$form [ 'actions' ][ 'submit' ] = array ( '#type' => 'submit' , '#value' => t ( 'Save permissions' ));
2007-09-10 13:14:38 +00:00
2012-08-30 19:24:38 +00:00
$form [ '#attached' ][ 'library' ][] = array ( 'user' , 'drupal.user.permissions' );
2009-05-10 19:16:03 +00:00
2007-09-10 13:14:38 +00:00
return $form ;
}
2008-05-07 19:34:24 +00:00
/**
* Save permissions selected on the administer permissions page .
*
2009-07-05 18:07:04 +00:00
* @ see user_admin_permissions ()
2008-05-07 19:34:24 +00:00
*/
2009-07-05 18:07:04 +00:00
function user_admin_permissions_submit ( $form , & $form_state ) {
2008-05-07 19:34:24 +00:00
foreach ( $form_state [ 'values' ][ 'role_names' ] as $rid => $name ) {
2009-09-19 10:54:36 +00:00
user_role_change_permissions ( $rid , $form_state [ 'values' ][ $rid ]);
2007-09-10 13:14:38 +00:00
}
drupal_set_message ( t ( 'The changes have been saved.' ));
2008-05-07 19:34:24 +00:00
// Clear the cached pages and blocks.
2012-11-28 21:36:29 +00:00
cache_invalidate_tags ( array ( 'content' => TRUE ));
2007-09-10 13:14:38 +00:00
}
/**
2010-04-13 15:23:03 +00:00
* Returns HTML for the administer permissions page .
*
* @ param $variables
* An associative array containing :
* - form : A render element representing the form .
2007-09-10 13:14:38 +00:00
*
* @ ingroup themeable
*/
2009-10-09 01:00:08 +00:00
function theme_user_admin_permissions ( $variables ) {
$form = $variables [ 'form' ];
2007-10-01 09:04:54 +00:00
$roles = user_roles ();
2007-09-10 13:14:38 +00:00
foreach ( element_children ( $form [ 'permission' ]) as $key ) {
2009-06-15 09:49:58 +00:00
$row = array ();
// Module name
if ( is_numeric ( $key )) {
2009-08-22 14:34:23 +00:00
$row [] = array ( 'data' => drupal_render ( $form [ 'permission' ][ $key ]), 'class' => array ( 'module' ), 'id' => 'module-' . $form [ 'permission' ][ $key ][ '#id' ], 'colspan' => count ( $form [ 'role_names' ][ '#value' ]) + 1 );
2009-06-15 09:49:58 +00:00
}
else {
// Permission row.
$row [] = array (
'data' => drupal_render ( $form [ 'permission' ][ $key ]),
2009-08-22 14:34:23 +00:00
'class' => array ( 'permission' ),
2009-06-15 09:49:58 +00:00
);
foreach ( element_children ( $form [ 'checkboxes' ]) as $rid ) {
2010-11-17 04:10:52 +00:00
$form [ 'checkboxes' ][ $rid ][ $key ][ '#title' ] = $roles [ $rid ] . ': ' . $form [ 'permission' ][ $key ][ '#markup' ];
2010-07-28 02:04:44 +00:00
$form [ 'checkboxes' ][ $rid ][ $key ][ '#title_display' ] = 'invisible' ;
$row [] = array ( 'data' => drupal_render ( $form [ 'checkboxes' ][ $rid ][ $key ]), 'class' => array ( 'checkbox' ));
2007-09-10 13:14:38 +00:00
}
}
2009-06-15 09:49:58 +00:00
$rows [] = $row ;
2007-09-10 13:14:38 +00:00
}
$header [] = ( t ( 'Permission' ));
foreach ( element_children ( $form [ 'role_names' ]) as $rid ) {
2009-08-22 14:34:23 +00:00
$header [] = array ( 'data' => drupal_render ( $form [ 'role_names' ][ $rid ]), 'class' => array ( 'checkbox' ));
2007-09-10 13:14:38 +00:00
}
2008-02-20 13:46:43 +00:00
$output = theme ( 'system_compact_link' );
2009-10-09 01:00:08 +00:00
$output .= theme ( 'table' , array ( 'header' => $header , 'rows' => $rows , 'attributes' => array ( 'id' => 'permissions' )));
2009-02-03 18:55:32 +00:00
$output .= drupal_render_children ( $form );
2007-09-10 13:14:38 +00:00
return $output ;
}
2010-03-21 21:20:43 +00:00
/**
2010-04-13 15:23:03 +00:00
* Returns HTML for an individual permission description .
2010-03-21 21:20:43 +00:00
*
* @ param $variables
* An associative array containing :
* - permission_item : An associative array representing the permission whose
* description is being themed . Useful keys include :
* - description : The text of the permission description .
* - warning : A security - related warning message about the permission ( if
* there is one ) .
* - hide : A boolean indicating whether or not the permission description was
* requested to be hidden rather than shown .
*
* @ ingroup themeable
*/
function theme_user_permission_description ( $variables ) {
if ( ! $variables [ 'hide' ]) {
$description = array ();
$permission_item = $variables [ 'permission_item' ];
if ( ! empty ( $permission_item [ 'description' ])) {
$description [] = $permission_item [ 'description' ];
}
if ( ! empty ( $permission_item [ 'warning' ])) {
$description [] = '<em class="permission-warning">' . $permission_item [ 'warning' ] . '</em>' ;
}
if ( ! empty ( $description )) {
return implode ( ' ' , $description );
}
}
}
2007-09-10 13:14:38 +00:00
/**
2010-03-24 07:34:10 +00:00
* Form to re - order roles or add a new one .
2010-03-23 19:22:58 +00:00
*
2007-09-10 13:14:38 +00:00
* @ ingroup forms
2010-03-24 07:34:10 +00:00
* @ see theme_user_admin_roles ()
2007-09-10 13:14:38 +00:00
*/
2010-03-24 07:34:10 +00:00
function user_admin_roles ( $form , $form_state ) {
2012-06-05 12:19:14 +00:00
$roles = db_select ( 'role' , 'r' )
-> addTag ( 'translatable' )
-> fields ( 'r' )
-> orderBy ( 'weight' )
-> orderBy ( 'name' )
-> execute ();
2010-03-24 07:34:10 +00:00
$form [ 'roles' ] = array (
'#tree' => TRUE ,
);
2012-06-05 12:19:14 +00:00
$max_weight = 0 ;
foreach ( $roles as $role ) {
$max_weight = max ( $max_weight , $role -> weight );
$form [ 'roles' ][ $role -> rid ][ '#role' ] = $role ;
$form [ 'roles' ][ $role -> rid ][ '#weight' ] = $role -> weight ;
$form [ 'roles' ][ $role -> rid ][ 'name' ] = array (
'#markup' => check_plain ( $role -> name ),
2007-09-10 13:14:38 +00:00
);
2012-06-05 12:19:14 +00:00
$form [ 'roles' ][ $role -> rid ][ 'weight' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textfield' ,
2012-06-05 12:19:14 +00:00
'#title' => t ( 'Weight for @title' , array ( '@title' => $role -> name )),
2010-10-20 01:31:07 +00:00
'#title_display' => 'invisible' ,
2010-03-24 07:34:10 +00:00
'#size' => 4 ,
2012-06-05 12:19:14 +00:00
'#default_value' => $role -> weight ,
2010-03-24 07:34:10 +00:00
'#attributes' => array ( 'class' => array ( 'role-weight' )),
2007-09-10 13:14:38 +00:00
);
2012-10-09 19:49:07 +00:00
$links [ 'edit' ] = array (
'title' => t ( 'edit role' ),
'href' => 'admin/people/roles/edit/' . $role -> rid ,
'weight' => 0 ,
);
$links [ 'permissions' ] = array (
'title' => t ( 'edit permissions' ),
'href' => 'admin/people/permissions/' . $role -> rid ,
'weight' => 5 ,
2012-06-05 12:19:14 +00:00
);
2012-10-09 19:49:07 +00:00
$form [ 'roles' ][ $role -> rid ][ 'operations' ] = array (
'#type' => 'operations' ,
'#links' => $links ,
2012-06-05 12:19:14 +00:00
);
2010-03-24 07:34:10 +00:00
}
2012-06-05 12:19:14 +00:00
// Embed the role add form.
$add_role = ( object ) array (
'rid' => NULL ,
'name' => NULL ,
'weight' => $max_weight + 1 ,
2010-03-24 07:34:10 +00:00
);
2012-06-05 12:19:14 +00:00
$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' ;
2010-04-24 14:49:14 +00:00
$form [ 'actions' ][ 'submit' ] = array (
2010-03-24 07:34:10 +00:00
'#type' => 'submit' ,
'#value' => t ( 'Save order' ),
2012-06-05 12:19:14 +00:00
// Do not validate the add form when saving the order.
'#limit_validation_errors' => array ( array ( 'roles' )),
2010-03-24 07:34:10 +00:00
'#submit' => array ( 'user_admin_roles_order_submit' ),
);
return $form ;
}
/**
* Form submit function . Update the role weights .
*/
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' ];
user_role_save ( $role );
}
2010-11-15 09:04:47 +00:00
drupal_set_message ( t ( 'The role settings have been updated.' ));
2010-03-24 07:34:10 +00:00
}
/**
2010-04-13 15:23:03 +00:00
* Returns HTML for the role order and new role form .
*
* @ param $variables
* An associative array containing :
* - form : A render element representing the form .
2010-03-24 07:34:10 +00:00
*
* @ ingroup themeable
*/
function theme_user_admin_roles ( $variables ) {
$form = $variables [ 'form' ];
2012-10-09 19:49:07 +00:00
$header = array ( t ( 'Name' ), t ( 'Weight' ), t ( 'Operations' ));
2010-03-24 07:34:10 +00:00
foreach ( element_children ( $form [ 'roles' ]) as $rid ) {
$row = array ();
2012-06-05 12:19:14 +00:00
foreach ( element_children ( $form [ 'roles' ][ $rid ]) as $column ) {
$row [] = drupal_render ( $form [ 'roles' ][ $rid ][ $column ]);
2010-03-24 07:34:10 +00:00
}
$rows [] = array ( 'data' => $row , 'class' => array ( 'draggable' ));
2007-09-10 13:14:38 +00:00
}
2012-06-05 12:19:14 +00:00
// 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 );
2010-03-24 07:34:10 +00:00
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 ()
*/
function user_admin_role ( $form , $form_state , $role ) {
2012-06-05 12:19:14 +00:00
$form [ 'role' ] = array (
'#tree' => TRUE ,
'#parents' => array ( 'role' ),
);
2010-03-24 07:34:10 +00:00
2012-06-05 12:19:14 +00:00
$form [ 'role' ][ 'name' ] = array (
2010-03-24 07:34:10 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Role name' ),
'#default_value' => $role -> name ,
'#size' => 30 ,
'#required' => TRUE ,
'#maxlength' => 64 ,
2012-06-05 12:19:14 +00:00
'#description' => t ( 'The name for this role. Example: "Moderator", "Editorial board", "Site architect".' ),
2010-03-24 07:34:10 +00:00
);
2012-06-05 12:19:14 +00:00
$form [ 'role' ][ 'rid' ] = array (
'#type' => 'machine_name' ,
'#default_value' => $role -> rid ,
'#required' => TRUE ,
'#disabled' => ! empty ( $role -> rid ),
'#size' => 30 ,
'#maxlength' => 64 ,
'#machine_name' => array (
'exists' => 'user_role_load' ,
'source' => array ( 'role' , 'name' ),
),
2010-03-24 07:34:10 +00:00
);
2012-06-05 12:19:14 +00:00
$form [ 'role' ][ 'weight' ] = array (
2010-03-24 07:34:10 +00:00
'#type' => 'value' ,
'#value' => $role -> weight ,
);
2010-04-24 14:49:14 +00:00
$form [ 'actions' ] = array ( '#type' => 'actions' );
2010-03-24 07:34:10 +00:00
$form [ 'actions' ][ 'submit' ] = array (
'#type' => 'submit' ,
2012-06-05 12:19:14 +00:00
'#value' => ! empty ( $role -> rid ) ? t ( 'Save role' ) : t ( 'Add role' ),
2010-03-24 07:34:10 +00:00
);
$form [ 'actions' ][ 'delete' ] = array (
'#type' => 'submit' ,
'#value' => t ( 'Delete role' ),
2012-06-05 12:19:14 +00:00
'#access' => ! empty ( $role -> rid ) && ! in_array ( $role -> rid , array ( DRUPAL_ANONYMOUS_RID , DRUPAL_AUTHENTICATED_RID )),
2010-03-26 22:24:31 +00:00
'#submit' => array ( 'user_admin_role_delete_submit' ),
2010-03-24 07:34:10 +00:00
);
2007-09-10 13:14:38 +00:00
return $form ;
}
2010-03-26 22:24:31 +00:00
/**
* Form submit handler for the user_admin_role () form .
*/
2007-09-10 13:14:38 +00:00
function user_admin_role_submit ( $form , & $form_state ) {
2012-06-05 12:19:14 +00:00
$role = ( object ) $form_state [ 'values' ][ 'role' ];
$status = user_role_save ( $role );
if ( $status === SAVED_UPDATED ) {
2007-09-10 13:14:38 +00:00
drupal_set_message ( t ( 'The role has been renamed.' ));
}
2012-06-05 12:19:14 +00:00
else {
2007-09-10 13:14:38 +00:00
drupal_set_message ( t ( 'The role has been added.' ));
}
2012-06-17 02:23:56 +00:00
$form_state [ 'redirect' ] = 'admin/people/roles' ;
2007-09-10 13:14:38 +00:00
}
2010-03-26 22:24:31 +00:00
/**
* Form submit handler for the user_admin_role () form .
*/
function user_admin_role_delete_submit ( $form , & $form_state ) {
2012-06-17 02:23:56 +00:00
$form_state [ 'redirect' ] = 'admin/people/roles/delete/' . $form_state [ 'values' ][ 'role' ][ 'rid' ];
2010-03-26 22:24:31 +00:00
}
/**
* Form to confirm role delete operation .
*/
function user_admin_role_delete_confirm ( $form , & $form_state , $role ) {
$form [ 'rid' ] = array (
'#type' => 'value' ,
'#value' => $role -> rid ,
);
2012-06-17 02:23:56 +00:00
return confirm_form ( $form , t ( 'Are you sure you want to delete the role %name ?' , array ( '%name' => $role -> name )), 'admin/people/roles' , t ( 'This action cannot be undone.' ), t ( 'Delete' ));
2010-03-26 22:24:31 +00:00
}
/**
* Form submit handler for user_admin_role_delete_confirm () .
*/
function user_admin_role_delete_confirm_submit ( $form , & $form_state ) {
2012-06-05 12:19:14 +00:00
user_role_delete ( $form_state [ 'values' ][ 'rid' ]);
2010-03-26 22:24:31 +00:00
drupal_set_message ( t ( 'The role has been deleted.' ));
2012-06-17 02:23:56 +00:00
$form_state [ 'redirect' ] = 'admin/people/roles' ;
2010-03-26 22:24:31 +00:00
}