diff --git a/core/modules/book/book.admin.inc b/core/modules/book/book.admin.inc index 7d007c4..8fefc78 100644 --- a/core/modules/book/book.admin.inc +++ b/core/modules/book/book.admin.inc @@ -32,12 +32,13 @@ function book_admin_overview() { * @see book_admin_settings_validate() * @ingroup forms */ -function book_admin_settings() { +function book_admin_settings($form, $form_state) { $types = node_type_get_names(); + $config = config('book.settings'); $form['book_allowed_types'] = array( '#type' => 'checkboxes', '#title' => t('Content types allowed in book outlines'), - '#default_value' => variable_get('book_allowed_types', array('book')), + '#default_value' => $config->get('allowed_types'), '#options' => $types, '#description' => t('Users with the %outline-perm permission can add all content types.', array('%outline-perm' => t('Administer book outlines'))), '#required' => TRUE, @@ -45,14 +46,14 @@ function book_admin_settings() { $form['book_child_type'] = array( '#type' => 'radios', '#title' => t('Content type for child pages'), - '#default_value' => variable_get('book_child_type', 'book'), + '#default_value' => $config->get('child_type'), '#options' => $types, '#required' => TRUE, ); $form['array_filter'] = array('#type' => 'value', '#value' => TRUE); $form['#validate'][] = 'book_admin_settings_validate'; - return system_settings_form($form); + return system_config_form($form, $form_state); } /** @@ -66,6 +67,18 @@ function book_admin_settings_validate($form, &$form_state) { } /** + * Form submission handler for book_admin_settings(). + * + * @see book_admin_settings() + */ +function book_admin_settings_submit($form, &$form_state) { + config('book.settings') + ->set('allowed_types', $form_state['values']['book_allowed_types']) + ->set('child_type', $form_state['values']['book_child_type']) + ->save(); + } + +/** * Form constructor for administering a single book's hierarchy. * * @param Drupal\node\Node $node diff --git a/core/modules/book/book.install b/core/modules/book/book.install index 899ee81..bdc4a28 100644 --- a/core/modules/book/book.install +++ b/core/modules/book/book.install @@ -17,10 +17,6 @@ function book_install() { * Implements hook_uninstall(). */ function book_uninstall() { - variable_del('book_allowed_types'); - variable_del('book_child_type'); - variable_del('book_block_mode'); - // Delete menu links. db_delete('menu_links') ->condition('module', 'book') @@ -48,9 +44,6 @@ function _book_install_type_create() { node_add_body_field($book_node_type); // Default to not promoted. variable_set('node_options_book', array('status')); - // Use this default type for adding content to books. - variable_set('book_allowed_types', array('book')); - variable_set('book_child_type', 'book'); } /** @@ -93,3 +86,16 @@ function book_schema() { return $schema; } + +/** + * Moves book settings from variables to config. + * + * @ingroup config_upgrade + */ +function book_update_8000() { + update_variables_to_config('book.settings', array( + 'book_allowed_types' => 'allowed_types', + 'book_child_type' => 'child_type', + 'book_block_mode' => 'block_mode', + )); +} diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 40802a1..559752e 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -98,7 +98,7 @@ function book_node_view_link(Node $node, $view_mode) { if (isset($node->book['depth'])) { if ($view_mode == 'full' && node_is_page($node)) { - $child_type = variable_get('book_child_type', 'book'); + $child_type = config('book.settings')->get('child_type'); if ((user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $child_type) && $node->status == 1 && $node->book['depth'] < MENU_MAX_DEPTH) { $links['book_add_child'] = array( 'title' => t('Add child page'), @@ -284,7 +284,7 @@ function book_block_view($delta = '') { $current_bid = empty($node->book['bid']) ? 0 : $node->book['bid']; } - if (variable_get('book_block_mode', 'all pages') == 'all pages') { + if (config('book.settings')->get('block_mode') == 'all pages') { $block['subject'] = t('Book navigation'); $book_menus = array(); $pseudo_tree = array(0 => array('below' => FALSE)); @@ -342,7 +342,7 @@ function book_block_configure($delta = '') { '#type' => 'radios', '#title' => t('Book navigation block display'), '#options' => $options, - '#default_value' => variable_get('book_block_mode', 'all pages'), + '#default_value' => config('book.settings')->get('block_mode'), '#description' => t("If Show block on all pages is selected, the block will contain the automatically generated menus for all of the site's books. If Show block only on book pages is selected, the block will contain only the one menu corresponding to the current page's book. In this case, if the current page is not in a book, no block will be displayed. The Page specific visibility settings or other visibility settings can be used in addition to selectively display this block."), ); @@ -354,7 +354,7 @@ function book_block_configure($delta = '') { */ function book_block_save($delta = '', $edit = array()) { $block = array(); - variable_set('book_block_mode', $edit['book_block_mode']); + config('book.settings')->set('block_mode', $edit['book_block_mode'])->save(); } /** @@ -1327,7 +1327,7 @@ function template_preprocess_book_node_export_html(&$variables) { * Determines if a given node type is in the list of types allowed for books. */ function book_type_is_allowed($type) { - return in_array($type, variable_get('book_allowed_types', array('book'))); + return in_array($type, config('book.settings')->get('allowed_types')); } /** @@ -1338,20 +1338,22 @@ function book_type_is_allowed($type) { */ function book_node_type_update($type) { if (!empty($type->old_type) && $type->old_type != $type->type) { + $config = config('book.settings'); // Update the list of node types that are allowed to be added to books. - $allowed_types = variable_get('book_allowed_types', array('book')); + $allowed_types = $config->get('allowed_types'); $key = array_search($type->old_type, $allowed_types); if ($key !== FALSE) { $allowed_types[$type->type] = $allowed_types[$key] ? $type->type : 0; unset($allowed_types[$key]); - variable_set('book_allowed_types', $allowed_types); + $config->set('allowed_types', $allowed_types); } // Update the setting for the "Add child page" link. - if (variable_get('book_child_type', 'book') == $type->old_type) { - variable_set('book_child_type', $type->type); + if ($config->get('child_type') == $type->old_type) { + $config->set('child_type', $type->type); } + $config->save(); } } diff --git a/core/modules/book/config/book.settings.yml b/core/modules/book/config/book.settings.yml new file mode 100644 index 0000000..1d8e23f --- /dev/null +++ b/core/modules/book/config/book.settings.yml @@ -0,0 +1,5 @@ +allowed_types: + - book +child_type: book +block_mode: all pages +