summaryrefslogtreecommitdiff
path: root/modules/node
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-10-11 03:07:21 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-10-11 03:07:21 +0000
commitb3265dbe174ce0efefa181b8af6c1eaea3ff22c2 (patch)
treeaa7e8b709c162fd781748d8bebaa12c75727e01e /modules/node
parent64a1a0d67eb5aecc8e6d78469b19f58e8443c717 (diff)
downloadbrdo-b3265dbe174ce0efefa181b8af6c1eaea3ff22c2.tar.gz
brdo-b3265dbe174ce0efefa181b8af6c1eaea3ff22c2.tar.bz2
#557292 by peximo, plach, catch, and yched: Convert node title to Field API.
Diffstat (limited to 'modules/node')
-rw-r--r--modules/node/node.admin.inc2
-rw-r--r--modules/node/node.install5
-rw-r--r--modules/node/node.module138
-rw-r--r--modules/node/node.pages.inc25
-rw-r--r--modules/node/node.test142
-rw-r--r--modules/node/node.tokens.inc2
-rw-r--r--modules/node/node.tpl.php2
7 files changed, 200 insertions, 116 deletions
diff --git a/modules/node/node.admin.inc b/modules/node/node.admin.inc
index 6563f1b4a..d9d3bec6e 100644
--- a/modules/node/node.admin.inc
+++ b/modules/node/node.admin.inc
@@ -339,7 +339,7 @@ function _node_mass_update_batch_process($nodes, $updates, &$context) {
$node = _node_mass_update_helper($nid, $updates);
// Store result for post-processing in the finished callback.
- $context['results'][] = l($node->title, 'node/' . $node->nid);
+ $context['results'][] = l($node->title[FIELD_LANGUAGE_NONE][0]['value'], 'node/' . $node->nid);
// Update our progress information.
$context['sandbox']['progress']++;
diff --git a/modules/node/node.install b/modules/node/node.install
index 947757605..7a4e156eb 100644
--- a/modules/node/node.install
+++ b/modules/node/node.install
@@ -438,9 +438,9 @@ function node_update_7006(&$context) {
if (!isset($context['total'])) {
// Initial invocation.
- // Re-save node types to create body field instances.
+ // Re-save node types to create title and body field instances.
foreach ($node_types as $type => $info) {
- if ($info->has_body) {
+ if ($info->has_title || $info->has_body) {
node_type_save($info);
}
}
@@ -485,6 +485,7 @@ function node_update_7006(&$context) {
'vid' => $revision->vid,
'type' => $revision->type,
);
+ $node->title[FIELD_LANGUAGE_NONE][0]['value'] = $revision->title;
if (!empty($revision->teaser) && $revision->teaser != text_summary($revision->body)) {
$node->body[FIELD_LANGUAGE_NONE][0]['summary'] = $revision->teaser;
}
diff --git a/modules/node/node.module b/modules/node/node.module
index 2e6a3800c..b4869de54 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -234,25 +234,6 @@ function node_field_build_modes($obj_type) {
}
/**
- * Implement hook_field_extra_fields().
- */
-function node_field_extra_fields($bundle) {
- $extra = array();
-
- if ($type = node_type_get_type($bundle)) {
- if ($type->has_title) {
- $extra['title'] = array(
- 'label' => $type->title_label,
- 'description' => t('Node module element.'),
- 'weight' => -5,
- );
- }
- }
-
- return $extra;
-}
-
-/**
* Gather a listing of links to nodes.
*
* @param $result
@@ -588,6 +569,50 @@ function node_configure_fields($type) {
field_delete_instance($instance);
}
+ if ($type->has_title) {
+ // Add the title field if not present.
+ $field = field_info_field('title');
+ $instance = field_info_instance('title', $type->type);
+
+ if (empty($field)) {
+ $field = array(
+ 'field_name' => 'title',
+ 'type' => 'text',
+ );
+ $field = field_create_field($field);
+ }
+ if (empty($instance)) {
+ $weight = -5;
+ $instance = array(
+ 'field_name' => 'title',
+ 'bundle' => $type->type,
+ 'label' => $type->title_label,
+ 'widget_type' => 'text',
+ 'widget' => array(
+ 'weight' => $weight,
+ ),
+ 'required' => TRUE,
+ 'locked' => TRUE,
+ 'display' => array(
+ 'full' => array(
+ 'label' => 'hidden',
+ 'type' => 'text_default',
+ 'weight' => $weight,
+ ),
+ 'teaser' => array(
+ 'label' => 'hidden',
+ 'type' => 'text_default',
+ 'weight' => $weight,
+ ),
+ ),
+ );
+ field_create_instance($instance);
+ }
+ else {
+ $instance['label'] = $type->title_label;
+ field_update_instance($instance);
+ }
+ }
}
/**
@@ -905,6 +930,14 @@ function node_save($node) {
$node->timestamp = REQUEST_TIME;
$update_node = TRUE;
+ // When converting the title property to fields we preserved the {node}.title
+ // db column for performance, setting the default language value into this
+ // column. After this we restore the field data structure to the previous node
+ // title field.
+ $title_field = $node->title;
+ $langcode = FIELD_LANGUAGE_NONE;
+ $node->title = $title_field[$langcode][0]['value'];
+
// Generate the node table query and the node_revisions table query.
if ($node->is_new) {
drupal_write_record('node', $node);
@@ -929,6 +962,9 @@ function node_save($node) {
->execute();
}
+ // Restore the title field data structure after db storage.
+ $node->title = $title_field;
+
// Call the node specific callback (if any). This can be
// node_invoke($node, 'insert') or
// node_invoke($node, 'update').
@@ -1121,7 +1157,7 @@ function node_build_content($node, $build_mode = 'full') {
$links['node_readmore'] = array(
'title' => t('Read more'),
'href' => 'node/' . $node->nid,
- 'attributes' => array('rel' => 'tag', 'title' => strip_tags($node->title))
+ 'attributes' => array('rel' => 'tag', 'title' => strip_tags($node->title[FIELD_LANGUAGE_NONE][0]['value']))
);
}
$node->content['links']['node'] = array(
@@ -1195,7 +1231,7 @@ function node_language_provider($languages) {
*/
function node_show($node, $message = FALSE) {
if ($message) {
- drupal_set_title(t('Revision of %title from %date', array('%title' => $node->title, '%date' => format_date($node->revision_timestamp))), PASS_THROUGH);
+ drupal_set_title(t('Revision of %title from %date', array('%title' => $node->title[FIELD_LANGUAGE_NONE][0]['value'], '%date' => format_date($node->revision_timestamp))), PASS_THROUGH);
}
// Update the history table, stating that this user viewed this node.
@@ -1229,7 +1265,7 @@ function template_preprocess_node(&$variables) {
$variables['date'] = format_date($node->created);
$variables['name'] = theme('username', array('account' => $node));
$variables['node_url'] = url('node/' . $node->nid);
- $variables['title'] = check_plain($node->title);
+ $variables['node_title'] = check_plain($node->title[FIELD_LANGUAGE_NONE][0]['value']);
$variables['page'] = (bool)menu_get_object();
if (!empty($node->in_preview)) {
@@ -1247,6 +1283,10 @@ function template_preprocess_node(&$variables) {
// Make the field variables available with the appropriate language.
field_attach_preprocess('node', $node, $variables['content'], $variables);
+ if (isset($variables['content']['title'])) {
+ unset($variables['content']['title']);
+ }
+
// Display post information only on certain node types.
if (variable_get('node_submitted_' . $node->type, TRUE)) {
$variables['display_submitted'] = TRUE;
@@ -1475,7 +1515,7 @@ function node_search_execute($keys = NULL) {
$results[] = array(
'link' => url('node/' . $item->sid, array('absolute' => TRUE)),
'type' => check_plain(node_type_get_name($node)),
- 'title' => $node->title,
+ 'title' => $node->title[FIELD_LANGUAGE_NONE][0]['value'],
'user' => theme('username', array('account' => $node)),
'date' => $node->changed,
'node' => $node,
@@ -1758,8 +1798,6 @@ function node_menu() {
);
}
$items['node/%node'] = array(
- 'title callback' => 'node_page_title',
- 'title arguments' => array(1),
'page callback' => 'node_page_view',
'page arguments' => array(1),
'access callback' => 'node_access',
@@ -1959,7 +1997,7 @@ function node_feed($nids = FALSE, $channel = array()) {
$item_text .= drupal_render($node->content) . $links;
}
- $items .= format_rss_item($node->title, $node->link, $item_text, $node->rss_elements);
+ $items .= format_rss_item($node->title[FIELD_LANGUAGE_NONE][0]['value'], $node->link, $item_text, $node->rss_elements);
}
$channel_defaults = array(
@@ -2060,8 +2098,11 @@ function node_page_default() {
* Menu callback; view a single node.
*/
function node_page_view($node) {
- drupal_set_title($node->title);
- return node_show($node);
+ $return = node_show($node);
+ if (isset($return['nodes'][$node->nid]['title'])) {
+ drupal_set_title($return['nodes'][$node->nid]['title']['items'][0]['#item']['value']);
+ }
+ return $return;
}
/**
@@ -2094,7 +2135,7 @@ function _node_index_node($node) {
node_build_content($node, 'search_index');
$node->rendered = drupal_render($node->content);
- $text = '<h1>' . check_plain($node->title) . '</h1>' . $node->rendered;
+ $text = '<h1>' . check_plain($node->title[FIELD_LANGUAGE_NONE][0]['value']) . '</h1>' . $node->rendered;
// Fetch extra data normally not visible
$extra = module_invoke_all('node_update_index', $node);
@@ -2819,20 +2860,10 @@ function _node_access_rebuild_batch_finished($success, $results, $operations) {
* Implement hook_form().
*/
function node_content_form($node, $form_state) {
- $type = node_type_get_type($node);
-
- if ($type->has_title) {
- $form['title'] = array(
- '#type' => 'textfield',
- '#title' => check_plain($type->title_label),
- '#required' => TRUE,
- '#default_value' => $node->title,
- '#maxlength' => 255,
- '#weight' => -5,
- );
- }
-
- return $form;
+ // It is impossible to define a content type without implementing hook_form()
+ // so simply return an empty array().
+ // @todo: remove this requirement.
+ return array();
}
/**
@@ -2948,7 +2979,7 @@ function node_action_info() {
*/
function node_publish_action($node, $context = array()) {
$node->status = NODE_PUBLISHED;
- watchdog('action', 'Set @type %title to published.', array('@type' => node_type_get_name($node), '%title' => $node->title));
+ watchdog('action', 'Set @type %title to published.', array('@type' => node_type_get_name($node), '%title' => $node->title[FIELD_LANGUAGE_NONE][0]['value']));
}
/**
@@ -2957,7 +2988,7 @@ function node_publish_action($node, $context = array()) {
*/
function node_unpublish_action($node, $context = array()) {
$node->status = NODE_NOT_PUBLISHED;
- watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_type_get_name($node), '%title' => $node->title));
+ watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_type_get_name($node), '%title' => $node->title[FIELD_LANGUAGE_NONE][0]['value']));
}
/**
@@ -2966,7 +2997,7 @@ function node_unpublish_action($node, $context = array()) {
*/
function node_make_sticky_action($node, $context = array()) {
$node->sticky = NODE_STICKY;
- watchdog('action', 'Set @type %title to sticky.', array('@type' => node_type_get_name($node), '%title' => $node->title));
+ watchdog('action', 'Set @type %title to sticky.', array('@type' => node_type_get_name($node), '%title' => $node->title[FIELD_LANGUAGE_NONE][0]['value']));
}
/**
@@ -2975,7 +3006,7 @@ function node_make_sticky_action($node, $context = array()) {
*/
function node_make_unsticky_action($node, $context = array()) {
$node->sticky = NODE_NOT_STICKY;
- watchdog('action', 'Set @type %title to unsticky.', array('@type' => node_type_get_name($node), '%title' => $node->title));
+ watchdog('action', 'Set @type %title to unsticky.', array('@type' => node_type_get_name($node), '%title' => $node->title[FIELD_LANGUAGE_NONE][0]['value']));
}
/**
@@ -2984,7 +3015,7 @@ function node_make_unsticky_action($node, $context = array()) {
*/
function node_promote_action($node, $context = array()) {
$node->promote = NODE_PROMOTED;
- watchdog('action', 'Promoted @type %title to front page.', array('@type' => node_type_get_name($node), '%title' => $node->title));
+ watchdog('action', 'Promoted @type %title to front page.', array('@type' => node_type_get_name($node), '%title' => $node->title[FIELD_LANGUAGE_NONE][0]['value']));
}
/**
@@ -2993,7 +3024,7 @@ function node_promote_action($node, $context = array()) {
*/
function node_unpromote_action($node, $context = array()) {
$node->promote = NODE_NOT_PROMOTED;
- watchdog('action', 'Removed @type %title from front page.', array('@type' => node_type_get_name($node), '%title' => $node->title));
+ watchdog('action', 'Removed @type %title from front page.', array('@type' => node_type_get_name($node), '%title' => $node->title[FIELD_LANGUAGE_NONE][0]['value']));
}
/**
@@ -3002,7 +3033,7 @@ function node_unpromote_action($node, $context = array()) {
*/
function node_save_action($node) {
node_save($node);
- watchdog('action', 'Saved @type %title', array('@type' => node_type_get_name($node), '%title' => $node->title));
+ watchdog('action', 'Saved @type %title', array('@type' => node_type_get_name($node), '%title' => $node->title[FIELD_LANGUAGE_NONE][0]['value']));
}
/**
@@ -3012,7 +3043,7 @@ function node_save_action($node) {
function node_assign_owner_action($node, $context) {
$node->uid = $context['owner_uid'];
$owner_name = db_query("SELECT name FROM {users} WHERE uid = :uid", array(':uid' => $context['owner_uid']))->fetchField();
- watchdog('action', 'Changed owner of @type %title to uid %name.', array('@type' => node_type_get_type($node), '%title' => $node->title, '%name' => $owner_name));
+ watchdog('action', 'Changed owner of @type %title to uid %name.', array('@type' => node_type_get_type($node), '%title' => $node->title[FIELD_LANGUAGE_NONE][0]['value'], '%name' => $owner_name));
}
function node_assign_owner_action_form($context) {
@@ -3093,7 +3124,7 @@ function node_unpublish_by_keyword_action($node, $context) {
foreach ($context['keywords'] as $keyword) {
if (strpos(drupal_render(node_build(clone $node)), $keyword) !== FALSE || strpos($node->title, $keyword) !== FALSE) {
$node->status = NODE_NOT_PUBLISHED;
- watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_type_get_name($node), '%title' => $node->title));
+ watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_type_get_name($node), '%title' => $node->title[FIELD_LANGUAGE_NONE][0]['value']));
break;
}
}
@@ -3137,6 +3168,9 @@ class NodeController extends DrupalDefaultEntityController {
// object type specific callback.
$typed_nodes = array();
foreach ($nodes as $id => $object) {
+ if (isset($object->title)) {
+ $object->title = array(FIELD_LANGUAGE_NONE => array(array('value' => $object->title)));
+ }
$typed_nodes[$object->type][$id] = $object;
}
diff --git a/modules/node/node.pages.inc b/modules/node/node.pages.inc
index bd59747df..276a2dd86 100644
--- a/modules/node/node.pages.inc
+++ b/modules/node/node.pages.inc
@@ -12,7 +12,7 @@
*/
function node_page_edit($node) {
$type_name = node_type_get_name($node);
- drupal_set_title(t('<em>Edit @type</em> @title', array('@type' => $type_name, '@title' => $node->title)), PASS_THROUGH);
+ drupal_set_title(t('<em>Edit @type</em> @title', array('@type' => $type_name, '@title' => $node->title[FIELD_LANGUAGE_NONE][0]['value'])), PASS_THROUGH);
return drupal_get_form($node->type . '_node_form', $node);
}
@@ -150,9 +150,6 @@ function node_form($form, &$form_state, $node) {
if ($extra = node_invoke($node, 'form', $form_state)) {
$form = array_merge_recursive($form, $extra);
}
- if (!isset($form['title']['#weight'])) {
- $form['title']['#weight'] = -5;
- }
$form['#node'] = $node;
@@ -414,8 +411,8 @@ function node_form_submit($form, &$form_state) {
$insert = empty($node->nid);
node_save($node);
$node_link = l(t('view'), 'node/' . $node->nid);
- $watchdog_args = array('@type' => $node->type, '%title' => $node->title);
- $t_args = array('@type' => node_type_get_name($node), '%title' => $node->title);
+ $watchdog_args = array('@type' => $node->type, '%title' => $node->title[FIELD_LANGUAGE_NONE][0]['value']);
+ $t_args = array('@type' => node_type_get_name($node), '%title' => $node->title[FIELD_LANGUAGE_NONE][0]['value']);
if ($insert) {
watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
@@ -464,7 +461,7 @@ function node_delete_confirm($form, &$form_state, $node) {
);
return confirm_form($form,
- t('Are you sure you want to delete %title?', array('%title' => $node->title)),
+ t('Are you sure you want to delete %title?', array('%title' => $node->title[FIELD_LANGUAGE_NONE][0]['value'])),
isset($_GET['destination']) ? $_GET['destination'] : 'node/' . $node->nid,
t('This action cannot be undone.'),
t('Delete'),
@@ -479,8 +476,8 @@ function node_delete_confirm_submit($form, &$form_state) {
if ($form_state['values']['confirm']) {
$node = node_load($form_state['values']['nid']);
node_delete($form_state['values']['nid']);
- watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title));
- drupal_set_message(t('@type %title has been deleted.', array('@type' => node_type_get_name($node), '%title' => $node->title)));
+ watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title[FIELD_LANGUAGE_NONE][0]['value']));
+ drupal_set_message(t('@type %title has been deleted.', array('@type' => node_type_get_name($node), '%title' => $node->title[FIELD_LANGUAGE_NONE][0]['value'])));
}
$form_state['redirect'] = '<front>';
@@ -490,7 +487,7 @@ function node_delete_confirm_submit($form, &$form_state) {
* Generate an overview table of older revisions of a node.
*/
function node_revision_overview($node) {
- drupal_set_title(t('Revisions for %title', array('%title' => $node->title)), PASS_THROUGH);
+ drupal_set_title(t('Revisions for %title', array('%title' => $node->title[FIELD_LANGUAGE_NONE][0]['value'])), PASS_THROUGH);
$header = array(t('Revision'), array('data' => t('Operations'), 'colspan' => 2));
@@ -552,8 +549,8 @@ function node_revision_revert_confirm_submit($form, &$form_state) {
node_save($node_revision);
- watchdog('content', '@type: reverted %title revision %revision.', array('@type' => $node_revision->type, '%title' => $node_revision->title, '%revision' => $node_revision->vid));
- drupal_set_message(t('@type %title has been reverted back to the revision from %revision-date.', array('@type' => node_type_get_name($node_revision), '%title' => $node_revision->title, '%revision-date' => format_date($node_revision->revision_timestamp))));
+ watchdog('content', '@type: reverted %title revision %revision.', array('@type' => $node_revision->type, '%title' => $node_revision->title[FIELD_LANGUAGE_NONE][0]['value'], '%revision' => $node_revision->vid));
+ drupal_set_message(t('@type %title has been reverted back to the revision from %revision-date.', array('@type' => node_type_get_name($node_revision), '%title' => $node_revision->title[FIELD_LANGUAGE_NONE][0]['value'], '%revision-date' => format_date($node_revision->revision_timestamp))));
$form_state['redirect'] = 'node/' . $node_revision->nid . '/revisions';
}
@@ -566,8 +563,8 @@ function node_revision_delete_confirm_submit($form, &$form_state) {
$node_revision = $form['#node_revision'];
node_revision_delete($node_revision->vid);
- watchdog('content', '@type: deleted %title revision %revision.', array('@type' => $node_revision->type, '%title' => $node_revision->title, '%revision' => $node_revision->vid));
- drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($node_revision->revision_timestamp), '@type' => node_type_get_name($node_revision), '%title' => $node_revision->title)));
+ watchdog('content', '@type: deleted %title revision %revision.', array('@type' => $node_revision->type, '%title' => $node_revision->title[FIELD_LANGUAGE_NONE][0]['value'], '%revision' => $node_revision->vid));
+ drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($node_revision->revision_timestamp), '@type' => node_type_get_name($node_revision), '%title' => $node_revision->title[FIELD_LANGUAGE_NONE][0]['value'])));
$form_state['redirect'] = 'node/' . $node_revision->nid;
if (db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid', array(':nid' => $node_revision->nid))->fetchField() > 1) {
$form_state['redirect'] .= '/revisions';
diff --git a/modules/node/node.test b/modules/node/node.test
index f1c296a76..a4f5f90e1 100644
--- a/modules/node/node.test
+++ b/modules/node/node.test
@@ -31,15 +31,15 @@ class NodeLoadMultipleUnitTest extends DrupalWebTestCase {
// Confirm that promoted nodes appear in the default node listing.
$this->drupalGet('node');
- $this->assertText($node1->title, t('Node title appears on the default listing.'));
- $this->assertText($node2->title, t('Node title appears on the default listing.'));
- $this->assertNoText($node3->title, t('Node title does not appear in the default listing.'));
- $this->assertNoText($node4->title, t('Node title does not appear in the default listing.'));
+ $this->assertText($node1->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node title appears on the default listing.'));
+ $this->assertText($node2->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node title appears on the default listing.'));
+ $this->assertNoText($node3->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node title does not appear in the default listing.'));
+ $this->assertNoText($node4->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node title does not appear in the default listing.'));
// Load nodes with only a condition. Nodes 3 and 4 will be loaded.
$nodes = node_load_multiple(NULL, array('promote' => 0));
- $this->assertEqual($node3->title, $nodes[$node3->nid]->title, t('Node was loaded.'));
- $this->assertEqual($node4->title, $nodes[$node4->nid]->title, t('Node was loaded.'));
+ $this->assertEqual($node3->title[FIELD_LANGUAGE_NONE][0]['value'], $nodes[$node3->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node was loaded.'));
+ $this->assertEqual($node4->title[FIELD_LANGUAGE_NONE][0]['value'], $nodes[$node4->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node was loaded.'));
$count = count($nodes);
$this->assertTrue($count == 2, t('@count nodes loaded.', array('@count' => $count)));
@@ -58,9 +58,9 @@ class NodeLoadMultipleUnitTest extends DrupalWebTestCase {
$nodes = node_load_multiple(array(1, 2, 3, 4), array('type' => 'article'));
$count = count($nodes);
$this->assertTrue($count == 3, t('@count nodes loaded', array('@count' => $count)));
- $this->assertEqual($nodes[$node1->nid]->title, $node1->title, t('Node successfully loaded.'));
- $this->assertEqual($nodes[$node2->nid]->title, $node2->title, t('Node successfully loaded.'));
- $this->assertEqual($nodes[$node3->nid]->title, $node3->title, t('Node successfully loaded.'));
+ $this->assertEqual($nodes[$node1->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], $node1->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node successfully loaded.'));
+ $this->assertEqual($nodes[$node2->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], $node2->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node successfully loaded.'));
+ $this->assertEqual($nodes[$node3->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], $node3->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node successfully loaded.'));
$this->assertFalse(isset($nodes[$node4->nid]));
// Now that all nodes have been loaded into the static cache, ensure that
@@ -68,16 +68,16 @@ class NodeLoadMultipleUnitTest extends DrupalWebTestCase {
$nodes = node_load_multiple(array(1, 2, 3, 4), array('type' => 'article'));
$count = count($nodes);
$this->assertTrue($count == 3, t('@count nodes loaded.', array('@count' => $count)));
- $this->assertEqual($nodes[$node1->nid]->title, $node1->title, t('Node successfully loaded'));
- $this->assertEqual($nodes[$node2->nid]->title, $node2->title, t('Node successfully loaded'));
- $this->assertEqual($nodes[$node3->nid]->title, $node3->title, t('Node successfully loaded'));
+ $this->assertEqual($nodes[$node1->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], $node1->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node successfully loaded'));
+ $this->assertEqual($nodes[$node2->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], $node2->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node successfully loaded'));
+ $this->assertEqual($nodes[$node3->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], $node3->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node successfully loaded'));
$this->assertFalse(isset($nodes[$node4->nid]), t('Node was not loaded'));
// Load nodes by nid, where type = article and promote = 0.
$nodes = node_load_multiple(array(1, 2, 3, 4), array('type' => 'article', 'promote' => 0));
$count = count($nodes);
$this->assertTrue($count == 1, t('@count node loaded', array('@count' => $count)));
- $this->assertEqual($nodes[$node3->nid]->title, $node3->title, t('Node successfully loaded.'));
+ $this->assertEqual($nodes[$node3->nid]->title[FIELD_LANGUAGE_NONE][0]['value'], $node3->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node successfully loaded.'));
}
}
@@ -152,7 +152,7 @@ class NodeRevisionsTestCase extends DrupalWebTestCase {
// Confirm that revisions revert properly.
$this->drupalPost("node/$node->nid/revisions/{$nodes[1]->vid}/revert", array(), t('Revert'));
$this->assertRaw(t('@type %title has been reverted back to the revision from %revision-date.',
- array('@type' => 'Page', '%title' => $nodes[1]->title,
+ array('@type' => 'Page', '%title' => $nodes[1]->title[FIELD_LANGUAGE_NONE][0]['value'],
'%revision-date' => format_date($nodes[1]->revision_timestamp))), t('Revision reverted.'));
$reverted_node = node_load($node->nid);
$this->assertTrue(($nodes[1]->body[FIELD_LANGUAGE_NONE][0]['value'] == $reverted_node->body[FIELD_LANGUAGE_NONE][0]['value']), t('Node reverted correctly.'));
@@ -161,7 +161,7 @@ class NodeRevisionsTestCase extends DrupalWebTestCase {
$this->drupalPost("node/$node->nid/revisions/{$nodes[1]->vid}/delete", array(), t('Delete'));
$this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.',
array('%revision-date' => format_date($nodes[1]->revision_timestamp),
- '@type' => 'Page', '%title' => $nodes[1]->title)), t('Revision deleted.'));
+ '@type' => 'Page', '%title' => $nodes[1]->title[FIELD_LANGUAGE_NONE][0]['value'])), t('Revision deleted.'));
$this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', array(':nid' => $node->nid, ':vid' => $nodes[1]->vid))->fetchField() == 0, t('Revision not found.'));
}
}
@@ -187,15 +187,16 @@ class PageEditTestCase extends DrupalWebTestCase {
*/
function testPageEdit() {
$langcode = FIELD_LANGUAGE_NONE;
+ $title_key = "title[$langcode][0][value]";
$body_key = "body[$langcode][0][value]";
// Create node to edit.
$edit = array();
- $edit['title'] = $this->randomName(8);
+ $edit[$title_key] = $this->randomName(8);
$edit[$body_key] = $this->randomName(16);
$this->drupalPost('node/add/page', $edit, t('Save'));
// Check that the node exists in the database.
- $node = $this->drupalGetNodeByTitle($edit['title']);
+ $node = $this->drupalGetNodeByTitle($edit[$title_key]);
$this->assertTrue($node, t('Node found in database.'));
// Check that "edit" link points to correct page.
@@ -206,18 +207,18 @@ class PageEditTestCase extends DrupalWebTestCase {
// Check that the title and body fields are displayed with the correct values.
$this->assertLink(t('Edit'), 0, t('Edit tab found.'));
- $this->assertFieldByName('title', $edit['title'], t('Title field displayed.'));
+ $this->assertFieldByName($title_key, $edit[$title_key], t('Title field displayed.'));
$this->assertFieldByName($body_key, $edit[$body_key], t('Body field displayed.'));
// Edit the content of the node.
$edit = array();
- $edit['title'] = $this->randomName(8);
+ $edit[$title_key] = $this->randomName(8);
$edit[$body_key] = $this->randomName(16);
// Stay on the current page, without reloading.
$this->drupalPost(NULL, $edit, t('Save'));
// Check that the title and body fields are displayed with the updated values.
- $this->assertText($edit['title'], t('Title displayed.'));
+ $this->assertText($edit[$title_key], t('Title displayed.'));
$this->assertText($edit[$body_key], t('Body displayed.'));
// Login as a second administrator user.
@@ -226,13 +227,13 @@ class PageEditTestCase extends DrupalWebTestCase {
// Edit the same node, creating a new revision.
$this->drupalGet("node/$node->nid/edit");
$edit = array();
- $edit['title'] = $this->randomName(8);
+ $edit[$title_key] = $this->randomName(8);
$edit[$body_key] = $this->randomName(16);
$edit['revision'] = TRUE;
$this->drupalPost(NULL, $edit, t('Save'));
// Ensure that the node revision has been created.
- $revised_node = $this->drupalGetNodeByTitle($edit['title']);
+ $revised_node = $this->drupalGetNodeByTitle($edit[$title_key]);
$this->assertNotIdentical($node->vid, $revised_node->vid, 'A new revision has been created.');
// Ensure that the node author is preserved when it was not changed in the
// edit form.
@@ -266,21 +267,22 @@ class PagePreviewTestCase extends DrupalWebTestCase {
*/
function testPagePreview() {
$langcode = FIELD_LANGUAGE_NONE;
+ $title_key = "title[$langcode][0][value]";
$body_key = "body[$langcode][0][value]";
// Fill in node creation form and preview node.
$edit = array();
- $edit['title'] = $this->randomName(8);
+ $edit[$title_key] = $this->randomName(8);
$edit[$body_key] = $this->randomName(16);
$this->drupalPost('node/add/page', $edit, t('Preview'));
// Check that the preview is displaying the title and body.
$this->assertTitle(t('Preview | Drupal'), t('Page title is preview.'));
- $this->assertText($edit['title'], t('Title displayed.'));
+ $this->assertText($edit[$title_key], t('Title displayed.'));
$this->assertText($edit[$body_key], t('Body displayed.'));
// Check that the title and body fields are displayed with the correct values.
- $this->assertFieldByName('title', $edit['title'], t('Title field displayed.'));
+ $this->assertFieldByName($title_key, $edit[$title_key], t('Title field displayed.'));
$this->assertFieldByName($body_key, $edit[$body_key], t('Body field displayed.'));
}
@@ -289,24 +291,25 @@ class PagePreviewTestCase extends DrupalWebTestCase {
*/
function testPagePreviewWithRevisions() {
$langcode = FIELD_LANGUAGE_NONE;
+ $title_key = "title[$langcode][0][value]";
$body_key = "body[$langcode][0][value]";
// Force revision on page content.
variable_set('node_options_page', array('status', 'revision'));
// Fill in node creation form and preview node.
$edit = array();
- $edit['title'] = $this->randomName(8);
+ $edit[$title_key] = $this->randomName(8);
$edit[$body_key] = $this->randomName(16);
$edit['log'] = $this->randomName(32);
$this->drupalPost('node/add/page', $edit, t('Preview'));
// Check that the preview is displaying the title and body.
$this->assertTitle(t('Preview | Drupal'), t('Page title is preview.'));
- $this->assertText($edit['title'], t('Title displayed.'));
+ $this->assertText($edit[$title_key], t('Title displayed.'));
$this->assertText($edit[$body_key], t('Body displayed.'));
// Check that the title and body fields are displayed with the correct values.
- $this->assertFieldByName('title', $edit['title'], t('Title field displayed.'));
+ $this->assertFieldByName($title_key, $edit[$title_key], t('Title field displayed.'));
$this->assertFieldByName($body_key, $edit[$body_key], t('Body field displayed.'));
// Check that the log field has the correct value.
@@ -336,16 +339,16 @@ class PageCreationTestCase extends DrupalWebTestCase {
function testPageCreation() {
// Create a node.
$edit = array();
- $edit['title'] = $this->randomName(8);
$langcode = FIELD_LANGUAGE_NONE;
+ $edit["title[$langcode][0][value]"] = $this->randomName(8);
$edit["body[$langcode][0][value]"] = $this->randomName(16);
$this->drupalPost('node/add/page', $edit, t('Save'));
// Check that the page has been created.
- $this->assertRaw(t('!post %title has been created.', array('!post' => 'Page', '%title' => $edit['title'])), t('Page created.'));
+ $this->assertRaw(t('!post %title has been created.', array('!post' => 'Page', '%title' => $edit["title[$langcode][0][value]"])), t('Page created.'));
// Check that the node exists in the database.
- $node = $this->drupalGetNodeByTitle($edit['title']);
+ $node = $this->drupalGetNodeByTitle($edit["title[$langcode][0][value]"]);
$this->assertTrue($node, t('Node found in database.'));
}
}
@@ -446,18 +449,21 @@ class NodeTitleXSSTestCase extends DrupalWebTestCase {
$this->drupalLogin($web_user);
$xss = '<script>alert("xss")</script>';
-
+ $title = $xss . $this->randomName();
+ $langcode = FIELD_LANGUAGE_NONE;
$edit = array(
- 'title' => $xss . $this->randomName(),
+ "title[$langcode][0][value]" => $title,
);
+
$this->drupalPost('node/add/page', $edit, t('Preview'));
$this->assertNoRaw($xss, t('Harmful tags are escaped when previewing a node.'));
- $node = $this->drupalCreateNode($edit);
+ $settings = array('title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $title))));
+ $node = $this->drupalCreateNode($settings);
$this->drupalGet('node/' . $node->nid);
// assertTitle() decodes HTML-entities inside the <title> element.
- $this->assertTitle($edit['title'] . ' | Drupal', t('Title is diplayed when viewing a node.'));
+ $this->assertTitle($edit["title[$langcode][0][value]"] . ' | Drupal', t('Title is diplayed when viewing a node.'));
$this->assertNoRaw($xss, t('Harmful tags are escaped when viewing a node.'));
$this->drupalGet('node/' . $node->nid . '/edit');
@@ -526,13 +532,13 @@ class NodePostSettingsTestCase extends DrupalWebTestCase {
// Create a node.
$edit = array();
- $edit['title'] = $this->randomName(8);
$langcode = FIELD_LANGUAGE_NONE;
+ $edit["title[$langcode][0][value]"] = $this->randomName(8);
$edit["body[$langcode][0][value]"] = $this->randomName(16);
$this->drupalPost('node/add/page', $edit, t('Save'));
// Check that the post information is displayed.
- $node = $this->drupalGetNodeByTitle($edit['title']);
+ $node = $this->drupalGetNodeByTitle($edit["title[$langcode][0][value]"]);
$this->assertRaw('<span class="submitted">', t('Post information is displayed.'));
}
@@ -548,13 +554,13 @@ class NodePostSettingsTestCase extends DrupalWebTestCase {
// Create a node.
$edit = array();
- $edit['title'] = $this->randomName(8);
$langcode = FIELD_LANGUAGE_NONE;
+ $edit["title[$langcode][0][value]"] = $this->randomName(8);
$edit["body[$langcode][0][value]"] = $this->randomName(16);
$this->drupalPost('node/add/page', $edit, t('Save'));
// Check that the post information is displayed.
- $node = $this->drupalGetNodeByTitle($edit['title']);
+ $node = $this->drupalGetNodeByTitle($edit["title[$langcode][0][value]"]);
$this->assertNoRaw('<span class="submitted">', t('Post information is not displayed.'));
}
}
@@ -792,7 +798,7 @@ class NodeSaveTestCase extends DrupalWebTestCase {
$test_nid = $max_nid + mt_rand(1000, 1000000);
$title = $this->randomName(8);
$node = array(
- 'title' => $title,
+ 'title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $title))),
'body' => array(FIELD_LANGUAGE_NONE => array(array('value' => $this->randomName(32)))),
'uid' => $this->web_user->uid,
'type' => 'article',
@@ -966,7 +972,7 @@ class NodeAdminTestCase extends DrupalWebTestCase {
$node3 = $this->drupalCreateNode(array('type' => 'page'));
$this->drupalGet('admin/content');
- $this->assertText($node1->title, t('Node appears on the node administration listing.'));
+ $this->assertText($node1->title[FIELD_LANGUAGE_NONE][0]['value'], t('Node appears on the node administration listing.'));
// Filter the node listing by status.
$edit = array(
@@ -975,8 +981,8 @@ class NodeAdminTestCase extends DrupalWebTestCase {
);
$this->drupalPost('admin/content', $edit, t('Filter'));
$this->assertRaw(t('<strong>%type</strong> is <strong>%value</strong>', array('%type' => t('status'), '%value' => t('published'))), t('The node administration listing is filtered by status.'));
- $this->assertText($node1->title, t('Published node appears on the node administration listing.'));
- $this->assertNoText($node2->title, t('Unpublished node does not appear on the node administration listing.'));
+ $this->assertText($node1->title[FIELD_LANGUAGE_NONE][0]['value'], t('Published node appears on the node administration listing.'));
+ $this->assertNoText($node2->title[FIELD_LANGUAGE_NONE][0]['value'], t('Unpublished node does not appear on the node administration listing.'));
// Filter the node listing by content type.
$edit = array(
@@ -986,7 +992,53 @@ class NodeAdminTestCase extends DrupalWebTestCase {
$this->drupalPost('admin/content', $edit, t('Refine'));
$this->assertRaw(t('<strong>%type</strong> is <strong>%value</strong>', array('%type' => t('status'), '%value' => t('published'))), t('The node administration listing is filtered by status.'));
$this->assertRaw(t('<strong>%type</strong> is <strong>%value</strong>', array('%type' => t('type'), '%value' => 'Article')), t('The node administration listing is filtered by content type.'));
- $this->assertText($node1->title, t('Article node appears on the node administration listing.'));
- $this->assertNoText($node3->title, t('Page node does not appear on the node administration listing.'));
+ $this->assertText($node1->title[FIELD_LANGUAGE_NONE][0]['value'], t('Article node appears on the node administration listing.'));
+ $this->assertNoText($node3->title[FIELD_LANGUAGE_NONE][0]['value'], t('Page node does not appear on the node administration listing.'));
+ }
+}
+
+/**
+ * Test node title.
+ */
+class NodeTitleTestCase extends DrupalWebTestCase {
+ protected $admin_user;
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Node title',
+ 'description' => 'Test node title.',
+ 'group' => 'Node'
+ );
+ }
+
+ function setUp() {
+ parent::setUp();
+ $this->admin_user = $this->drupalCreateUser(array('administer nodes', 'create article content', 'create page content'));
+ $this->drupalLogin($this->admin_user);
+ }
+
+ /**
+ * Create one node and test if the node title has the correct value.
+ */
+ function testNodeTitle() {
+ // Create page content with title
+ $settings = array(
+ 'title' => array(FIELD_LANGUAGE_NONE => array(array('value' => $this->randomName(8)))),
+ );
+ $node = $this->drupalCreateNode($settings);
+
+ // Test <title> tag.
+ $this->drupalGet("node/$node->nid");
+ $xpath = '//title';
+ $this->assertEqual(current($this->xpath($xpath)), $node->title[FIELD_LANGUAGE_NONE][0]['value'] .' | Drupal', 'Page title is equal to node title.', 'Node');
+
+ // Test breadcrumb in comment preview.
+ $this->drupalGet("comment/reply/$node->nid");
+ $xpath = '//div[@class="breadcrumb"]/a[last()]';
+ $this->assertEqual(current($this->xpath($xpath)), $node->title[FIELD_LANGUAGE_NONE][0]['value'], 'Node breadcrumb is equal to node title.', 'Node');
+
+ // Test node title in comment preview.
+ $xpath = '//div[@id="node-'. $node->nid .'"]/h2/a';
+ $this->assertEqual(current($this->xpath($xpath)), $node->title[FIELD_LANGUAGE_NONE][0]['value'], 'Node preview title is equal to node title.', 'Node');
}
}
diff --git a/modules/node/node.tokens.inc b/modules/node/node.tokens.inc
index 4fb5dd402..06380fc79 100644
--- a/modules/node/node.tokens.inc
+++ b/modules/node/node.tokens.inc
@@ -134,7 +134,7 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr
break;
case 'title':
- $replacements[$original] = $sanitize ? check_plain($node->title) : $node->title;
+ $replacements[$original] = $sanitize ? check_plain($node->title[FIELD_LANGUAGE_NONE][0]['value']) : $node->title[FIELD_LANGUAGE_NONE][0]['value'];
break;
case 'body':
diff --git a/modules/node/node.tpl.php b/modules/node/node.tpl.php
index 1bc4c2c6e..99acaf5b2 100644
--- a/modules/node/node.tpl.php
+++ b/modules/node/node.tpl.php
@@ -75,7 +75,7 @@
<?php print $user_picture; ?>
<?php if (!$page): ?>
- <h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2>
+ <h2<?php print $title_attributes; ?>>a href="<?php print $node_url; ?>"><?php print $node_title; ?></a></h2>
<?php endif; ?>
<?php if ($display_submitted || !empty($content['links']['terms'])): ?>