Finishing that last commit.

5.x
Neil Drumm 2006-08-06 23:06:56 +00:00
parent 129c8eb18c
commit cb036dbb43
2 changed files with 397 additions and 100 deletions

View File

@ -0,0 +1,397 @@
<?php
// $Id$
/**
* @file
* Content type editing UI.
*/
/**
* Displays the content type admin overview page.
*/
function node_overview_types() {
$types = node_get_types();
$names = node_get_types('names');
$header = array(t('Name'), t('Type'), t('Description'), array('data' => t('Operations'), 'colspan' => '2'));
$rows = array();
foreach ($names as $key => $name) {
$type = $types[$key];
if (module_exist($type->module)) {
$name = check_plain($name);
$type_url_str = str_replace('_', '-', $type->type);
// Populate the operations field.
$operations = array();
// Set the edit column.
$operations[] = array('data' => l(t('edit'), 'admin/content/types/'. $type_url_str));
// Set the delete column.
if ($type->custom) {
$operations[] = array('data' => l(t('delete'), 'admin/content/types/'. $type_url_str .'/delete'));
}
else {
$operations[] = array('data' => '');
}
$row = array(array('data' => l($name, 'admin/content/types/'. $type_url_str), 'class' => $class), array('data' => check_plain($type->type), 'class' => $class), array('data' => check_plain($type->description), 'class' => $class));
foreach ($operations as $operation) {
$operation['class'] = $class;
$row[] = $operation;
}
$rows[] = $row;
}
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No content types available.'), 'colspan' => '5', 'class' => 'message'));
}
return theme('table', $header, $rows);
}
/**
* Generates the node type editing form.
*/
function node_type_form($type = NULL) {
if (!isset($type->type)) {
$type = new stdClass();
$type->type = $type->name = $type->module = $type->description = $type->help = '';
$type->min_word_count = 0;
$type->has_title = TRUE;
$type->has_body = TRUE;
$type->title_label = t('Title');
$type->body_label = t('Body');
$type->custom = TRUE;
$type->modified = FALSE;
$type->locked = FALSE;
}
$form['identity'] = array(
'#type' => 'fieldset',
'#title' => t('Identification'),
);
$form['identity']['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>create content</em> page. It is recommended that this name consists only of lowercase letters, numbers, and <strong>spaces</strong>. The name must be unique to this content type.'),
'#required' => TRUE,
);
if (!$type->locked) {
$form['identity']['type'] = array(
'#title' => t('Type'),
'#type' => 'textfield',
'#default_value' => $type->type,
'#maxlength' => 32,
'#required' => TRUE,
'#description' => t('The machine-readable name of this content type. This text will be used for constructing the URL of the <em>create content</em> page for this content type. It is recommended that this name consists only of lowercase letters, numbers, and <strong>underscores</strong>. Dashes are not allowed. Underscores will be converted into dashes when constructing the URL of the <em>create content</em> page. The name must be unique to this content type.'),
);
}
else {
$form['identity']['type'] = array(
'#type' => 'value',
'#value' => $type->type,
);
$form['identity']['type_display'] = array(
'#title' => t('Type'),
'#type' => 'item',
'#value' => theme('placeholder', $type->type),
'#description' => t('The machine-readable name of this content type. This field cannot be modified for system-defined content types.'),
);
}
$form['submission'] = array(
'#type' => 'fieldset',
'#title' =>t('Submission form'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
if ($type->has_title) {
$form['submission']['title_label'] = array(
'#title' => t('Title field label'),
'#type' => 'textfield',
'#default_value' => $type->title_label,
'#description' => t('The label for the title field of this content type.'),
'#required' => TRUE,
);
}
if ($type->has_body) {
$form['submission']['body_label'] = array(
'#title' => t('Body field label'),
'#type' => 'textfield',
'#default_value' => $type->body_label,
'#description' => t('The label for the body field of this content type.'),
'#required' => TRUE,
);
}
$form['submission']['description'] = array(
'#title' => t('Description'),
'#type' => 'textarea',
'#default_value' => $type->description,
'#description' => t('A brief description of this content type. This text will be displayed as part of the list on the <em>create content</em> page.'),
);
$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 submission form for this content type. It is useful for helping or instructing your users.')
);
$form['submission']['min_word_count'] = array(
'#type' => 'select',
'#title' => t('Minimum number of words'),
'#default_value' => $type->min_word_count,
'#options' => drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)),
'#description' => t('The minimum number of words for the body field to be considered valid for this content type. This can be useful to rule out submissions that do not meet the site\'s standards, such as short test posts.')
);
$form['workflow'] = array(
'#type' => 'fieldset',
'#title' =>t('Workflow'),
'#collapsible' => TRUE,
);
$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 nodes</em> permission will be able to override these options.'),
);
$form['old_type'] = array(
'#type' => 'value',
'#value' => $type->type,
);
$form['orig_type'] = array(
'#type' => 'value',
'#value' => $type->orig_type,
);
$form['module'] = array(
'#type' => 'value',
'#value' => $type->module,
);
$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['submit'] = array(
'#type' => 'submit',
'#value' => t('Save content type'),
);
if ($type->custom) {
if (!empty($type->type)) {
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete content type'),
);
}
}
else {
$form['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset to defaults'),
);
}
return drupal_get_form('node_type_form', $form);
}
/**
* Implementation of hook_form_validate().
*/
function node_type_form_validate($form_id, $form_values) {
$type = new stdClass();
$type->type = trim($form_values['type']);
$type->name = trim($form_values['name']);
// Work out what the type was before the user submitted this form
$old_type = trim($form_values['old_type']);
if (empty($old_type)) {
$old_type = $type->type;
}
$types = node_get_types('names');
if (!$form_values['locked']) {
if (isset($types[$type->type]) && $type->type != $old_type) {
form_set_error('type', t('The machine-readable name %type is already taken.', array('%type' => theme('placeholder', $type->type))));
}
if (strpos($type->type, '-') !== FALSE) {
form_set_error('type', t('The machine-readable name cannot contain dashes.', array('%type' => theme('placeholder', $type->type))));
}
}
$names = array_flip($types);
if (isset($names[$type->name]) && $names[$type->name] != $old_type) {
form_set_error('name', t('The human-readable name %name is already taken.', array('%name' => theme('placeholder', $names[$type->name]))));
break;
}
}
/**
* Implementation of hook_form_submit().
*/
function node_type_form_submit($form_id, $form_values) {
$op = isset($_POST['op']) ? $_POST['op'] : '';
$type = new stdClass();
$type->type = trim($form_values['type']);
$type->name = trim($form_values['name']);
$type->orig_type = trim($form_values['orig_type']);
$type->old_type = isset($form_values['old_type']) ? $form_values['old_type'] : $type->type;
$type->description = $form_values['description'];
$type->help = $form_values['help'];
$type->min_word_count = $form_values['min_word_count'];
$type->title_label = $form_values['title_label'];
$type->body_label = $form_values['body_label'];
$type->module = !empty($form_values['module']) ? $form_values['module'] : 'node';
$type->has_title = $type->has_body = TRUE;
$type->custom = $form_values['custom'];
$type->modified = TRUE;
$type->locked = $form_values['locked'];
if ($op == t('Reset to defaults')) {
node_type_reset($type);
}
elseif ($op == t('Delete content type')) {
return 'admin/content/types/'. $type->old_type .'/delete';
}
if (!empty($form_values['old_type'])) {
if ($type->old_type != $type->type) {
$update_count = node_type_update_nodes($type->old_type, $type->type);
if ($update_count) {
drupal_set_message(t('Changed the content type of %update_count %posts from %old_type to %type.', array('%update_count' => $update_count, '%posts' => format_plural($update_count, 'post', 'posts'), '%old_type' => theme('placeholder', $type->old_type), '%type' => theme('placeholder', $type->type))));
cache_clear_all('filter:', TRUE);
}
}
}
$status = node_type_save($type);
// Remove everything that's been saved already - whatever's left is assumed
// to be a persistent variable.
foreach ($form_values as $key => $value) {
if (isset($type->$key)) {
unset($form_values[$key]);
}
}
unset($form_values['type_display'], $form_values['old_type'], $form_values['orig_type'], $form_values['submit'], $form_values['delete'], $form_values['reset'], $form_values['form_id']);
// Save or reset persistent variable values.
foreach ($form_values as $key => $value) {
$key .= '_'. $type->type;
if ($op == t('Reset to defaults')) {
variable_del($key);
}
else {
if (is_array($value)) {
$value = array_keys(array_filter($value));
}
variable_set($key, $value);
if ($type->old_type != $type->type) {
$key = str_replace($type->type, $type->old_type, $key);
variable_del($key);
}
}
}
node_types_rebuild();
menu_rebuild();
cache_clear_all();
$t_args = array('%name' => theme('placeholder', $type->name));
if ($op == t('Reset to defaults')) {
drupal_set_message(t('The content type %name has been reset to its default values.', $t_args));
return;
}
if ($status == SAVED_UPDATED) {
drupal_set_message(t('The content type %name has been updated.', $t_args));
}
elseif ($status == SAVED_NEW) {
drupal_set_message(t('The content type %name has been added.', $t_args));
watchdog('node', t('Added content type %name.', $t_args), WATCHDOG_NOTICE, l(t('view'), 'admin/content/types'));
}
return 'admin/content/types';
}
/**
* Resets all of the relevant fields of a module-defined node type to their
* default values.
*
* @param &$type
* The node type to reset. The node type is passed back by reference with its
* resetted values. If there is no module-defined info for this node type,
* then nothing happens.
*/
function node_type_reset(&$type) {
$info_array = module_invoke($type->module, 'node_info');
if (isset($info_array[$type->orig_type])) {
$info = _node_type_set_defaults($info_array[$type->orig_type]);
$info['type'] = $type->orig_type;
foreach ($info as $field => $value) {
$type->$field = $value;
}
}
}
/**
* Menu callback; delete a single content type.
*/
function node_type_delete($type) {
$form['type'] = array('#type' => 'value', '#value' => $type->type);
$form['name'] = array('#type' => 'value', '#value' => $type->name);
$message = t('Are you sure you want to delete the content type %type?', array('%type' => theme('placeholder', $type->name)));
$caption = '';
$num_nodes = db_num_rows(db_query("SELECT * FROM {node} WHERE type = '%s'", $type->type));
if ($num_nodes) {
$caption .= '<p>'. t('<strong>Warning:</strong> there %are currently %num_nodes %type %nodes on your site. %they may not be able to be displayed or edited correctly, once you have removed this content type.', array('%are' => format_plural($num_nodes, 'is', 'are'), '%num_nodes' => $num_nodes, '%type' => theme('placeholder', $type->name), '%nodes' => format_plural($num_nodes, 'node', 'nodes'), '%they' => format_plural($num_nodes, 'It', 'They'))) .'</p>';
}
$caption .= '<p>'. t('This action cannot be undone.') .'</p>';
return confirm_form('node_type_delete_form', $form, $message, 'admin/content/types', $caption, t('Delete'));
}
/**
* Process content type delete form submissions.
*/
function node_type_delete_form_submit($form_id, $form_values) {
db_query("DELETE FROM {node_type} WHERE type = '%s'", $form_values['type']);
$t_args = array('%name' => theme('placeholder', $form_values['name']));
drupal_set_message(t('The content type %name has been deleted.', $t_args));
watchdog('menu', t('Deleted content type %name.', $t_args), WATCHDOG_NOTICE);
node_types_rebuild();
menu_rebuild();
return 'admin/content/types';
}

