Form constructor for the node type editing form.
$type: (optional) An object representing the node type, when editing an existing node type.
function node_type_form($form, &$form_state, $type = NULL) {
if (!isset($type->type)) {
// This is a new type. Node module managed types are custom and unlocked.
$type = node_type_set_defaults(array(
'custom' => 1,
'locked' => 0,
));
}
// Make the type object available to implementations of hook_form_alter.
$form['#node_type'] = $type;
$form['name'] = array(
'#title' => t('Name'),
'#type' => 'textfield',
'#default_value' => $type->name,
'#description' => t('The human-readable name of this content type. This text will be displayed as part of the list on the <em>Add new content</em> page. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.'),
'#required' => TRUE,
'#size' => 30,
);
$form['type'] = array(
'#type' => 'machine_name',
'#default_value' => $type->type,
'#maxlength' => 32,
'#disabled' => $type->locked,
'#machine_name' => array(
'exists' => 'node_type_load',
'source' => array(
'name',
),
),
'#description' => t('A unique machine-readable name for this content type. It must only contain lowercase letters, numbers, and underscores. This name will be used for constructing the URL of the %node-add page, in which underscores will be converted into hyphens.', array(
'%node-add' => t('Add new content'),
)),
);
$form['description'] = array(
'#title' => t('Description'),
'#type' => 'textarea',
'#default_value' => $type->description,
'#description' => t('Describe this content type. The text will be displayed on the <em>Add new content</em> page.'),
);
$form['additional_settings'] = array(
'#type' => 'vertical_tabs',
'#attached' => array(
'library' => array(
array(
'node',
'drupal.content_types',
),
),
),
);
$form['submission'] = array(
'#type' => 'details',
'#title' => t('Submission form settings'),
'#group' => 'additional_settings',
);
$form['submission']['title_label'] = array(
'#title' => t('Title field label'),
'#type' => 'textfield',
'#default_value' => $type->title_label,
'#required' => TRUE,
);
if (!$type->has_title) {
// Avoid overwriting a content type that intentionally does not have a
// title field.
$form['submission']['title_label']['#attributes'] = array(
'disabled' => 'disabled',
);
$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(
'#type' => 'radios',
'#title' => t('Preview before submitting'),
'#default_value' => variable_get('node_preview_' . $type->type, DRUPAL_OPTIONAL),
'#options' => array(
DRUPAL_DISABLED => t('Disabled'),
DRUPAL_OPTIONAL => t('Optional'),
DRUPAL_REQUIRED => t('Required'),
),
);
$form['submission']['help'] = array(
'#type' => 'textarea',
'#title' => t('Explanation or submission guidelines'),
'#default_value' => $type->help,
'#description' => t('This text will be displayed at the top of the page when creating or editing content of this type.'),
);
$form['workflow'] = array(
'#type' => 'details',
'#title' => t('Publishing options'),
'#collapsed' => TRUE,
'#group' => 'additional_settings',
);
$form['workflow']['node_options'] = array(
'#type' => 'checkboxes',
'#title' => t('Default options'),
'#default_value' => variable_get('node_options_' . $type->type, array(
'status',
'promote',
)),
'#options' => array(
'status' => t('Published'),
'promote' => t('Promoted to front page'),
'sticky' => t('Sticky at top of lists'),
'revision' => t('Create new revision'),
),
'#description' => t('Users with the <em>Administer content</em> permission will be able to override these options.'),
);
if (module_exists('language')) {
$form['language'] = array(
'#type' => 'details',
'#title' => t('Language settings'),
'#collapsed' => TRUE,
'#group' => 'additional_settings',
);
$language_configuration = language_get_default_configuration('node', $type->type);
$form['language']['language_configuration'] = array(
'#type' => 'language_configuration',
'#entity_information' => array(
'entity_type' => 'node',
'bundle' => $type->type,
),
'#default_value' => $language_configuration,
);
$form['#submit'][] = 'language_configuration_element_submit';
}
$form['display'] = array(
'#type' => 'details',
'#title' => t('Display settings'),
'#collapsed' => TRUE,
'#group' => 'additional_settings',
);
$form['display']['node_submitted'] = array(
'#type' => 'checkbox',
'#title' => t('Display author and date information.'),
'#default_value' => variable_get('node_submitted_' . $type->type, TRUE),
'#description' => t('Author username and publish date will be displayed.'),
);
$form['old_type'] = array(
'#type' => 'value',
'#value' => $type->type,
);
$form['orig_type'] = array(
'#type' => 'value',
'#value' => isset($type->orig_type) ? $type->orig_type : '',
);
$form['base'] = array(
'#type' => 'value',
'#value' => $type->base,
);
$form['custom'] = array(
'#type' => 'value',
'#value' => $type->custom,
);
$form['modified'] = array(
'#type' => 'value',
'#value' => $type->modified,
);
$form['locked'] = array(
'#type' => 'value',
'#value' => $type->locked,
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save content type'),
'#weight' => 40,
);
if ($type->custom) {
if (!empty($type->type)) {
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete content type'),
'#weight' => 45,
);
}
}
$form['#submit'][] = 'node_type_form_submit';
return $form;
}