1 |
7547bb19
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Implements a generic entity change owner action.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Implements hook_action_info().
|
10 |
|
|
*/
|
11 |
|
|
function views_bulk_operations_change_owner_action_info() {
|
12 |
|
|
return array(
|
13 |
|
|
'views_bulk_operations_change_owner_action' => array(
|
14 |
|
|
'type' => 'entity',
|
15 |
|
|
'label' => t('Change owner'),
|
16 |
|
|
'configurable' => TRUE,
|
17 |
|
|
'behavior' => array('changes_property'),
|
18 |
|
|
'triggers' => array('any'),
|
19 |
|
|
),
|
20 |
|
|
);
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
/**
|
24 |
|
|
* Action function.
|
25 |
|
|
*/
|
26 |
|
|
function views_bulk_operations_change_owner_action($entity, $context) {
|
27 |
|
|
$entity->uid = $context['owner_uid'];
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
/**
|
31 |
|
|
* Action form function.
|
32 |
|
|
*/
|
33 |
|
|
function views_bulk_operations_change_owner_action_form($context, &$form_state) {
|
34 |
|
|
$form['owner_username'] = array(
|
35 |
|
|
'#type' => 'textfield',
|
36 |
|
|
'#maxlength' => USERNAME_MAX_LENGTH,
|
37 |
|
|
'#title' => t('Owner'),
|
38 |
|
|
'#required' => TRUE,
|
39 |
|
|
'#description' => t('Choose the user you would like to set as the owner.'),
|
40 |
|
|
'#autocomplete_path' => 'user/autocomplete',
|
41 |
|
|
);
|
42 |
|
|
|
43 |
|
|
return $form;
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
/**
|
47 |
|
|
* Action form validate function.
|
48 |
|
|
*
|
49 |
|
|
* Checks that the submitted text is a valid username.
|
50 |
|
|
*/
|
51 |
|
|
function views_bulk_operations_change_owner_action_validate($form, $form_state) {
|
52 |
|
|
if (!user_load_by_name($form_state['values']['owner_username'])) {
|
53 |
|
|
form_set_error('owner_username', t('Valid username required.'));
|
54 |
|
|
}
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
/**
|
58 |
|
|
* Action form submit function.
|
59 |
|
|
*
|
60 |
|
|
* Pass submitted username back to views_bulk_operations_change_owner.
|
61 |
|
|
*/
|
62 |
|
|
function views_bulk_operations_change_owner_action_submit($form, $form_state) {
|
63 |
|
|
$user = user_load_by_name($form_state['values']['owner_username']);
|
64 |
|
|
return array('owner_uid' => $user->uid);
|
65 |
|
|
} |