summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarim Ratib2011-05-19 16:05:13 (GMT)
committer Karim Ratib2011-05-19 16:05:13 (GMT)
commitf5eeb0bfabeecc51b6a43ef82d74115128709109 (patch)
treefb3b4645d7455d1cfb7a2e5fe78bc0faed9bad09
parent118ad365e3a5d5a7d89eccf423f2d5fbf0ea23d5 (diff)
Issue #578618 by kenianbei: Add book action
-rw-r--r--actions/book.action.inc69
1 files changed, 69 insertions, 0 deletions
diff --git a/actions/book.action.inc b/actions/book.action.inc
new file mode 100644
index 0000000..3ecd1f9
--- /dev/null
+++ b/actions/book.action.inc
@@ -0,0 +1,69 @@
+<?php
+
+function views_bulk_operations_book_action_info() {
+ if (!module_exists('book')) return array();
+ return array(
+ 'views_bulk_operations_move_book_action' => array(
+ 'type' => 'node',
+ 'description' => t('Move book page to new parent'),
+ 'configurable' => TRUE,
+ 'behavior' => array('changes_node_property'),
+ ),
+ 'views_bulk_operations_remove_book_action' => array(
+ 'type' => 'node',
+ 'description' => t('Remove book page from outline'),
+ 'configurable' => FALSE,
+ 'behavior' => array('deletes_node_property'),
+ )
+ );
+}
+
+function views_bulk_operations_move_book_action_form($context) {
+ if (!isset($context['book'])) {
+ $context['book'] = '';
+ }
+ $options = array();
+ $books = book_get_books();
+ foreach ($books as $value) {
+ $options[$value['nid']] = $value['title'];
+ }
+
+ if (empty($options)) {
+ drupal_set_message(t('You have no books.'), 'error');
+ return array();
+ }
+
+ $form['book'] = array(
+ '#type' => 'select',
+ '#title' => t('Choose a parent book'),
+ '#options' => $options,
+ '#description' => t('Select the parent book page you wish to move the book page into.'),
+ );
+ return $form;
+}
+
+function views_bulk_operations_move_book_action_submit($form, $form_state) {
+ return array(
+ 'book' => $form_state['values']['book'],
+ );
+}
+
+function views_bulk_operations_move_book_action($node, $context) {
+ if (isset($context['book'])) {
+ $book_node = node_load($context['book']);
+ $bid = $book_node->nid;
+ $mlid = $book_node->book['mlid'];
+ $node->book['bid'] = $bid;
+ $node->book['plid'] = $mlid;
+ $node->book['module'] = 'book';
+ book_nodeapi($node, 'update', $a3 = NULL, $a4 = NULL);
+ drupal_set_message(t('Book page %node was successfully added to %book_node.', array('%node' => $node->title, '%book_node' =>$book_node->title)));
+ }
+}
+
+function views_bulk_operations_remove_book_action($node, $context) {
+ $node->book['module'] = 'book';
+ book_nodeapi($node, 'delete', $a3 = NULL, $a4 = NULL);
+ drupal_set_message(t('%node was removed from outline.', array('%node' => $node->title, '%mlid' => $node->book['mlid'])));
+}
+