Commit 7e571b97 authored by Dries's avatar Dries
Browse files

- Patch #1703164 by chriscalip, kbasarab, no_commit_credit, aspilicious: Fixed...

- Patch #1703164 by chriscalip, kbasarab, no_commit_credit, aspilicious: Fixed Convert book settings to the new configuration system.
parent 19fecb52
...@@ -29,15 +29,17 @@ function book_admin_overview() { ...@@ -29,15 +29,17 @@ function book_admin_overview() {
* Form constructor for the book settings form. * Form constructor for the book settings form.
* *
* @see book_menu() * @see book_menu()
* @see book_admin_settings_submit()
* @see book_admin_settings_validate() * @see book_admin_settings_validate()
* @ingroup forms * @ingroup forms
*/ */
function book_admin_settings() { function book_admin_settings($form, &$form_state) {
$types = node_type_get_names(); $types = node_type_get_names();
$config = config('book.settings');
$form['book_allowed_types'] = array( $form['book_allowed_types'] = array(
'#type' => 'checkboxes', '#type' => 'checkboxes',
'#title' => t('Content types allowed in book outlines'), '#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, '#options' => $types,
'#description' => t('Users with the %outline-perm permission can add all content types.', array('%outline-perm' => t('Administer book outlines'))), '#description' => t('Users with the %outline-perm permission can add all content types.', array('%outline-perm' => t('Administer book outlines'))),
'#required' => TRUE, '#required' => TRUE,
...@@ -45,14 +47,14 @@ function book_admin_settings() { ...@@ -45,14 +47,14 @@ function book_admin_settings() {
$form['book_child_type'] = array( $form['book_child_type'] = array(
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Content type for child pages'), '#title' => t('Content type for child pages'),
'#default_value' => variable_get('book_child_type', 'book'), '#default_value' => $config->get('child_type'),
'#options' => $types, '#options' => $types,
'#required' => TRUE, '#required' => TRUE,
); );
$form['array_filter'] = array('#type' => 'value', '#value' => TRUE); $form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
$form['#validate'][] = 'book_admin_settings_validate'; $form['#validate'][] = 'book_admin_settings_validate';
return system_settings_form($form); return system_config_form($form, $form_state);
} }
/** /**
...@@ -65,6 +67,18 @@ function book_admin_settings_validate($form, &$form_state) { ...@@ -65,6 +67,18 @@ function book_admin_settings_validate($form, &$form_state) {
} }
} }
/**
* Form submission handler for book_admin_settings().
*
* @see book_admin_settings_validate()
*/
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. * Form constructor for administering a single book's hierarchy.
* *
......
...@@ -17,10 +17,6 @@ function book_install() { ...@@ -17,10 +17,6 @@ function book_install() {
* Implements hook_uninstall(). * Implements hook_uninstall().
*/ */
function book_uninstall() { function book_uninstall() {
variable_del('book_allowed_types');
variable_del('book_child_type');
variable_del('book_block_mode');
// Delete menu links. // Delete menu links.
db_delete('menu_links') db_delete('menu_links')
->condition('module', 'book') ->condition('module', 'book')
...@@ -48,9 +44,6 @@ function _book_install_type_create() { ...@@ -48,9 +44,6 @@ function _book_install_type_create() {
node_add_body_field($book_node_type); node_add_body_field($book_node_type);
// Default to not promoted. // Default to not promoted.
variable_set('node_options_book', array('status')); 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() { ...@@ -93,3 +86,16 @@ function book_schema() {
return $schema; return $schema;
} }
/**
* Move 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.navigation.mode',
));
}
...@@ -98,7 +98,7 @@ function book_node_view_link(Node $node, $view_mode) { ...@@ -98,7 +98,7 @@ function book_node_view_link(Node $node, $view_mode) {
if (isset($node->book['depth'])) { if (isset($node->book['depth'])) {
if ($view_mode == 'full' && node_is_page($node)) { 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) { 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( $links['book_add_child'] = array(
'title' => t('Add child page'), 'title' => t('Add child page'),
...@@ -284,7 +284,7 @@ function book_block_view($delta = '') { ...@@ -284,7 +284,7 @@ function book_block_view($delta = '') {
$current_bid = empty($node->book['bid']) ? 0 : $node->book['bid']; $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.navigation.mode') == 'all pages') {
$block['subject'] = t('Book navigation'); $block['subject'] = t('Book navigation');
$book_menus = array(); $book_menus = array();
$pseudo_tree = array(0 => array('below' => FALSE)); $pseudo_tree = array(0 => array('below' => FALSE));
...@@ -342,7 +342,7 @@ function book_block_configure($delta = '') { ...@@ -342,7 +342,7 @@ function book_block_configure($delta = '') {
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Book navigation block display'), '#title' => t('Book navigation block display'),
'#options' => $options, '#options' => $options,
'#default_value' => variable_get('book_block_mode', 'all pages'), '#default_value' => config('book.settings')->get('block.navigation.mode'),
'#description' => t("If <em>Show block on all pages</em> is selected, the block will contain the automatically generated menus for all of the site's books. If <em>Show block only on book pages</em> 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 <em>Page specific visibility settings</em> or other visibility settings can be used in addition to selectively display this block."), '#description' => t("If <em>Show block on all pages</em> is selected, the block will contain the automatically generated menus for all of the site's books. If <em>Show block only on book pages</em> 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 <em>Page specific visibility settings</em> or other visibility settings can be used in addition to selectively display this block."),
); );
...@@ -354,7 +354,7 @@ function book_block_configure($delta = '') { ...@@ -354,7 +354,7 @@ function book_block_configure($delta = '') {
*/ */
function book_block_save($delta = '', $edit = array()) { function book_block_save($delta = '', $edit = array()) {
$block = array(); $block = array();
variable_set('book_block_mode', $edit['book_block_mode']); config('book.settings')->set('block.navigation.mode', $edit['book_block_mode'])->save();
} }
/** /**
...@@ -1327,7 +1327,7 @@ function template_preprocess_book_node_export_html(&$variables) { ...@@ -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. * Determines if a given node type is in the list of types allowed for books.
*/ */
function book_type_is_allowed($type) { 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) { ...@@ -1338,20 +1338,22 @@ function book_type_is_allowed($type) {
*/ */
function book_node_type_update($type) { function book_node_type_update($type) {
if (!empty($type->old_type) && $type->old_type != $type->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. // 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); $key = array_search($type->old_type, $allowed_types);
if ($key !== FALSE) { if ($key !== FALSE) {
$allowed_types[$type->type] = $allowed_types[$key] ? $type->type : 0; $allowed_types[$type->type] = $allowed_types[$key] ? $type->type : 0;
unset($allowed_types[$key]); 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. // Update the setting for the "Add child page" link.
if (variable_get('book_child_type', 'book') == $type->old_type) { if ($config->get('child_type') == $type->old_type) {
variable_set('book_child_type', $type->type); $config->set('child_type', $type->type);
} }
$config->save();
} }
} }
......
allowed_types:
- book
block:
navigation:
mode: all pages
child_type: book
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment