/** * This is an example implementation for the hook. Preforms actions when converting a node based on it's type. * * @param $data * An array containing information about the conversion process. The keys are * - dest_node_type The destination type of the node * - node The node object * - Any other information passed by $op = 'options' or $op = 'options validate' * @param $op * A string containing the operation which should be executed. These are the possible values * - insert Operations which should be run when the node is transferred to the new node type. * Usually for transferring and adding new node information into the database. * - delete Operations which should be run after the node is transferred to the new node type. * Usually for deleting unneeded information from the database after the transfer. * - options Configuration elements shown on the conversion form. Should return a FAPI array. * - options validate Validation check on the options elements. * @return * Should return a FAPI array only when using the options operation. */ function hook_node_convert_change($data, $op) { // All of this is just an example. if ($op == 'insert') { if ($data['dest_node_type'] == 'book') { $book = array(); $node = $data['node']; $book['link_path'] = 'node/' . $node->nid; $book['link_title'] = $node->title; $book['plid'] = 0; $book['menu_name'] = book_menu_name($node->nid); $mlid = menu_link_save($book); $book['bid'] = $data['hook_options']['bid']; if ($book['bid'] == 'self') { $book['bid'] = $node->nid; } $id = db_insert('book')->fields(array('nid' => $node->nid, 'mlid' => $book['mlid'], 'bid' => $book['bid']))->execute(); } if ($data['dest_node_type'] == 'forum') { $id = db_insert('forum')->fields(array('tid' => $data['hook_options']['forum'], 'vid' => $data['node']->vid, 'nid' => $data['node']->nid))->execute(); $id = db_insert('taxonomy_term_node')->fields(array('tid' => $data['hook_options']['forum'], 'vid' => $data['node']->vid, 'nid' => $data['node']->nid))->execute(); } } elseif ($op == 'delete') { if ($data['node']->type == 'book') { menu_link_delete($data['node']->book['mlid']); db_delete('book')->condition('mlid', $data['node']->book['mlid'])->execute(); } if ($data['node']->type == 'forum') { db_delete('forum')->condition('nid', $data['node']->nid)->execute(); db_delete('taxonomy_term_node')->condition('nid', $data['node']->nid)->execute(); } } elseif ($op == 'options') { $form = array(); if ($data['dest_node_type'] == 'book') { foreach (book_get_books() as $book) { $options[$book['nid']] = $book['title']; } $options = array('self' => '<' . t('create a new book') . '>') + $options; $form['bid'] = array('#type' => 'select', '#title' => t('Book'), '#options' => $options, '#description' => t('Your page will be a part of the selected book.'), '#attributes' => array('class' => 'book-title-select')); } if ($data['dest_node_type'] == 'forum') { $vid = variable_get('forum_nav_vocabulary', ''); $form['forum'] = taxonomy_form($vid); $form['forum']['#weight'] = 7; $form['forum']['#required'] = TRUE; $form['forum']['#options'][''] = t('- Please choose -'); } return $form; } elseif ($op == 'options validate') { $form_state = $data['form_state']; if ($data['dest_node_type'] == 'forum') { $containers = variable_get('forum_containers', array()); $term = $form_state['values']['hook_options']['forum']; if (in_array($term, $containers)) { $term = taxonomy_term_load($term); form_set_error('hook_options][forum', t('The item %forum is only a container for forums. Please select one of the forums below it.', array('%forum' => $term->name))); } } } }
function nys_preprocess_book_navigation(&$variables) { $node = node_load($variables['book_link']['nid']); $variables['display'] = TRUE; if (strlen($node->body) >= 3000 || $variables['book_link']['nid'] == $variables['book_link']['bid']) { $book_link = $variables['book_link']; $tree = menu_tree_all_data(book_menu_name($book_link['bid'])); $variables['tree'] = '<div class="book-navigation-tree">' . menu_tree_output($tree) . '</div>'; } else { $variables['display'] = FALSE; } }