- <?php
- * @file
- * Install, update and uninstall functions for the book module.
- */
-
- * Implements hook_install().
- */
- function book_install() {
-
- _book_install_type_create();
- }
-
- * Implements hook_uninstall().
- */
- function book_uninstall() {
-
- db_delete('menu_links')
- ->condition('module', 'book')
- ->execute();
- menu_cache_clear_all();
- }
-
- * Creates the book content type.
- */
- function _book_install_type_create() {
-
- $book_node_type = array(
- 'type' => 'book',
- 'name' => t('Book page'),
- 'base' => 'node_content',
- 'description' => t('<em>Books</em> have a built-in hierarchical navigation. Use for handbooks or tutorials.'),
- 'custom' => 1,
- 'modified' => 1,
- 'locked' => 0,
- 'is_new' => TRUE,
- 'settings' => array(
- 'promote_enabled' => FALSE,
- ),
- );
-
- $book_node_type = node_type_set_defaults($book_node_type);
- node_type_save($book_node_type);
- node_add_body_field($book_node_type);
- }
-
- * Implements hook_schema().
- */
- function book_schema() {
- $schema['book'] = array(
- 'description' => 'Stores book outline information. Uniquely connects each node in the outline to a link in {menu_links}',
- 'fields' => array(
- 'mlid' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => "The book page's {menu_links}.mlid.",
- ),
- 'nid' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => "The book page's {node}.nid.",
- ),
- 'bid' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => "The book ID is the {book}.nid of the top-level page.",
- ),
- ),
- 'primary key' => array('mlid'),
- 'unique keys' => array(
- 'nid' => array('nid'),
- ),
- 'indexes' => array(
- 'bid' => array('bid'),
- ),
- );
-
- return $schema;
- }
-
- * @defgroup updates-7.x-to-1.x Updates from 7.x to 1.x
- * @{
- * Update functions from Drupal 7.x to Backdrop CMS 1.x.
- */
-
- * Move book settings from variables to config.
- */
- function book_update_1000() {
-
- $config = config('book.settings');
- $config->set('book_allowed_types', update_variable_get('book_allowed_types', array('book')));
- $config->set('book_child_type', update_variable_get('book_child_type', 'book'));
- $config->set('book_block_mode', update_variable_get('book_block_mode', 'all pages'));
- $config->save();
-
-
- update_variable_del('book_allowed_types');
- update_variable_del('book_child_type');
- update_variable_del('book_block_mode');
- }
-
- * Add options for navigation and links.
- */
- function book_update_1001() {
- $config = config('book.settings');
- $config->set('book_navigation', 1);
- $config->set('book_navigation_options', array('tree', 'pager'));
- $config->set('book_links', array('book_add_child'));
- $config->save();
- }
-
- * Add option for reorder link.
- */
- function book_update_1002() {
- $config = config('book.settings');
- $book_links = $config->get('book_links');
- if (isset($book_links['book_add_child'])) {
- $book_links['book_reorder'] = 'book_reorder';
- }
- else {
- $book_links[] = 'book_reorder';
- }
- $config->set('book_links', $book_links);
- $config->save();
- }
-
- * Add option for dis-allowing books for all content types.
- */
- function book_update_1003() {
- $config = config('book.settings');
- if ($config->get('book_admin_allowed_all') === NULL) {
- $config->set('book_admin_allowed_all', 1);
- $config->save();
- }
- }
-
- * @} End of "defgroup updates-7.x-to-1.x"
- * The next series of updates should start at 2000.
- */