View File

@ -1,100 +0,0 @@
<?php
// $Id$
/**
* @file
* Enables the creation of pages that can be added to the navigation system.
*/
/**
* Implementation of hook_help().
*/
function page_help($section) {
switch ($section) {
case 'admin/help#page':
$output = '<p>'. t('The page module allows users to create static pages, which are the most basic type of content. Pages are commonly collected in books via the book module. Users should create a page if the information on the page is static. An example would be an "about" page. ') .'</p>';
$output .= '<p>'. t('When a page is created, a user can set authoring information, configure publishing options, whether readers will be able to post comments. They can also select the content type of the page (e.g., full HTML, filtered HTML). ') .'</p>';
$output .= '<p>'. t('As an administrator, you can set the publishing default for a page (in its workflow): you can specify whether a page is by default published, sent to moderation, promoted to the front page, sticky at the top of lists, and whether revisions are enabled by default. You can set the permissions that different user roles have to view, create, and edit pages.') .'</p>';
$output .= '<p>'. t('If the location module is enabled, then location specific information can be added. If the trackback module is enabled trackbacks can be configured.') .'</p>';
$output .= t('<p>You can</p>
<ul>
<li>read the node administration help at <a href="%admin-help-node">administer &gt;&gt; help &gt;&gt; node</a>.</li>
<li>read the page administration help at <a href="%admin-help-page">administer &gt;&gt; help &gt;&gt; page</a>.</li>
<li>read the story administration help at <a href="%admin-help-story">administer &gt;&gt; help &gt;&gt; story</a>.</li>
<li>create a page at <a href="%node-add-page">create content &gt;&gt; page</a>.</li>
<li>administer page content type at <a href="%admin-settings-content-types-page">administer &gt;&gt; settings &gt;&gt; content types &gt;&gt; configure page</a>.</li>
</ul>
', array('%admin-help-node' => url('admin/help/node'), '%admin-help-page' => url('admin/help/page'), '%admin-help-story' => url('admin/help/story'), '%node-add-page' => url('node/add/page'), '%admin-settings-content-types-page' => url('admin/content/types/page')));
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%page">Page page</a>.', array('%page' => 'http://drupal.org/handbook/modules/page/')) .'</p>';
return $output;
case 'admin/settings/modules#description':
return t('Enables the creation of pages that can be added to the navigation system.');
case 'node/add#page':
return t('If you want to add a static page, like a contact page or an about page, use a page.');
}
}
/**
* Implementation of hook_perm().
*/
function page_perm() {
return array('create pages', 'edit own pages');
}
/**
* Implementation of hook_node_info().
*/
function page_node_info() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
/**
* Implementation of hook_access().
*/
function page_access($op, $node) {
global $user;
if ($op == 'create') {
return user_access('create pages');
}
if ($op == 'update' || $op == 'delete') {
if (user_access('edit own pages') && ($user->uid == $node->uid)) {
return TRUE;
}
}
}
/**
* Implementation of hook_menu().
*/
function page_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array('path' => 'node/add/page', 'title' => t('page'),
'access' => user_access('create pages'));
}
return $items;
}
/**
* Implementation of hook_form().
*/
function page_form(&$node) {
$form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5);
$form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE);
$form['body_filter']['format'] = filter_form($node->format);
$form['log'] = array(
'#type' => 'textarea', '#title' => t('Log message'), '#default_value' => $node->log, '#weight' => 5,
'#description' => t('An explanation of the additions or updates being made to help other authors understand your motivations.')
);
return $form;
}