book.action.inc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * @file
  4. * Implements actions for managing books (book.module).
  5. */
  6. function views_bulk_operations_book_action_info() {
  7. $actions = array();
  8. if (module_exists('book')) {
  9. $actions['views_bulk_operations_move_to_book_action'] = array(
  10. 'type' => 'node',
  11. 'label' => t('Move to book'),
  12. 'configurable' => TRUE,
  13. 'behavior' => array('changes_property'),
  14. 'triggers' => array('any'),
  15. );
  16. $actions['views_bulk_operations_remove_from_book_action'] = array(
  17. 'type' => 'node',
  18. 'label' => t('Remove from book'),
  19. 'configurable' => FALSE,
  20. 'triggers' => array('any'),
  21. );
  22. }
  23. return $actions;
  24. }
  25. function views_bulk_operations_move_to_book_action_form($context) {
  26. $form = array();
  27. if (!isset($context['book'])) {
  28. $context['book'] = '';
  29. }
  30. $options = array();
  31. $books = book_get_books();
  32. foreach ($books as $value) {
  33. $options[$value['nid']] = $value['title'];
  34. }
  35. if (empty($options)) {
  36. drupal_set_message(t('You have no books.'), 'error');
  37. return array();
  38. }
  39. $form['book'] = array(
  40. '#type' => 'select',
  41. '#title' => t('Choose a parent book'),
  42. '#options' => $options,
  43. '#description' => t('Select the parent book page you wish to move the book page into'),
  44. );
  45. return $form;
  46. }
  47. function views_bulk_operations_move_to_book_action_submit($form, $form_state) {
  48. return array('book' => $form_state['values']['book']);
  49. }
  50. function views_bulk_operations_move_to_book_action($node, $context = array()) {
  51. if (isset($context['book'])) {
  52. $book_node = node_load($context['book']);
  53. $mlid = db_select('menu_links' , 'ml')
  54. ->condition('ml.link_path' , 'node/' . $node->nid)
  55. ->fields('ml' , array('mlid'))
  56. ->execute()
  57. ->fetchField();
  58. $node->book['mlid'] = $mlid;
  59. $node->book['bid'] = $book_node->nid;
  60. $node->book['plid'] = $book_node->book['mlid'];
  61. $node->book['module'] = 'book';
  62. }
  63. }
  64. /**
  65. * Adds the action 'Remove node from a parent book'
  66. */
  67. function views_bulk_operations_remove_from_book_action($node, $context) {
  68. $book = $node->book['mlid'];
  69. book_node_delete($node);
  70. }