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..e755a7a 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -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( diff --git a/core/modules/node/node.module b/core/modules/node/node.module index a6a64ae..6212039 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); @@ -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;