change_owner.action.inc 1.6 KB

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