diff --git a/core/modules/book/book.install b/core/modules/book/book.install index 2293c46..c15377f 100644 --- a/core/modules/book/book.install +++ b/core/modules/book/book.install @@ -43,7 +43,7 @@ function _book_install_type_create() { node_type_save($book_node_type); node_add_body_field($book_node_type); // Default to not promoted. - variable_set('node_options_book', array('status')); + config('node.settings.book')->set('options', array('status')); } /** diff --git a/core/modules/field/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php b/core/modules/field/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php index 0ac151f..fe990e8 100644 --- a/core/modules/field/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php +++ b/core/modules/field/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php @@ -51,7 +51,7 @@ function setUp() { $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); // Set "Article" content type to use multilingual support with translation. - $edit = array('language_configuration[language_hidden]' => FALSE, 'node_type_language_translation_enabled' => TRUE); + $edit = array('language_configuration[language_hidden]' => FALSE, 'type_language_translation_enabled' => TRUE); $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Article')), 'Article content type has been updated.'); } diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index 56f8402..7bffad5 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -15,7 +15,7 @@ function forum_install() { // options set (for example, they are not promoted to the front page). // @todo Convert to default module configuration, once Node module's content // types are converted. - variable_set('node_options_forum', array('status')); + config('node.settings.book')->set('options', array('status')); } /** @@ -117,7 +117,7 @@ function forum_uninstall() { // Load the dependent Taxonomy module, in case it has been disabled. drupal_load('module', 'taxonomy'); - variable_del('node_options_forum'); + config('node.settings.forum')->delete(); field_delete_field('taxonomy_forums'); // Purge field data now to allow taxonomy module to be uninstalled diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php index f56cfbb..24d2048 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php @@ -195,7 +195,7 @@ function testForum() { // Test loading multiple forum nodes on the front page. $this->drupalLogin($this->drupalCreateUser(array('administer content types', 'create forum content', 'post comments'))); - $this->drupalPost('admin/structure/types/manage/forum', array('node_options[promote]' => 'promote'), t('Save content type')); + $this->drupalPost('admin/structure/types/manage/forum', array('options[promote]' => 'promote'), t('Save content type')); $this->createForumTopic($this->forum, FALSE); $this->createForumTopic($this->forum, FALSE); $this->drupalGet('node'); diff --git a/core/modules/node/content_types.inc b/core/modules/node/content_types.inc index 999de7f..6e015dc 100644 --- a/core/modules/node/content_types.inc +++ b/core/modules/node/content_types.inc @@ -113,6 +113,8 @@ function node_type_form($form, &$form_state, $type = NULL) { $type = node_type_set_defaults(array('custom' => 1, 'locked' => 0)); } + $config = config('node.settings.' . $type->type); + // Make the type object available to implementations of hook_form_alter. $form['#node_type'] = $type; @@ -172,10 +174,10 @@ function node_type_form($form, &$form_state, $type = NULL) { $form['submission']['title_label']['#description'] = t('This content type does not have a title field.'); $form['submission']['title_label']['#required'] = FALSE; } - $form['submission']['node_preview'] = array( + $form['submission']['preview'] = array( '#type' => 'radios', '#title' => t('Preview before submitting'), - '#default_value' => variable_get('node_preview_' . $type->type, DRUPAL_OPTIONAL), + '#default_value' => $config->get('preview') ?: DRUPAL_OPTIONAL, '#options' => array( DRUPAL_DISABLED => t('Disabled'), DRUPAL_OPTIONAL => t('Optional'), @@ -195,9 +197,9 @@ function node_type_form($form, &$form_state, $type = NULL) { '#collapsed' => TRUE, '#group' => 'additional_settings', ); - $form['workflow']['node_options'] = array('#type' => 'checkboxes', + $form['workflow']['options'] = array('#type' => 'checkboxes', '#title' => t('Default options'), - '#default_value' => variable_get('node_options_' . $type->type, array('status', 'promote')), + '#default_value' => $config->get('options') ?: array('status', 'promote'), '#options' => array( 'status' => t('Published'), 'promote' => t('Promoted to front page'), @@ -234,10 +236,10 @@ function node_type_form($form, &$form_state, $type = NULL) { '#collapsed' => TRUE, '#group' => 'additional_settings', ); - $form['display']['node_submitted'] = array( + $form['display']['submitted'] = array( '#type' => 'checkbox', '#title' => t('Display author and date information.'), - '#default_value' => variable_get('node_submitted_' . $type->type, TRUE), + '#default_value' => !is_null($config->get('submitted')) ? $config->get('submitted') : TRUE, '#description' => t('Author username and publish date will be displayed.'), ); $form['old_type'] = array( @@ -377,6 +379,7 @@ function node_type_form_submit($form, &$form_state) { unset($variables['form_token'], $variables['op'], $variables['submit'], $variables['delete'], $variables['reset'], $variables['form_id'], $variables['form_build_id']); // Save or reset persistent variable values. + $node_type_settings = config('node.settings.' . $type->type); foreach ($variables as $key => $value) { $variable_new = $key . '_' . $type->type; $variable_old = $key . '_' . $type->old_type; @@ -384,12 +387,19 @@ function node_type_form_submit($form, &$form_state) { if (is_array($value)) { $value = array_keys(array_filter($value)); } + $node_type_settings->set($key, $value); + // @todo remove when comment and menu variables are converted. variable_set($variable_new, $value); - if ($variable_new != $variable_old) { variable_del($variable_old); } } + $node_type_settings->save(); + + // Remove old settings if needed. + if ($type->type != $type->old_type) { + config('node.settings.' . $type->old_type)->delete(); + } // Saving the content type after saving the variables allows modules to act // on those variables via hook_node_type_insert(). diff --git a/core/modules/node/content_types.js b/core/modules/node/content_types.js index 736440b..0a3f1d0 100644 --- a/core/modules/node/content_types.js +++ b/core/modules/node/content_types.js @@ -18,10 +18,10 @@ Drupal.behaviors.contentTypes = { }); $context.find('fieldset#edit-workflow').drupalSetSummary(function(context) { var vals = []; - $(context).find("input[name^='node_options']:checked").parent().each(function() { + $(context).find("input[name^='options']:checked").parent().each(function() { vals.push(Drupal.checkPlain($(this).text())); }); - if (!$(context).find('#edit-node-options-status').is(':checked')) { + if (!$(context).find('#edit-options-status').is(':checked')) { vals.unshift(Drupal.t('Not published')); } return vals.join(', '); @@ -43,7 +43,7 @@ Drupal.behaviors.contentTypes = { $context.find('input:checked').next('label').each(function() { vals.push(Drupal.checkPlain($(this).text())); }); - if (!$context.find('#edit-node-submitted').is(':checked')) { + if (!$context.find('#edit-submitted').is(':checked')) { vals.unshift(Drupal.t("Don't display post information")); } return vals.join(', '); diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index 215ad81..21c5e99 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -26,7 +26,10 @@ class NodeFormController extends EntityFormController { */ protected function prepareEntity(EntityInterface $node) { // Set up default values, if required. - $node_options = variable_get('node_options_' . $node->type, array('status', 'promote')); + $node_options = config('node.settings.' . $node->type)->get('options'); + if (is_null($node_options)) { + $node_options = array('status', 'promote'); + } // If this is a new node, fill in the default values. if (!isset($node->nid) || isset($node->is_new)) { foreach (array('status', 'promote', 'sticky') as $key) { @@ -250,7 +253,7 @@ public function form(array $form, array &$form_state, EntityInterface $node) { protected function actions(array $form, array &$form_state) { $element = parent::actions($form, $form_state); $node = $this->getEntity($form_state); - $preview_mode = variable_get('node_preview_' . $node->type, DRUPAL_OPTIONAL); + $preview_mode = config('node.settings.' . $node->type)->get('preview') ?: DRUPAL_OPTIONAL; $element['preview'] = array( '#access' => $preview_mode != DRUPAL_DISABLED, diff --git a/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/NodeBundle.php b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/NodeBundle.php new file mode 100644 index 0000000..aa58c17 --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/NodeBundle.php @@ -0,0 +1,141 @@ +type; + } +} diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php index 36baad2..2499aef 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php @@ -107,7 +107,7 @@ function testUnpublishedNodeCreation() { config('system.site')->set('page.front', 'test-page')->save(); // Set "Basic page" content type to be unpublished by default. - variable_set('node_options_page', array()); + config('node.settings.page')->set('options', array())->save(); // Create a node. $edit = array(); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodePostSettingsTest.php b/core/modules/node/lib/Drupal/node/Tests/NodePostSettingsTest.php index ce48614..2a8821e 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodePostSettingsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodePostSettingsTest.php @@ -34,7 +34,7 @@ function testPagePostInfo() { // Set "Basic page" content type to display post information. $edit = array(); - $edit['node_submitted'] = TRUE; + $edit['submitted'] = TRUE; $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); // Create a node. @@ -57,7 +57,7 @@ function testPageNotPostInfo() { // Set "Basic page" content type to display post information. $edit = array(); - $edit['node_submitted'] = FALSE; + $edit['submitted'] = FALSE; $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); // Create a node. diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTypePersistenceTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTypePersistenceTest.php index c51b5a0..ba84e9d 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTypePersistenceTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTypePersistenceTest.php @@ -32,9 +32,9 @@ function testNodeTypeCustomizationPersistence() { // Enable poll and verify that the node type is in the DB and is not // disabled. $this->drupalPost('admin/modules', $poll_enable, t('Save configuration')); - $disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchField(); - $this->assertNotIdentical($disabled, FALSE, 'Poll node type found in the database'); - $this->assertEqual($disabled, 0, 'Poll node type is not disabled'); + $poll = entity_load('node_bundle', 'poll'); + $this->assertNotIdentical($poll->disabled, FALSE, 'Poll node type found in the database'); + $this->assertEqual($poll->disabled, 0, 'Poll node type is not disabled'); // Check that poll node type (uncustomized) shows up. $this->drupalGet('node/add'); @@ -51,17 +51,17 @@ function testNodeTypeCustomizationPersistence() { // Disable poll and check that the node type gets disabled. $this->drupalPost('admin/modules', $poll_disable, t('Save configuration')); - $disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchField(); - $this->assertEqual($disabled, 1, 'Poll node type is disabled'); + $poll = entity_load('node_bundle', 'poll'); + $this->assertEqual($poll->disabled, 1, 'Poll node type is disabled'); $this->drupalGet('node/add'); $this->assertNoText('poll', 'poll type is not found on node/add'); // Reenable poll and check that the customization survived the module // disable. $this->drupalPost('admin/modules', $poll_enable, t('Save configuration')); - $disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchField(); - $this->assertNotIdentical($disabled, FALSE, 'Poll node type found in the database'); - $this->assertEqual($disabled, 0, 'Poll node type is not disabled'); + $poll = entity_load('node_bundle', 'poll'); + $this->assertNotIdentical($poll->disabled, FALSE, 'Poll node type found in the database'); + $this->assertEqual($poll->disabled, 0, 'Poll node type is not disabled'); $this->drupalGet('node/add'); $this->assertText($description, 'Customized description found'); @@ -70,8 +70,8 @@ function testNodeTypeCustomizationPersistence() { $edit = array('uninstall[poll]' => 'poll'); $this->drupalPost('admin/modules/uninstall', $edit, t('Uninstall')); $this->drupalPost(NULL, array(), t('Uninstall')); - $disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchField(); - $this->assertTrue($disabled, 'Poll node type is in the database and is disabled'); + $poll = entity_load('node_bundle', 'poll'); + $this->assertTrue($poll->disabled, 'Poll node type is in the database and is disabled'); $this->drupalGet('node/add'); $this->assertNoText('poll', 'poll type is no longer found on node/add'); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php index 944af15..b989e14 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php @@ -53,7 +53,7 @@ function testNodeTypeCreation() { // Create a content type programmaticaly. $type = $this->drupalCreateContentType(); - $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $type->type))->fetchField(); + $type_exists = (bool) entity_load('node_bundle', $type->type); $this->assertTrue($type_exists, 'The new content type has been created in the database.'); // Login a test user. @@ -72,7 +72,7 @@ function testNodeTypeCreation() { 'type' => 'foo', ); $this->drupalPost('admin/structure/types/add', $edit, t('Save content type')); - $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => 'foo'))->fetchField(); + $type_exists = (bool) entity_load('node_bundle', 'foo'); $this->assertTrue($type_exists, 'The new content type has been created in the database.'); } diff --git a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php index b429e07..6f0eafd 100644 --- a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php @@ -58,7 +58,7 @@ function testPagePreviewWithRevisions() { $title_key = "title"; $body_key = "body[$langcode][0][value]"; // Force revision on "Basic page" content. - variable_set('node_options_page', array('status', 'revision')); + config('node.settings.page')->set('options', array('status', 'revision')); // Fill in node creation form and preview node. $edit = array(); diff --git a/core/modules/node/node.install b/core/modules/node/node.install index f9c30a5..7217118 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -34,7 +34,7 @@ function node_schema() { 'default' => NULL, ), 'type' => array( - 'description' => 'The {node_type}.type of this node.', + 'description' => 'The type of this node.', 'type' => 'varchar', 'length' => 32, 'not null' => TRUE, @@ -281,103 +281,6 @@ function node_schema() { ), ); - $schema['node_type'] = array( - 'description' => 'Stores information about all defined {node} types.', - 'fields' => array( - 'type' => array( - 'description' => 'The machine-readable name of this type.', - 'type' => 'varchar', - 'length' => 32, - 'not null' => TRUE, - ), - 'name' => array( - 'description' => 'The human-readable name of this type.', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - 'translatable' => TRUE, - ), - 'base' => array( - 'description' => 'The base string used to construct callbacks corresponding to this node type.', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - ), - 'module' => array( - 'description' => 'The module defining this node type.', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - ), - 'description' => array( - 'description' => 'A brief description of this type.', - 'type' => 'text', - 'not null' => TRUE, - 'size' => 'medium', - 'translatable' => TRUE, - ), - 'help' => array( - 'description' => 'Help information shown to the user when creating a {node} of this type.', - 'type' => 'text', - 'not null' => TRUE, - 'size' => 'medium', - 'translatable' => TRUE, - ), - 'has_title' => array( - 'description' => 'Boolean indicating whether this type uses the {node}.title field.', - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'size' => 'tiny', - ), - 'title_label' => array( - 'description' => 'The label displayed for the title field on the edit form.', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - 'translatable' => TRUE, - ), - 'custom' => array( - 'description' => 'A boolean indicating whether this type is defined by a module (FALSE) or by a user via Add content type (TRUE).', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'size' => 'tiny', - ), - 'modified' => array( - 'description' => 'A boolean indicating whether this type has been modified by an administrator; currently not used in any way.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'size' => 'tiny', - ), - 'locked' => array( - 'description' => 'A boolean indicating whether the administrator can change the machine name of this type.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'size' => 'tiny', - ), - 'disabled' => array( - 'description' => 'A boolean indicating whether the node type is disabled.', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'size' => 'tiny' - ), - 'orig_type' => array( - 'description' => 'The original machine-readable name of this node type. This may be different from the current type name if the locked field is 0.', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - ), - 'primary key' => array('type'), - ); - $schema['block_node_type'] = array( 'description' => 'Sets up display criteria for blocks based on content types', 'fields' => array( @@ -397,7 +300,7 @@ function node_schema() { 'type' => 'varchar', 'length' => 32, 'not null' => TRUE, - 'description' => "The machine-readable name of this type from {node_type}.type.", + 'description' => "The machine-readable name of this type.", ), ), 'primary key' => array('module', 'delta', 'type'), @@ -464,17 +367,10 @@ function node_install() { */ function node_uninstall() { // Delete node type variables. - $types = db_query('SELECT type FROM {node_type}')->fetchCol(); - foreach ($types as $type) { - db_delete('variable') - ->condition(db_or() - ->condition('name', 'node_preview_' . $type) - ->condition('name', 'node_options_' . $type) - ->condition('name', 'node_submitted_' . $type) - ->condition('name', 'node_permissions_' . $type) - ->condition('name', 'node_type_language_translation_enabled_' . $type) - ) - ->execute(); + $content_types = config_get_storage_names_with_prefix('node.type'); + foreach ($content_types as $content_type) { + $type = config($content_type)->get('type'); + config('node.settings.' . $type)->delete(); config('language.settings')->clear('node. ' . $type . '.language.default_configuration')->save(); } @@ -533,8 +429,9 @@ function _update_7000_node_get_types() { * @ingroup config_upgrade */ function node_update_8001() { - $types = db_query('SELECT type FROM {node_type}')->fetchCol(); - foreach ($types as $type) { + $content_types = config_get_storage_names_with_prefix('node.type'); + foreach ($content_types as $content_type) { + $type = config($content_type)->get('type'); $node_type_language = update_variable_get('language_content_type_' . $type); if (isset($node_type_language)) { update_variable_set('node_type_language_' . $type, $node_type_language); @@ -561,8 +458,9 @@ function node_update_8002() { * Rename node type language variable names. */ function node_update_8003() { - $types = db_query('SELECT type FROM {node_type}')->fetchCol(); - foreach ($types as $type) { + $content_types = config_get_storage_names_with_prefix('node.type'); + foreach ($content_types as $content_type) { + $type = config($content_type)->get('type'); update_variable_set('node_type_language_default_' . $type, LANGUAGE_NOT_SPECIFIED); $node_type_language = update_variable_get('node_type_language_' . $type, 0); if ($node_type_language == 0) { @@ -681,8 +579,9 @@ function node_update_8006(&$sandbox) { * Move the language default values to config. */ function node_update_8007() { - $types = db_query('SELECT type FROM {node_type}')->fetchCol(); - foreach ($types as $type) { + $content_types = config_get_storage_names_with_prefix('node.type'); + foreach ($content_types as $content_type) { + $type = config($content_type)->get('type'); $language_default = update_variable_get('node_type_language_default_' . $type, NULL); $language_hidden = update_variable_get('node_type_language_hidden_' . $type, NULL); if (isset($language_default) || isset($language_hidden)) { @@ -740,6 +639,46 @@ function node_update_8011() { } /** + * Convert existing node types to the new config system. + * + * @ingroup config_upgrade + */ +function node_update_8012() { + $result = db_select('node_type', 'nt') + ->fields('nt') + ->execute() + ->fetchAllAssoc('name', PDO::FETCH_ASSOC); + foreach ($result as $name => $node_type) { + + // Node type. + $config = config('node.type.' . $name); + $config->setData($node_type); + $config->save(); + + // Node type settings. + $variables = db_select('variable', 'v') + ->fields('v') + ->condition('name', 'node_%_' . $name) + ->execute(); + $node_type_settings = config('node.settings.' . $name); + foreach ($variables as $variable) { + $node_type_settings->set(str_replace(array('node_', '_' . $name), '', $variable->name), unserialize($variable->value)); + update_variable_del($variable->name); + } + $node_type_settings->save(); + } +} + +/** + * Remove the {node_type} table. + * + * @ingroup config_upgrade + */ +function node_update_8013() { + db_drop_table('node_type'); +} + +/** * @} End of "addtogroup updates-7.x-to-8.x" * The next series of updates should start at 9000. */ diff --git a/core/modules/node/node.module b/core/modules/node/node.module index e6251ab..5cfd566 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -538,10 +538,10 @@ function node_type_load($name) { */ function node_type_save($info) { $existing_type = !empty($info->old_type) ? $info->old_type : $info->type; - $is_existing = (bool) db_query_range('SELECT 1 FROM {node_type} WHERE type = :type', 0, 1, array(':type' => $existing_type))->fetchField(); + $is_existing = (bool) entity_load('node_bundle', $existing_type); $type = node_type_set_defaults($info); - $fields = array( + $content_type = entity_create('node_bundle', array( 'type' => (string) $type->type, 'name' => (string) $type->name, 'base' => (string) $type->base, @@ -554,13 +554,11 @@ function node_type_save($info) { 'locked' => (int) $type->locked, 'disabled' => (int) $type->disabled, 'module' => $type->module, - ); + )); if ($is_existing) { - db_update('node_type') - ->fields($fields) - ->condition('type', $existing_type) - ->execute(); + + $content_type->save(); if (!empty($type->old_type) && $type->old_type != $type->type) { field_attach_rename_bundle('node', $type->old_type, $type->type); @@ -569,10 +567,8 @@ function node_type_save($info) { $status = SAVED_UPDATED; } else { - $fields['orig_type'] = (string) $type->orig_type; - db_insert('node_type') - ->fields($fields) - ->execute(); + $content_type->orig_type = (string) $type->orig_type; + $content_type->save(); field_attach_create_bundle('node', $type->type); @@ -683,9 +679,7 @@ function node_field_extra_fields() { */ function node_type_delete($name) { $type = node_type_load($name); - db_delete('node_type') - ->condition('type', $name) - ->execute(); + entity_delete_multiple('node_type', array($name)); field_attach_delete_bundle('node', $name); module_invoke_all('node_type_delete', $type); @@ -715,7 +709,7 @@ function node_type_update_nodes($old_type, $type) { * Builds and returns the list of available node types. * * The list of types is built by invoking hook_node_info() on all modules and - * comparing this information with the node types in the {node_type} table. + * comparing this information with the node types stored in configuration. * These two information sources are not synchronized during module installation * until node_types_rebuild() is called. * @@ -728,8 +722,8 @@ function node_type_update_nodes($old_type, $type) { * - names: Associative array of the names of node types, keyed by the type. * - types: Associative array of node type objects, keyed by the type. * Both of these arrays will include new types that have been defined by - * hook_node_info() implementations but not yet saved in the {node_type} - * table. These are indicated in the type object by $type->is_new being set + * hook_node_info() implementations but not yet saved as configuration. + * These are indicated in the type object by $type->is_new being set * to the value 1. These arrays will also include obsolete types: types that * were previously defined by modules that have now been disabled, or for * whatever reason are no longer being defined in hook_node_info() @@ -761,15 +755,15 @@ function _node_types_build($rebuild = FALSE) { $_node_types->names[$type] = $info['name']; } } - $query = db_select('node_type', 'nt') - ->addTag('translatable') - ->addTag('node_type_access') - ->fields('nt') - ->orderBy('nt.type', 'ASC'); - if (!$rebuild) { - $query->condition('disabled', 0); - } - foreach ($query->execute() as $type_object) { + + // Do not use entity_load_multiple() as we'll end up in a + // neverending loop. + $content_types = config_get_storage_names_with_prefix('node.type.'); + foreach ($content_types as $config) { + $type_object = (object) config($config)->get(); + if (!$rebuild && $type_object->disabled) { + continue; + } $type_db = $type_object->type; // Original disabled value. $disabled = $type_object->disabled; @@ -1201,7 +1195,8 @@ function template_preprocess_node(&$variables) { field_attach_preprocess('node', $node, $variables['content'], $variables); // Display post information only on certain node types. - if (variable_get('node_submitted_' . $node->type, TRUE)) { + $submitted = config('node.settings.' . $node->type)->get('submitted'); + if (is_null($submitted) || $submitted) { $variables['display_submitted'] = TRUE; $variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date'])); $variables['user_picture'] = theme_get_setting('toggle_node_user_picture') ? theme('user_picture', array('account' => $node)) : ''; @@ -2939,7 +2934,7 @@ function node_list_permissions($type) { function node_permissions_get_configured_types() { $configured_types = array(); foreach (node_type_get_types() as $name => $type) { - if (variable_get('node_permissions_' . $name, 1)) { + if (config('node.settings.' . $name)->get('permissions') ?: TRUE) { $configured_types[$name] = $type; } } diff --git a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php index e6fd10d..765eb62 100644 --- a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php +++ b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php @@ -55,7 +55,7 @@ function testAliasTranslation() { ); $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), 'Basic page content type has been updated.'); - variable_set('node_type_language_translation_enabled_page', TRUE); + config('node.settings.page')->set('language_translation_enabled', TRUE); $english_node = $this->drupalCreateNode(array('type' => 'page')); $english_alias = $this->randomName(); diff --git a/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php b/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php index d1ce358..a82ab61 100644 --- a/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php +++ b/core/modules/poll/lib/Drupal/poll/Tests/PollTranslateTest.php @@ -54,7 +54,7 @@ function testPollTranslate() { // Set "Poll" content type to use multilingual support with translation. $this->drupalGet('admin/structure/types/manage/poll'); - $edit = array('language_configuration[language_hidden]' => FALSE, 'node_type_language_translation_enabled' => TRUE); + $edit = array('language_configuration[language_hidden]' => FALSE, 'type_language_translation_enabled' => TRUE); $this->drupalPost('admin/structure/types/manage/poll', $edit, t('Save content type')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Poll')), 'Poll content type has been updated.'); diff --git a/core/modules/rest/lib/Drupal/rest/Tests/DeleteTest.php b/core/modules/rest/lib/Drupal/rest/Tests/DeleteTest.php index 187c386..00005a7 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/DeleteTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/DeleteTest.php @@ -112,6 +112,8 @@ protected function entityCreate($entity_type) { return entity_create('node', array('title' => $this->randomString())); case 'user': return entity_create('user', array('name' => $this->randomName())); + case 'node_type': + return entity_create('node_bundle', array('type' => 'article', 'name' => $this->randomName())); default: return entity_create($entity_type, array()); } diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index e9c0860..8a5f680 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -2598,7 +2598,7 @@ function hook_schema() { 'not null' => TRUE, 'default' => 0), 'type' => array( - 'description' => 'The {node_type} of this node.', + 'description' => 'The type of this node.', 'type' => 'varchar', 'length' => 32, 'not null' => TRUE, diff --git a/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php b/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php index bc9094d..b106e70 100644 --- a/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php +++ b/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php @@ -51,7 +51,7 @@ function setUp() { // Set "Basic page" content type to use multilingual support with // translation. $this->drupalGet('admin/structure/types/manage/page'); - $edit = array('language_configuration[language_hidden]' => FALSE, 'node_type_language_translation_enabled' => TRUE); + $edit = array('language_configuration[language_hidden]' => FALSE, 'type_language_translation_enabled' => TRUE); $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), 'Basic page content type has been updated.'); @@ -230,7 +230,7 @@ function testLanguageSwitcherBlockIntegration() { // Disable translation support to check that the language switcher is left // untouched only for new nodes. $this->drupalLogin($this->admin_user); - $edit = array('language_configuration[language_hidden]' => TRUE, 'node_type_language_translation_enabled' => FALSE); + $edit = array('language_configuration[language_hidden]' => TRUE, 'type_language_translation_enabled' => FALSE); $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); $this->drupalLogin($this->translator); diff --git a/core/modules/translation/translation.module b/core/modules/translation/translation.module index 0fc5332..188686c 100644 --- a/core/modules/translation/translation.module +++ b/core/modules/translation/translation.module @@ -157,10 +157,10 @@ function translation_form_node_type_form_alter(&$form, &$form_state) { // TODO: When form #states allows OR values change this to use form #states. $form['#attached']['library'][] = array('translation', 'drupal.translation'); // Add translation option to content type form. - $form['language']['node_type_language_translation_enabled'] = array( + $form['language']['type_language_translation_enabled'] = array( '#type' => 'checkbox', '#title' => t('Enable translation'), - '#default_value' => variable_get('node_type_language_translation_enabled_' . $form['#node_type']->type, FALSE), + '#default_value' => config('node.settings.' . $form['#node_type']->type)->get('type_language_translation_enabled'), '#element_validate' => array('translation_node_type_language_translation_enabled_validate'), '#prefix' => "", ); @@ -173,11 +173,11 @@ function translation_form_node_type_form_alter(&$form, &$form_state) { * and language selector is not hidden, translation cannot be enabled. */ function translation_node_type_language_translation_enabled_validate($element, &$form_state, $form) { - if (language_is_locked($form_state['values']['language_configuration']['langcode']) && $form_state['values']['language_configuration']['language_hidden'] && $form_state['values']['node_type_language_translation_enabled']) { + if (language_is_locked($form_state['values']['language_configuration']['langcode']) && $form_state['values']['language_configuration']['language_hidden'] && $form_state['values']['language_translation_enabled']) { foreach (language_list(LANGUAGE_LOCKED) as $language) { $locked_languages[] = $language->name; } - form_set_error('node_type_language_translation_enabled', t('Translation is not supported if language is always one of: @locked_languages', array('@locked_languages' => implode(", ", $locked_languages)))); + form_set_error('language_translation_enabled', t('Translation is not supported if language is always one of: @locked_languages', array('@locked_languages' => implode(", ", $locked_languages)))); } } @@ -507,7 +507,7 @@ function translation_node_get_translations($tnid) { * TRUE if translation is supported, and FALSE if not. */ function translation_supported_type($type) { - return variable_get('node_type_language_translation_enabled_' . $type, FALSE); + return config('node.settings.' . $type)->get('type_language_translation_enabled'); } /** diff --git a/core/profiles/standard/standard.install b/core/profiles/standard/standard.install index b4dc761..7b4a36c 100644 --- a/core/profiles/standard/standard.install +++ b/core/profiles/standard/standard.install @@ -236,12 +236,15 @@ function standard_install() { rdf_mapping_save($rdf_mapping); } - // Default "Basic page" to not be promoted and have comments disabled. - variable_set('node_options_page', array('status')); + // Comments are disabled for page. variable_set('comment_page', COMMENT_NODE_HIDDEN); - // Don't display date and author information for "Basic page" nodes by default. - variable_set('node_submitted_page', FALSE); + // Don't display date and author information for "Basic page" nodes + // and default "Basic page" to not be promoted. + config('node.settings.page') + ->set('submitted', FALSE) + ->set('options', array('status')) + ->save(); // Enable user picture support and set the default to a square thumbnail option. variable_set('user_pictures', '1');