Commit 766e6494 authored by drumm's avatar drumm
Browse files

#77525 by hunmonk, clean up for hook_(node|user)_operations().

parent d96bebfc
......@@ -1154,12 +1154,29 @@ function node_last_changed($nid) {
*/
function node_node_operations() {
$operations = array(
'approve' => array(t('Approve the selected posts'), 'node_operations_approve'),
'promote' => array(t('Promote the selected posts'), 'node_operations_promote'),
'sticky' => array(t('Make the selected posts sticky'), 'node_operations_sticky'),
'demote' => array(t('Demote the selected posts'), 'node_operations_demote'),
'unpublish' => array(t('Unpublish the selected posts'), 'node_operations_unpublish'),
'delete' => array(t('Delete the selected posts'), ''),
'approve' => array(
'label' => t('Approve the selected posts'),
'callback' => 'node_operations_approve',
),
'promote' => array(
'label' => t('Promote the selected posts'),
'callback' => 'node_operations_promote',
),
'sticky' => array(
'label' => t('Make the selected posts sticky'),
'callback' => 'node_operations_sticky',
),
'demote' => array(
'label' => t('Demote the selected posts'),
'callback' => 'node_operations_demote',
),
'unpublish' => array(
'label' => t('Unpublish the selected posts'),
'callback' => 'node_operations_unpublish',
),
'delete' => array(
'label' => t('Delete the selected posts'),
),
);
return $operations;
}
......@@ -1370,23 +1387,26 @@ function node_admin_nodes_submit($form_id, $edit) {
$operations = module_invoke_all('node_operations');
$operation = $operations[$edit['operation']];
// Filter out unchecked nodes
$nodes = array_diff($edit['nodes'], array(0));
if ($function = $operation[1]) {
call_user_func($function, $nodes);
$nodes = array_filter($edit['nodes']);
if ($function = $operation['callback']) {
// Add in callback arguments if present.
if (isset($operation['callback arguments'])) {
$args = array_merge(array($nodes), $operation['callback arguments']);
}
else {
$args = array($nodes);
}
call_user_func_array($function, $args);
cache_clear_all();
drupal_set_message(t('The update has been performed.'));
}
}
function node_admin_nodes_validate($form_id, $edit) {
$edit['nodes'] = array_diff($edit['nodes'], array(0));
if (count($edit['nodes']) == 0) {
if ($edit['operation'] == 'delete') {
form_set_error('', t('Please select some items to perform the delete operation.'));
}
else {
form_set_error('', t('Please select some items to perform the update on.'));
}
$nodes = array_filter($edit['nodes']);
if (count($nodes) == 0) {
form_set_error('', t('No items selected.'));
}
}
......@@ -1411,8 +1431,8 @@ function node_admin_nodes() {
'#suffix' => '</div>',
);
$options = array();
foreach (module_invoke_all('node_operations') as $key => $value) {
$options[$key] = $value[0];
foreach (module_invoke_all('node_operations') as $operation => $array) {
$options[$operation] = $array['label'];
}
$form['options']['operation'] = array('#type' => 'select', '#options' => $options, '#default_value' => 'approve');
$form['options']['submit'] = array('#type' => 'submit', '#value' => t('Update'));
......
......@@ -1935,8 +1935,8 @@ function user_admin_account() {
'#suffix' => '</div>',
);
$options = array();
foreach (module_invoke_all('user_operations') as $key => $value) {
$options[$key] = $value[0];
foreach (module_invoke_all('user_operations') as $operation => $array) {
$options[$operation] = $array['label'];
}
$form['options']['operation'] = array(
'#type' => 'select',
......@@ -2031,8 +2031,16 @@ function user_admin_account_submit($form_id, $edit) {
$operation = $operations[$edit['operation']];
// Filter out unchecked accounts.
$accounts = array_filter($edit['accounts']);
if ($function = $operation[1]) {
call_user_func($function, $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);
cache_clear_all();
drupal_set_message(t('The update has been performed.'));
}
......@@ -2052,7 +2060,7 @@ function user_user_operations() {
global $form_values;
$roles = user_roles(1);
unset($roles[2]); // Can't edit authenticated role.
unset($roles[DRUPAL_AUTHENTICATED_RID]); // Can't edit authenticated role.
$add_roles = array();
foreach ($roles as $key => $value) {
......@@ -2065,18 +2073,35 @@ function user_user_operations() {
}
$operations = array(
'unblock' => array(t('Unblock the selected users'), 'user_user_operations_unblock'),
'block' => array(t('Block the selected users'), 'user_user_operations_block'),
t('Add a role to the selected users') => array($add_roles),
t('Remove a role from the selected users') => array($remove_roles),
'delete' => array(t('Delete the selected users'), ''),
'unblock' => array(
'label' => t('Unblock the selected users'),
'callback' => 'user_user_operations_unblock',
),
'block' => array(
'label' => t('Block the selected users'),
'callback' => 'user_user_operations_block',
),
t('Add a role to the selected users') => array(
'label' => $add_roles,
),
t('Remove a role from the selected users') => array(
'label' => $remove_roles,
),
'delete' => array(
'label' => t('Delete the selected users'),
),
);
// If the form has been posted, we need to insert the proper data for role editing if necessary.
if ($form_values) {
$operation = explode('-', $form_values['operation']);
if ($operation[0] == 'add_role' || $operation[0] == 'remove_role') {
$operations[$form_values['operation']] = array(NULL, 'user_multiple_role_edit');
$operation_rid = explode('-', $form_values['operation']);
$operation = $operation_rid[0];
$rid = $operation_rid[1];
if ($operation == 'add_role' || $operation == 'remove_role') {
$operations[$form_values['operation']] = array(
'callback' => 'user_multiple_role_edit',
'callback arguments' => array($operation, $rid),
);
}
}
......@@ -2100,14 +2125,7 @@ function user_user_operations_block($accounts) {
/**
* Callback function for admin mass adding/deleting a user role.
*/
function user_multiple_role_edit($accounts) {
global $form_values;
// Get the operation and role from the posted form.
$operation_rid = explode('-', $form_values['operation']);
$operation = $operation_rid[0];
$rid = $operation_rid[1];
function user_multiple_role_edit($accounts, $operation, $rid) {
switch ($operation) {
case 'add_role':
foreach ($accounts as $uid) {
......
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