Commit 7e571b97 authored by Dries's avatar Dries

- 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() {
* Form constructor for the book settings form.
*
* @see book_menu()
* @see book_admin_settings_submit()
* @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 +47,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);
}
/**
......@@ -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.
*
......
......@@ -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;
}
/**
* 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) {
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.navigation.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.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."),
);
......@@ -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.navigation.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();
}
}
......
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