Commit 129c8eb1 authored by drumm's avatar drumm

#62340 by chx, webchick, Jaza, Eaton, mathieu, and myself. Configurable node types.

parent 0299beb0
......@@ -10,7 +10,13 @@
* Implementation of hook_node_info().
*/
function blog_node_info() {
return array('blog' => array('name' => t('blog entry'), 'base' => 'blog'));
return array(
'blog' => array(
'name' => t('blog entry'),
'module' => 'blog',
'description' => t('A blog is a regularly updated journal or diary made up of individual posts shown in reversed chronological order. Each member of the site may create and maintain a blog.'),
)
);
}
/**
......@@ -72,8 +78,6 @@ function blog_help($section) {
return $output;
case 'admin/settings/modules#description':
return t('Enables keeping an easily and regularly updated web page or a blog.');
case 'node/add#blog':
return t("A blog is a regularly updated journal or diary made up of individual posts shown in reversed chronological order. Each member of the site may create and maintain a blog.");
}
}
......@@ -201,6 +205,7 @@ function blog_page_last() {
function blog_form(&$node) {
global $nid;
$iid = $_GET['iid'];
$type = node_get_types('type', $node);
if (empty($node->body)) {
......@@ -221,8 +226,8 @@ function blog_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['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5);
$form['body_filter']['body'] = array('#type' => 'textarea', '#title' => check_plain($type->body_label), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE);
$form['body_filter']['filter'] = filter_form($node->format);
return $form;
}
......
......@@ -10,7 +10,13 @@
* Implementation of hook_node_info().
*/
function book_node_info() {
return array('book' => array('name' => t('book page'), 'base' => 'book'));
return array(
'book' => array(
'name' => t('book page'),
'module' => 'book',
'description' => t("A book is a collaborative writing effort: users can collaborate writing the pages of the book, positioning the pages in the right order, and reviewing or modifying pages previously written. So when you have some information to share or when you read a page of the book and you didn't like it, or if you think a certain page could have been written better, you can do something about it."),
)
);
}
/**
......@@ -83,10 +89,6 @@ function book_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'node/add/book',
'title' => t('book page'),
'access' => user_access('create book pages'));
$items[] = array(
'path' => 'admin/content/book',
'title' => t('books'),
......@@ -224,6 +226,7 @@ function book_submit(&$node) {
* Implementation of hook_form().
*/
function book_form(&$node) {
$type = node_get_types('type', $node);
if ($node->nid && !$node->parent && !user_access('create new books')) {
$form['parent'] = array('#type' => 'value', '#value' => $node->parent);
}
......@@ -238,13 +241,13 @@ function book_form(&$node) {
}
$form['title'] = array('#type' => 'textfield',
'#title' => t('Title'),
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -5,
);
$form['body_filter']['body'] = array('#type' => 'textarea',
'#title' => t('Body'),
'#title' => check_plain($type->body_label),
'#default_value' => $node->body,
'#rows' => 20,
'#required' => TRUE,
......@@ -1014,8 +1017,6 @@ function book_help($section) {
return t('<p>The book module offers a means to organize content, authored by many users, in an online manual, outline or FAQ.</p>');
case 'admin/content/book/orphan':
return t('<p>Pages in a book are like a tree. As pages are edited, reorganized and removed, child pages might be left with no link to the rest of the book. Such pages are referred to as "orphan pages". On this page, administrators can review their books for orphans and reattach those pages as desired.</p>');
case 'node/add#book':
return t("A book is a collaborative writing effort: users can collaborate writing the pages of the book, positioning the pages in the right order, and reviewing or modifying pages previously written. So when you have some information to share or when you read a page of the book and you didn't like it, or if you think a certain page could have been written better, you can do something about it.");
}
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'outline') {
......
......@@ -265,10 +265,16 @@ function comment_link($type, $node = NULL, $teaser = FALSE) {
}
function comment_form_alter($form_id, &$form) {
if (isset($form['type'])) {
if ($form['type']['#value'] .'_node_settings' == $form_id) {
$form['workflow']['comment_'. $form['type']['#value']] = array('#type' => 'radios', '#title' => t('Default comment setting'), '#default_value' => variable_get('comment_'. $form['type']['#value'], COMMENT_NODE_READ_WRITE), '#options' => array(t('Disabled'), t('Read only'), t('Read/Write')), '#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'));
}
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
$form['workflow']['comment'] = array(
'#type' => 'radios',
'#title' => t('Default comment setting'),
'#default_value' => variable_get('comment_'. $form['identity']['type']['#default_value'], COMMENT_NODE_READ_WRITE),
'#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
'#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'),
);
}
elseif (isset($form['type'])) {
if ($form['type']['#value'] .'_node_form' == $form_id) {
$node = $form['#node'];
if (user_access('administer comments')) {
......
......@@ -33,8 +33,6 @@ function forum_help($section) {
return t('<p>Containers help you organize your forums. The job of a container is to hold, or contain, other forums that are related. For example, a container named "Food" might hold two forums named "Fruit" and "Vegetables".</p>');
case 'admin/content/forum/add/forum':
return t('<p>A forum holds discussion topics that are related. For example, a forum named "Fruit" might contain topics titled "Apples" and "Bananas".</p>');
case 'node/add#forum':
return t('Create a new topic for discussion in the forums.');
}
}
......@@ -107,7 +105,14 @@ function forum_menu($may_cache) {
* Implementation of hook_node_info().
*/
function forum_node_info() {
return array('forum' => array('name' => t('forum topic'), 'base' => 'forum'));
return array(
'forum' => array(
'name' => t('forum topic'),
'module' => 'forum',
'description' => t('Create a new topic for discussion in the forums.'),
'title_label' => t('Subject'),
)
);
}
/**
......@@ -383,7 +388,8 @@ function forum_update($node) {
* Implementation of hook_form().
*/
function forum_form(&$node) {
$form['title'] = array('#type' => 'textfield', '#title' => t('Subject'), '#default_value' => $node->title, '#required' => TRUE, '#weight' => -5);
$type = node_get_types('type', $node);
$form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#default_value' => $node->title, '#required' => TRUE, '#weight' => -5);
if ($node->nid) {
$forum_terms = taxonomy_node_get_terms_by_vocabulary(_forum_get_vid(), $node->nid);
......@@ -392,7 +398,7 @@ function forum_form(&$node) {
$form['shadow'] = array('#type' => 'checkbox', '#title' => t('Leave shadow copy'), '#default_value' => $shadow, '#description' => t('If you move this topic, you can leave a link in the old forum to the new forum.'));
}
$form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE);
$form['body_filter']['body'] = array('#type' => 'textarea', '#title' => check_plain($type->body_label), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE);
$form['body_filter']['format'] = filter_form($node->format);
return $form;
......
This diff is collapsed.
......@@ -25,8 +25,6 @@ function poll_help($section) {
return $output;
case 'admin/settings/modules#description':
return t("Allows your site to capture votes on different topics in the form of multiple choice questions.");
case 'node/add#poll':
return t("A poll is a multiple-choice question which visitors can vote on.");
}
}
......@@ -128,8 +126,9 @@ function poll_validate($node) {
*/
function poll_form(&$node) {
$admin = user_access('administer nodes');
$type = node_get_types('type', $node);
$form['title'] = array('#type' => 'textfield', '#title' => t('Question'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -1);
$form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -1);
$form['choice']['choices'] = array('#type' => 'hidden', '#default_value' => max(2, count($node->choice) ? count($node->choice) : 5));
$form['choice']['morechoices'] = array('#type' => 'checkbox', '#title' => t('Need more choices'), '#default_value' => 0, '#description' => t("If the amount of boxes above isn't enough, check this box and click the Preview button below to add some more."), '#weight' => 1);
......@@ -271,7 +270,15 @@ function poll_load($node) {
* Implementation of hook_node_info().
*/
function poll_node_info() {
return array('poll' => array('name' => t("poll"), 'base' => 'poll'));
return array(
'poll' => array(
'name' => t("poll"),
'module' => 'poll',
'description' => t("A poll is a multiple-choice question which visitors can vote on."),
'title_label' => t('Question'),
'has_body' => FALSE,
)
);
}
function poll_page() {
......
......@@ -198,6 +198,24 @@ function system_install() {
KEY uid (uid)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE TABLE {node_type} (
type varchar(32) NOT NULL,
name varchar(255) NOT NULL default '',
module varchar(255) NOT NULL,
description mediumtext NOT NULL,
help mediumtext NOT NULL,
has_title tinyint(3) unsigned NOT NULL,
title_label varchar(255) NOT NULL default '',
has_body tinyint(3) unsigned NOT NULL,
body_label varchar(255) NOT NULL default '',
min_word_count smallint(4) unsigned NOT NULL,
custom tinyint(1) NOT NULL DEFAULT '0',
modified tinyint(1) NOT NULL DEFAULT '0',
locked tinyint(1) NOT NULL DEFAULT '0',
orig_type varchar(255) NOT NULL default '',
PRIMARY KEY (type)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE TABLE {url_alias} (
pid int(10) unsigned NOT NULL auto_increment,
src varchar(128) NOT NULL default '',
......@@ -789,6 +807,9 @@ function system_install() {
db_query("INSERT INTO {node_access} VALUES (0, 0, 'all', 1, 0, 0)");
db_query("INSERT INTO {node_type} (type, name, module, description, help, has_title, title_label, has_body, body_label, min_word_count, custom, modified, locked, orig_type) VALUES ('page', 'page', 'node', 'If you want to add a static page, like a contact page or an about page, use a page.', '', 1, 'Title', 1, 'Body', 0, 1, 1, 0, 'page')");
db_query("INSERT INTO {node_type} (type, name, module, description, help, has_title, title_label, has_body, body_label, min_word_count, custom, modified, locked, orig_type) VALUES ('story', 'story', 'node', 'Stories are articles in their simplest form: they have a title, a teaser and a body, but can be extended by other modules. The teaser is part of the body too. Stories may be used as a personal blog or for news articles.', '', 1, 'Title', 1, 'Body', 0, 1, 1, 0, 'story')");
db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('Filtered HTML',',1,2,',1)");
db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('PHP code','',0)");
db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('Full HTML','',1)");
......@@ -2908,3 +2929,99 @@ function system_update_187() {
}
return $ret;
}
function system_update_188() {
// Add ability to create dynamic node types like the CCK module
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
// Create node_type table
$ret[] = update_sql("CREATE TABLE {node_type} (
type varchar(32) NOT NULL,
name varchar(255) NOT NULL,
module varchar(255) NOT NULL,
description mediumtext NOT NULL,
help mediumtext NOT NULL,
has_title tinyint(3) unsigned NOT NULL,
title_label varchar(255) NOT NULL default '',
has_body tinyint(3) unsigned NOT NULL,
body_label varchar(255) NOT NULL default '',
min_word_count smallint(4) unsigned NOT NULL,
custom tinyint(1) NOT NULL DEFAULT '0',
modified tinyint(1) NOT NULL DEFAULT '0',
locked tinyint(1) NOT NULL DEFAULT '0',
orig_type varchar(255) NOT NULL default '',
PRIMARY KEY (type)
) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
$ret[] = update_sql("CREATE TABLE {node_type} (
type varchar(32) NOT NULL,
name varchar(255) NOT NULL,
module varchar(255) NOT NULL,
description text NOT NULL,
help text NOT NULL,
has_title integer unsigned NOT NULL,
title_label varchar(255) NOT NULL default '',
has_body integer unsigned NOT NULL,
body_label varchar(255) NOT NULL default '',
min_word_count integer unsigned NOT NULL,
custom smallint NOT NULL DEFAULT '0',
modified smallint NOT NULL DEFAULT '0',
locked smallint NOT NULL DEFAULT '0',
orig_type varchar(255) NOT NULL default '',
PRIMARY KEY (type)
);");
break;
}
// Insert default user-defined node types into the database.
$types = array(
array(
'type' => 'page',
'name' => t('page'),
'module' => 'node',
'description' => t('If you want to add a static page, like a contact page or an about page, use a page.'),
'custom' => TRUE,
'modified' => TRUE,
'locked' => FALSE,
),
array(
'type' => 'story',
'name' => t('story'),
'module' => 'node',
'description' => t('Stories are articles in their simplest form: they have a title, a teaser and a body, but can be extendd by other modules. The teaser is part of the body too. Stories may be used as a personal blog or for news articles.'),
'custom' => TRUE,
'modified' => TRUE,
'locked' => FALSE,
)
);
foreach ($types as $type) {
$type = (object) _node_type_set_defaults($type);
node_type_save($type);
}
cache_clear_all();
system_modules();
menu_rebuild();
node_types_rebuild();
// Migrate old values for 'minimum_x_size' variables to the node_type table.
$query = db_query('SELECT type FROM {node_type}');
while ($result = db_fetch_object($query)) {
$variable_name = 'minimum_'. $result->type .'_size';
if ($value = db_fetch_object(db_query("SELECT value FROM {variable} WHERE name = '%s'", $variable_name))) {
$value = (int) unserialize($value->value);
db_query("UPDATE {node_type} SET min_word_count = %d, modified = %d WHERE type = '%s'", $value, 1, $result->type);
variable_del($variable_name);
}
}
node_types_rebuild();
return $ret;
}
......@@ -1253,6 +1253,7 @@ function system_modules_submit($form_id, $edit) {
}
menu_rebuild();
node_types_rebuild();
drupal_set_message(t('The configuration options have been saved.'));
return 'admin/settings/modules';
......@@ -1377,7 +1378,7 @@ function system_theme_settings($key = '') {
);
// Toggle node display.
$node_types = module_invoke('node', 'get_types');
$node_types = node_get_types('names');
if ($node_types) {
$form['node_info'] = array(
'#type' => 'fieldset',
......
......@@ -138,7 +138,7 @@ function taxonomy_overview_vocabularies() {
foreach ($vocabularies as $vocabulary) {
$types = array();
foreach ($vocabulary->nodes as $type) {
$node_type = node_get_name($type);
$node_type = node_get_types('name', $type);
$types[] = $node_type ? $node_type : $type;
}
$rows[] = array('name' => check_plain($vocabulary->name),
......
......@@ -110,7 +110,7 @@ function tracker_page($uid = 0) {
}
$rows[] = array(
node_get_name($node->type),
node_get_types('name', $node->type),
l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)),
theme('username', $node),
array('class' => 'replies', 'data' => $comments),
......
......@@ -348,14 +348,16 @@ function _upload_prepare(&$node) {
}
function upload_form_alter($form_id, &$form) {
if (isset($form['type'])) {
if ($form['type']['#value'] .'_node_settings' == $form_id) {
$form['workflow']['upload_'. $form['type']['#value']] = array(
'#type' => 'radios', '#title' => t('Attachments'), '#default_value' => variable_get('upload_'. $form['type']['#value'], 1),
'#options' => array(t('Disabled'), t('Enabled')),
);
}
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
$form['workflow']['upload'] = array(
'#type' => 'radios',
'#title' => t('Attachments'),
'#default_value' => variable_get('upload_'. $form['identity']['type']['#default_value'], 1),
'#options' => array(t('Disabled'), t('Enabled')),
);
}
if (isset($form['type'])) {
$node = $form['#node'];
if ($form['type']['#value'] .'_node_form' == $form_id && variable_get("upload_$node->type", TRUE) && user_access('upload files')) {
drupal_add_js('misc/progress.js');
......
......@@ -8,7 +8,7 @@
* An array of modules to be enabled.
*/
function default_profile_modules() {
return array('block', 'comment', 'filter', 'help', 'menu', 'node', 'page', 'story', 'system', 'taxonomy', 'user', 'watchdog');
return array('block', 'comment', 'filter', 'help', 'menu', 'node', 'system', 'taxonomy', 'user', 'watchdog');
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment