diff --git a/core/modules/node/content_types.inc b/core/modules/node/content_types.inc index 538b19f..041ffd0 100644 --- a/core/modules/node/content_types.inc +++ b/core/modules/node/content_types.inc @@ -127,8 +127,11 @@ function node_type_form($form, &$form_state, $type = NULL) { $form['type'] = array( '#type' => 'machine_name', - '#default_value' => $type->type, - '#maxlength' => 32, + '#field_prefix' => 'custom_', + // Remove the 'custom_' prefix from the default value. + '#default_value' => preg_replace('/^custom_/', '', $type->type), + // 32 characters minus the 'custom_' prefix. + '#maxlength' => 25, '#disabled' => $type->locked, '#machine_name' => array( 'exists' => 'node_type_load', @@ -306,7 +309,8 @@ function _node_characters($length) { */ function node_type_form_validate($form, &$form_state) { $type = new stdClass(); - $type->type = trim($form_state['values']['type']); + $type->type = 'custom_' . trim($form_state['values']['type']); + form_set_value($form['type'], $type->type, $form_state); $type->name = trim($form_state['values']['name']); // Work out what the type was before the user submitted this form diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php index 944af15..d692eab 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php @@ -72,8 +72,21 @@ 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 = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => 'custom_foo'))->fetchField(); $this->assertTrue($type_exists, 'The new content type has been created in the database.'); + + // Create a content type with the same machine name as one provided by a + // disabled module. + $edit = array( + 'name' => $this->randomName(), + 'type' => 'node_type_test', + ); + $this->drupalPost('admin/structure/types/add', $edit, t('Save content type')); + + // Enable the module with the conflicting content type name. + module_enable(array('node_type_test')); + $entity_info = entity_get_info('node'); + $this->assertEqual($entity_info['bundles']['node_type_test']['label'], t('Test node type'), 'The module-defined content type was installed.'); } /**