Commit 61740bd8 authored by Dries's avatar Dries

- Patch #10056: allow the node title forms to be customized.

parent e3a4085a
......@@ -182,6 +182,13 @@ function blog_page_last() {
return $output;
}
/**
* Implementation of hook_validate().
*/
function blog_validate(&$node) {
node_validate_title($node);
}
/**
* Implementation of hook_form().
*/
......@@ -189,6 +196,8 @@ function blog_form(&$node) {
global $nid;
$iid = $_GET['iid'];
$output = form_textfield(t('Title'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
if (empty($node->body)) {
/*
** If the user clicked a "blog it" link, we load the data from the
......
......@@ -182,6 +182,13 @@ function blog_page_last() {
return $output;
}
/**
* Implementation of hook_validate().
*/
function blog_validate(&$node) {
node_validate_title($node);
}
/**
* Implementation of hook_form().
*/
......@@ -189,6 +196,8 @@ function blog_form(&$node) {
global $nid;
$iid = $_GET['iid'];
$output = form_textfield(t('Title'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
if (empty($node->body)) {
/*
** If the user clicked a "blog it" link, we load the data from the
......
......@@ -225,13 +225,16 @@ function book_validate(&$node) {
$node->weight = 0;
$node->revision = 1;
}
node_validate_title($node);
}
/**
* Implementation of hook_form().
*/
function book_form(&$node) {
$output = form_select(t('Parent'), 'parent', ($node->parent ? $node->parent : arg(4)), book_toc($node->nid), t('The parent that this page belongs in. Note that pages whose parent is <top-level> are regarded as independent, top-level books.'));
$output = form_textfield(t('Title'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
$output .= form_select(t('Parent'), 'parent', ($node->parent ? $node->parent : arg(4)), book_toc($node->nid), t('The parent that this page belongs in. Note that pages whose parent is <top-level> are regarded as independent, top-level books.'));
if (function_exists('taxonomy_node_form')) {
$output .= implode('', taxonomy_node_form('book', $node));
......
......@@ -225,13 +225,16 @@ function book_validate(&$node) {
$node->weight = 0;
$node->revision = 1;
}
node_validate_title($node);
}
/**
* Implementation of hook_form().
*/
function book_form(&$node) {
$output = form_select(t('Parent'), 'parent', ($node->parent ? $node->parent : arg(4)), book_toc($node->nid), t('The parent that this page belongs in. Note that pages whose parent is <top-level> are regarded as independent, top-level books.'));
$output = form_textfield(t('Title'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
$output .= form_select(t('Parent'), 'parent', ($node->parent ? $node->parent : arg(4)), book_toc($node->nid), t('The parent that this page belongs in. Note that pages whose parent is <top-level> are regarded as independent, top-level books.'));
if (function_exists('taxonomy_node_form')) {
$output .= implode('', taxonomy_node_form('book', $node));
......
......@@ -517,6 +517,8 @@ function forum_validate(&$node) {
// Make sure all fields are set properly:
$node->icon = $node->icon ? $node->icon : '';
node_validate_title($node,t('You have to specify a subject.'));
if ($node->taxonomy) {
// Extract the node's proper topic ID.
$vocabulary = variable_get('forum_nav_vocabulary', '');
......@@ -558,6 +560,8 @@ function forum_update($node) {
* Implementation of hook_form().
*/
function forum_form(&$node) {
$output = form_textfield(t('Subject'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
if (!$node->nid) {
// new topic
$node->taxonomy[] = arg(3);
......@@ -566,7 +570,7 @@ function forum_form(&$node) {
$node->taxonomy = array($node->tid);
}
$output = implode('', taxonomy_node_form('forum', $node));
$output .= implode('', taxonomy_node_form('forum', $node));
if ($node->nid) {
// if editing, give option to leave shadows
......
......@@ -517,6 +517,8 @@ function forum_validate(&$node) {
// Make sure all fields are set properly:
$node->icon = $node->icon ? $node->icon : '';
node_validate_title($node,t('You have to specify a subject.'));
if ($node->taxonomy) {
// Extract the node's proper topic ID.
$vocabulary = variable_get('forum_nav_vocabulary', '');
......@@ -558,6 +560,8 @@ function forum_update($node) {
* Implementation of hook_form().
*/
function forum_form(&$node) {
$output = form_textfield(t('Subject'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
if (!$node->nid) {
// new topic
$node->taxonomy[] = arg(3);
......@@ -566,7 +570,7 @@ function forum_form(&$node) {
$node->taxonomy = array($node->tid);
}
$output = implode('', taxonomy_node_form('forum', $node));
$output .= implode('', taxonomy_node_form('forum', $node));
if ($node->nid) {
// if editing, give option to leave shadows
......
......@@ -1242,13 +1242,6 @@ function node_validate($node) {
// Convert the node to an object, if necessary.
$node = array2object($node);
// Validate the title field.
if (isset($node->title)) {
if (trim($node->title) == '') {
form_set_error('title', t('You have to specify a title.'));
}
}
// Make sure the body has the minimum number of words.
// todo use a better word counting algorithm that will work in other languages
if (isset($node->body) && count(explode(' ', $node->body)) < variable_get('minimum_'. $node->type .'_size', 0)) {
......@@ -1324,6 +1317,16 @@ function node_validate($node) {
return $node;
}
/**
* Validate the title of a node
*/
function node_validate_title($node, $message = NULL) {
// Validate the title field.
if (trim($node->title) == '') {
form_set_error('title', isset($message) ? $message : t('You have to specify a title.'));
}
}
/**
* Generate the node editing form.
*/
......@@ -1378,9 +1381,8 @@ function node_form($edit) {
$output .= $extras ? '<div class="extra">'. $extras .'</div></div>' : '</div>';
}
// Add the default fields.
// Open the enclosing div.
$output .= '<div class="standard">';
$output .= form_textfield(t('Title'), 'title', $edit->title, 60, 128, NULL, NULL, TRUE);
// Add the node-type-specific fields.
$output .= $form;
......
......@@ -1242,13 +1242,6 @@ function node_validate($node) {
// Convert the node to an object, if necessary.
$node = array2object($node);
// Validate the title field.
if (isset($node->title)) {
if (trim($node->title) == '') {
form_set_error('title', t('You have to specify a title.'));
}
}
// Make sure the body has the minimum number of words.
// todo use a better word counting algorithm that will work in other languages
if (isset($node->body) && count(explode(' ', $node->body)) < variable_get('minimum_'. $node->type .'_size', 0)) {
......@@ -1324,6 +1317,16 @@ function node_validate($node) {
return $node;
}
/**
* Validate the title of a node
*/
function node_validate_title($node, $message = NULL) {
// Validate the title field.
if (trim($node->title) == '') {
form_set_error('title', isset($message) ? $message : t('You have to specify a title.'));
}
}
/**
* Generate the node editing form.
*/
......@@ -1378,9 +1381,8 @@ function node_form($edit) {
$output .= $extras ? '<div class="extra">'. $extras .'</div></div>' : '</div>';
}
// Add the default fields.
// Open the enclosing div.
$output .= '<div class="standard">';
$output .= form_textfield(t('Title'), 'title', $edit->title, 60, 128, NULL, NULL, TRUE);
// Add the node-type-specific fields.
$output .= $form;
......
......@@ -63,10 +63,19 @@ function page_menu($may_cache) {
return $items;
}
/**
* Implementation of hook_validate().
*/
function page_validate(&$node) {
node_validate_title($node);
}
/**
* Implementation of hook_form().
*/
function page_form(&$node) {
$output = form_textfield(t('Title'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
if (function_exists('taxonomy_node_form')) {
$output .= implode('', taxonomy_node_form('page', $node));
}
......
......@@ -63,10 +63,19 @@ function page_menu($may_cache) {
return $items;
}
/**
* Implementation of hook_validate().
*/
function page_validate(&$node) {
node_validate_title($node);
}
/**
* Implementation of hook_form().
*/
function page_form(&$node) {
$output = form_textfield(t('Title'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
if (function_exists('taxonomy_node_form')) {
$output .= implode('', taxonomy_node_form('page', $node));
}
......
......@@ -92,6 +92,9 @@ function poll_delete($node) {
* Implementation of hook_validate().
*/
function poll_validate(&$node) {
node_validate_title($node,t('You have to specify a question.'));
if (isset($node->title)) {
// Check for at least two options and validate amount of votes:
$realchoices = 0;
......@@ -120,8 +123,10 @@ function poll_validate(&$node) {
function poll_form(&$node) {
$admin = user_access('administer nodes');
$output = form_textfield(t('Question'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
if (function_exists('taxonomy_node_form')) {
$output = implode('', taxonomy_node_form('poll', $node));
$output .= implode('', taxonomy_node_form('poll', $node));
}
if (!isset($node->choices)) {
......
......@@ -92,6 +92,9 @@ function poll_delete($node) {
* Implementation of hook_validate().
*/
function poll_validate(&$node) {
node_validate_title($node,t('You have to specify a question.'));
if (isset($node->title)) {
// Check for at least two options and validate amount of votes:
$realchoices = 0;
......@@ -120,8 +123,10 @@ function poll_validate(&$node) {
function poll_form(&$node) {
$admin = user_access('administer nodes');
$output = form_textfield(t('Question'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
if (function_exists('taxonomy_node_form')) {
$output = implode('', taxonomy_node_form('poll', $node));
$output .= implode('', taxonomy_node_form('poll', $node));
}
if (!isset($node->choices)) {
......
......@@ -63,11 +63,18 @@ function story_menu($may_cache) {
return $items;
}
/**
* Implementation of hook_validate().
*/
function story_validate(&$node) {
node_validate_title($node);
}
/**
* Implementation of hook_form().
*/
function story_form(&$node) {
$output = '';
$output = form_textfield(t('Title'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
if (function_exists('taxonomy_node_form')) {
$output .= implode('', taxonomy_node_form('story', $node));
......
......@@ -63,11 +63,18 @@ function story_menu($may_cache) {
return $items;
}
/**
* Implementation of hook_validate().
*/
function story_validate(&$node) {
node_validate_title($node);
}
/**
* Implementation of hook_form().
*/
function story_form(&$node) {
$output = '';
$output = form_textfield(t('Title'), 'title', $node->title, 60, 128, NULL, NULL, TRUE);
if (function_exists('taxonomy_node_form')) {
$output .= implode('', taxonomy_node_form('story', $node));
......
......@@ -30,6 +30,10 @@
* 9. sites/org
*
* 10. sites/default
*
* If you are installing on a non-standard port number, the ':' is
* replaced by a '.'. For example, http://www.drupal.org:8080/mysite/test/
* could be loaded from sites/www.drupal.org.8080.mysite.test/.
*/
/**
......
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