diff --git a/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/ContentType.php b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/ContentType.php new file mode 100644 index 0000000..09ca03e --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/ContentType.php @@ -0,0 +1,141 @@ +type; + } +} diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTypePersistenceTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTypePersistenceTest.php index c51b5a0..519c137 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('contenttype', '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('contenttype', '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('contenttype', '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('contenttype', '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..b6faf0d 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('contenttype', $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('contenttype', 'foo'); $this->assertTrue($type_exists, 'The new content type has been created in the database.'); } diff --git a/core/modules/node/node.install b/core/modules/node/node.install index f9c30a5..4ce60b9 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,8 +367,9 @@ function node_install() { */ function node_uninstall() { // Delete node type variables. - $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'); db_delete('variable') ->condition(db_or() ->condition('name', 'node_preview_' . $type) @@ -526,15 +430,38 @@ function _update_7000_node_get_types() { */ /** + * Convert existing node types to the new config system. + */ +function node_update_8000() { + $result = db_select('node_type', 'nt') + ->fields('nt') + ->execute() + ->fetchAllAssoc('name', PDO::FETCH_ASSOC); + foreach ($result as $name => $node_type) { + $config = config('node.type.' . $name); + $config->setData($node_type); + $config->save(); + } +} + +/** + * Remove the {node_type} table. + */ +function node_update_8001() { + db_drop_table('node_type'); +} + +/** * Rename node type language variable names. * * @see http://drupal.org/node/540294 * * @ingroup config_upgrade */ -function node_update_8001() { - $types = db_query('SELECT type FROM {node_type}')->fetchCol(); - foreach ($types as $type) { +function node_update_8002() { + $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); @@ -546,7 +473,7 @@ function node_update_8001() { /** * Rename node.language field to node.langcode. */ -function node_update_8002() { +function node_update_8003() { $spec = array( 'description' => 'The {language}.langcode of this node.', 'type' => 'varchar', @@ -560,9 +487,10 @@ 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) { +function node_update_8004() { + $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) { @@ -583,7 +511,7 @@ function node_update_8003() { /** * Create a UUID column for nodes. */ -function node_update_8004() { +function node_update_8005() { $spec = array( 'description' => 'Unique Key: Universally unique identifier for this entity.', 'type' => 'varchar', @@ -607,7 +535,7 @@ function node_update_8004() { /** * Make *id fields unsigned. */ -function node_update_8005() { +function node_update_8006() { db_drop_index('node', 'uid'); db_change_field('node', 'uid', 'uid', array( @@ -664,7 +592,7 @@ function node_update_8005() { /** * Generate a UUID for all nodes. */ -function node_update_8006(&$sandbox) { +function node_update_8007(&$sandbox) { if (!isset($sandbox['progress'])) { $sandbox['progress'] = 0; $sandbox['last'] = 0; @@ -680,9 +608,10 @@ 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) { +function node_update_8008() { + $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)) { @@ -695,7 +624,7 @@ function node_update_8007() { /** * Rename default menu names. */ -function node_update_8008() { +function node_update_8009() { // System menu's new block deltas are prefixed with 'menu-'. $map = array( 'navigation' => 'menu-tools', @@ -717,7 +646,7 @@ function node_update_8008() { * * @ingroup config_upgrade */ -function node_update_8009() { +function node_update_8010() { update_variables_to_config('node.settings', array('default_nodes_main' => 'items_per_page')); } @@ -726,7 +655,7 @@ function node_update_8009() { * * @ingroup config_upgrade */ -function node_update_8010() { +function node_update_8011() { update_variables_to_state(array('node_access_needs_rebuild' => 'node.node_access_needs_rebuild')); } @@ -735,7 +664,7 @@ function node_update_8010() { * * @ingroup config_upgrade */ -function node_update_8011() { +function node_update_8012() { update_variables_to_state(array('node_cron_last' =>'node.cron_last')); } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index a6a64ae..b870fe6 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('contenttype', $existing_type); $type = node_type_set_defaults($info); - $fields = array( + $content_type = entity_create('contenttype', 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('contenttype', 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; diff --git a/core/modules/rest/lib/Drupal/rest/Tests/DeleteTest.php b/core/modules/rest/lib/Drupal/rest/Tests/DeleteTest.php index 187c386..04b21db 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 'contenttype': + return entity_create('contenttype', 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 d10d3e0..65056ff 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -2643,7 +2643,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,