/** * Print all child pages of a book. */ function tao_print_book_children($node) { // Book recursive printing if (module_exists('book') && book_type_is_allowed($node->type)) { if (isset($_GET['print']) && isset($_GET['book_recurse'])) { $child_pages = ''; $zomglimit = 0; $tree = array_shift(book_menu_subtree_data($node->book)); if (!empty($tree['below'])) { foreach ($tree['below'] as $link) { _tao_print_book_children($link, $child_pages, $zomglimit); } } return $child_pages; } } }
/** * Print all child pages of a book. */ function tao_print_book_children($node) { // We use a semaphore here since this function calls and is called by the // node_view() stack so that it may be called multiple times for a single book tree. static $semaphore; if (module_exists('book') && book_type_is_allowed($node->type)) { if (isset($_GET['print']) && isset($_GET['book_recurse']) && !isset($semaphore)) { $semaphore = TRUE; $child_pages = ''; $zomglimit = 0; $tree = array_shift(book_menu_subtree_data($node->book)); if (!empty($tree['below'])) { foreach ($tree['below'] as $link) { _tao_print_book_children($link, $child_pages, $zomglimit); } } unset($semaphore); return $child_pages; } } return ''; }
function testBookNodeTypeChange() { $this->drupalLogin($this->admin_user); // Change the name, machine name and description. $edit = array('name' => 'Bar', 'type' => 'bar'); $this->drupalPostForm('admin/structure/types/manage/book', $edit, t('Save content type')); // Ensure that the config book.settings:allowed_types has been updated with // the new machine and the old one has been removed. $this->assertTrue(book_type_is_allowed('bar'), 'Config book.settings:allowed_types contains the updated node type machine name "bar".'); $this->assertFalse(book_type_is_allowed('book'), 'Config book.settings:allowed_types does not contain the old node type machine name "book".'); $edit = array('name' => 'Basic page', 'title_label' => 'Title for basic page', 'type' => 'page'); $this->drupalPostForm('admin/structure/types/add', $edit, t('Save content type')); // Add page to the allowed node types. $edit = array('book_allowed_types[page]' => 'page', 'book_allowed_types[bar]' => 'bar'); $this->drupalPostForm('admin/structure/book/settings', $edit, t('Save configuration')); $this->assertTrue(book_type_is_allowed('bar'), 'Config book.settings:allowed_types contains the bar node type.'); $this->assertTrue(book_type_is_allowed('page'), 'Config book.settings:allowed_types contains the page node type.'); // Test the order of the book.settings::allowed_types configuration is as // expected. The point of this test is to prove that after changing a node // type going to admin/structure/book/settings and pressing save without // changing anything should not alter the book.settings configuration. The // order will be: // @code // array( // 'bar', // 'page', // ); // @endcode $current_config = \Drupal::config('book.settings')->get(); $this->drupalPostForm('admin/structure/book/settings', array(), t('Save configuration')); $this->assertIdentical($current_config, \Drupal::config('book.settings')->get()); // Change the name, machine name and description. $edit = array('name' => 'Zebra book', 'type' => 'zebra'); $this->drupalPostForm('admin/structure/types/manage/bar', $edit, t('Save content type')); $this->assertTrue(book_type_is_allowed('zebra'), 'Config book.settings:allowed_types contains the zebra node type.'); $this->assertTrue(book_type_is_allowed('page'), 'Config book.settings:allowed_types contains the page node type.'); // Test the order of the book.settings::allowed_types configuration is as // expected. The order should be: // @code // array( // 'page', // 'zebra', // ); // @endcode $current_config = \Drupal::config('book.settings')->get(); $this->drupalPostForm('admin/structure/book/settings', array(), t('Save configuration')); $this->assertIdentical($current_config, \Drupal::config('book.settings')->get()); $edit = array('name' => 'Animal book', 'type' => 'zebra'); $this->drupalPostForm('admin/structure/types/manage/zebra', $edit, t('Save content type')); // Test the order of the book.settings::allowed_types configuration is as // expected. The order should be: // @code // array( // 'page', // 'zebra', // ); // @endcode $current_config = \Drupal::config('book.settings')->get(); $this->drupalPostForm('admin/structure/book/settings', array(), t('Save configuration')); $this->assertIdentical($current_config, \Drupal::config('book.settings')->get()); // Ensure that after all the node type changes book.settings:child_type has // the expected value. $this->assertEqual(\Drupal::config('book.settings')->get('child_type'), 'zebra'); }