Commit 1813bf3d authored by webchick's avatar webchick

Issue #1928082 by vijaycs85, YesCT, alexpott: Fixed Make usage of...

Issue #1928082 by vijaycs85, YesCT, alexpott: Fixed Make usage of book.settings:allowed_types() consistent.
parent f7a6f396
......@@ -93,7 +93,8 @@ function book_admin_settings_validate($form, &$form_state) {
*/
function book_admin_settings_submit($form, &$form_state) {
config('book.settings')
->set('allowed_types', $form_state['values']['book_allowed_types'])
// Remove unchecked types.
->set('allowed_types', array_filter($form_state['values']['book_allowed_types']))
->set('child_type', $form_state['values']['book_child_type'])
->save();
}
......
......@@ -94,8 +94,24 @@ function book_schema() {
*/
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',
));
$allowed_types = update_variable_get('book_allowed_types', FALSE);
if ($allowed_types) {
// In Drupal 7 the variable book_allowed_types was stored like this:
// array(
// 0 => 'book',
// 1 => 'article',
// )
// In Drupal 8 book.settings:allowed_types should be stored like this:
// array(
// 'book' => 'book',
// 'article' => 'article',
// )
config('book.settings')
->set('allowed_types', drupal_map_assoc($allowed_types))
->save();
}
}
......@@ -1232,7 +1232,8 @@ function template_preprocess_book_node_export_html(&$variables) {
* A Boolean TRUE if the node type can be included in books; otherwise, FALSE.
*/
function book_type_is_allowed($type) {
return in_array($type, config('book.settings')->get('allowed_types'));
$allowed_types = config('book.settings')->get('allowed_types');
return isset($allowed_types[$type]);
}
/**
......@@ -1246,11 +1247,12 @@ function book_node_type_update($type) {
$config = config('book.settings');
// Update the list of node types that are allowed to be added to books.
$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]);
if (isset($allowed_types[$type->old_type])) {
// Replace the old machine-readable name with the new machine-readable
// name.
$allowed_types[$type->type] = $type->type;
unset($allowed_types[$type->old_type]);
$config->set('allowed_types', $allowed_types);
}
......
allowed_types:
- book
book: book
block:
navigation:
mode: all pages
mode: 'all pages'
child_type: book
......@@ -67,7 +67,7 @@ function setUp() {
// Create users.
$this->book_author = $this->drupalCreateUser(array('create new books', 'create book content', 'edit own book content', 'add content to books'));
$this->web_user = $this->drupalCreateUser(array('access printer-friendly version', 'node test view'));
$this->admin_user = $this->drupalCreateUser(array('create new books', 'create book content', 'edit own book content', 'add content to books', 'administer blocks', 'administer permissions', 'administer book outlines', 'node test view'));
$this->admin_user = $this->drupalCreateUser(array('create new books', 'create book content', 'edit own book content', 'add content to books', 'administer blocks', 'administer permissions', 'administer book outlines', 'node test view', 'administer content types'));
}
/**
......@@ -388,5 +388,23 @@ function testBookDelete() {
$node = node_load($this->book->nid, TRUE);
$this->assertTrue(empty($node->book), 'Deleting childless top-level book node properly allowed.');
}
/*
* Tests node type changing machine name when type is a book allowed type.
*/
function testBookNodeTypeChange() {
$this->drupalLogin($this->admin_user);
// Change the name, machine name and description.
$edit = array(
'name' => 'Bar',
'type' => 'bar',
);
$this->drupalPost('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".');
}
}
......@@ -139,6 +139,20 @@ public function testVariableUpgrade() {
'screenshot' => 'public://color/seven-09696463/dummy-screenshot.png',
);
$expected_config['book.settings'] = array(
'allowed_types' => array(
'book' => 'book',
// Content type does not have to exist.
'test' => 'test',
),
'block' => array(
'navigation' => array(
'mode' => 'all pages'
)
),
'child_type' => 'book',
);
foreach ($expected_config as $file => $values) {
$config = config($file);
$this->verbose(print_r($config->get(), TRUE));
......
......@@ -133,6 +133,10 @@
->fields(array('value' => 's:10:"plain_text";'))
->condition('name', 'filter_fallback_format')
->execute();
db_update('variable')
->fields(array('value' => 'a:2:{i:0;s:4:"book";i:1;s:4:"test";}'))
->condition('name', 'book_allowed_types')
->execute();
// color module in bartik
$palette = array(
......
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