Commit cab88a70 authored by webchick's avatar webchick

#220233 by Berdir, marcingy, et al: Add useful API functions for extracting node type data.

parent 6fc4eb9f
......@@ -74,7 +74,7 @@ function blog_help($path, $arg) {
*/
function blog_form($node, $form_state) {
global $nid;
$type = node_get_types('type', $node);
$type = node_type_get_type($node);
$form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => !empty($node->title) ? $node->title : NULL, '#weight' => -5);
$form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
......
......@@ -719,7 +719,7 @@ function blogapi_blogger_title(&$contents) {
* Add some settings to the admin_settings form.
*/
function blogapi_admin_settings() {
$node_types = array_map('check_plain', node_get_types('names'));
$node_types = array_map('check_plain', node_type_get_names());
$defaults = isset($node_types['blog']) ? array('blog' => 1) : array();
$form['blogapi_node_types'] = array(
'#type' => 'checkboxes',
......@@ -959,7 +959,7 @@ function _blogapi_validate_blogid($blogid) {
function _blogapi_get_node_types() {
$available_types = array_keys(array_filter(variable_get('blogapi_node_types', array('blog' => 1))));
$types = array();
foreach (node_get_types() as $type => $name) {
foreach (node_type_get_types() as $type => $name) {
if (node_access('create', $type) && in_array($type, $available_types)) {
$types[] = $type;
}
......
......@@ -35,7 +35,7 @@ function book_admin_overview() {
* @ingroup forms
*/
function book_admin_settings() {
$types = node_get_types('names');
$types = node_type_get_names();
$form['book_allowed_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Allowed book outline types'),
......
......@@ -23,7 +23,7 @@ function comment_uninstall() {
// Remove variables.
variable_del('comment_block_count');
$node_types = array_keys(node_get_types());
$node_types = array_keys(node_type_get_types());
foreach ($node_types as $node_type) {
variable_del('comment_' . $node_type);
variable_del('comment_anonymous_' . $node_type);
......@@ -90,7 +90,7 @@ function comment_update_6002() {
'comment_preview' => COMMENT_PREVIEW_REQUIRED,
'comment_form_location' => COMMENT_FORM_SEPARATE_PAGE,
);
$types = node_get_types();
$types = node_type_get_types();
foreach ($settings as $setting => $default) {
$value = variable_get($setting, $default);
foreach ($types as $type => $object) {
......@@ -125,7 +125,7 @@ function comment_update_6003() {
* Remove comment settings for page ordering.
*/
function comment_update_7000() {
$types = node_get_types();
$types = node_type_get_types();
foreach ($types as $type => $object) {
variable_del('comment_default_order' . $type);
}
......
......@@ -47,7 +47,7 @@ function hook_fieldable_info() {
'cacheable' => FALSE,
// Bundles must provide human readable name so
// we can create help and error messages about them.
'bundles' => node_get_types('names'),
'bundles' => node_type_get_names(),
),
);
return $return;
......
......@@ -538,7 +538,7 @@ function forum_block_view($delta = '') {
* Implement hook_form().
*/
function forum_form($node, $form_state) {
$type = node_get_types('type', $node);
$type = node_type_get_type($node);
$form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#default_value' => !empty($node->title) ? $node->title : '', '#required' => TRUE, '#weight' => -5);
if (!empty($node->nid)) {
......@@ -746,7 +746,7 @@ function template_preprocess_forums(&$variables) {
if (node_access('create', $type)) {
// Fetch the "General" name of the content type;
// Push the link with title and url to the array.
$forum_types[$type] = array('title' => t('Post new @node_type', array('@node_type' => node_get_types('name', $type))), 'href' => 'node/add/' . str_replace('_', '-', $type) . '/' . $variables['tid']);
$forum_types[$type] = array('title' => t('Post new @node_type', array('@node_type' => node_type_get_name($type))), 'href' => 'node/add/' . str_replace('_', '-', $type) . '/' . $variables['tid']);
}
}
......
......@@ -185,7 +185,7 @@ function locale_update_6004() {
* interfere with language variables.
*/
function locale_update_6005() {
foreach (node_get_types() as $type => $content_type) {
foreach (node_type_get_types() as $type => $content_type) {
// Default to NULL, so we can skip dealing with non-existent settings.
$setting = variable_get('language_' . $type);
if ($type == 'default' && is_numeric($setting)) {
......@@ -254,7 +254,7 @@ function locale_uninstall() {
variable_del('locale_cache_strings');
variable_del('locale_js_directory');
foreach (node_get_types() as $type => $content_type) {
foreach (node_type_get_types() as $type => $content_type) {
$setting = variable_del('language_content_type_' . $type);
}
......
......@@ -10,14 +10,14 @@
* Displays the content type admin overview page.
*/
function node_overview_types() {
$types = node_get_types();
$names = node_get_types('names');
$types = node_type_get_types();
$names = node_type_get_names();
$header = array(t('Name'), array('data' => t('Operations'), 'colspan' => '2'));
$rows = array();
foreach ($names as $key => $name) {
$type = $types[$key];
if (node_hook($type, 'form')) {
$type = $types[$key];
if (node_hook($type->type, 'form')) {
$type_url_str = str_replace('_', '-', $type->type);
$row = array(theme('node_admin_overview', $name, $type));
// Set the edit column.
......@@ -233,7 +233,7 @@ function node_type_form_validate($form, &$form_state) {
// Work out what the type was before the user submitted this form
$old_type = trim($form_state['values']['old_type']);
$types = node_get_types('names');
$types = node_type_get_names();
if (!$form_state['values']['locked']) {
if (isset($types[$type->type]) && $type->type != $old_type) {
......
......@@ -144,7 +144,7 @@ function node_filters() {
);
}
$filters['type'] = array('title' => t('type'), 'options' => node_get_types('names'));
$filters['type'] = array('title' => t('type'), 'options' => node_type_get_names());
// The taxonomy filter
if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
......@@ -501,7 +501,7 @@ function node_admin_nodes() {
$nodes[$node->nid] = '';
$options = empty($node->language) ? array() : array('language' => $languages[$node->language]);
$form['title'][$node->nid] = array('#markup' => l($node->title, 'node/' . $node->nid, $options) . ' ' . theme('mark', node_mark($node->nid, $node->changed)));
$form['name'][$node->nid] = array('#markup' => check_plain(node_get_types('name', $node)));
$form['name'][$node->nid] = array('#markup' => check_plain(node_type_get_name($node)));
$form['username'][$node->nid] = array('#markup' => theme('username', $node));
$form['status'][$node->nid] = array('#markup' => ($node->status ? t('published') : t('not published')));
$form['changed'][$node->nid] = array('#markup' => format_date($node->changed, 'small'));
......
......@@ -736,7 +736,7 @@ function hook_prepare($node) {
* For a detailed usage example, see node_example.module.
*/
function hook_form($node, $form_state) {
$type = node_get_types('type', $node);
$type = node_type_get_type($node);
$form['title'] = array(
'#type' => 'textfield',
......
This diff is collapsed.
......@@ -11,7 +11,7 @@
* Menu callback; presents the node editing form, or redirects to delete confirmation.
*/
function node_page_edit($node) {
$type_name = node_get_types('name', $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);
return drupal_get_form($node->type . '_node_form', $node);
}
......@@ -53,7 +53,7 @@ function theme_node_add_list($content) {
function node_add($type) {
global $user;
$types = node_get_types();
$types = node_type_get_types();
$type = isset($type) ? str_replace('-', '_', $type) : NULL;
// If a node type has been specified, validate its existence.
if (isset($types[$type]) && node_access('create', $type)) {
......@@ -290,7 +290,7 @@ function node_form(&$form_state, $node) {
*/
function node_body_field($node, $label, $word_count) {
// Do not generate a body field if the type does not specify one.
if (!node_get_types('type', $node)->has_body) {
if (!node_type_get_type($node->type)->has_body) {
return array();
}
......@@ -463,7 +463,7 @@ function node_form_submit($form, &$form_state) {
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_get_types('name', $node), '%title' => $node->title);
$t_args = array('@type' => node_type_get_name($node), '%title' => $node->title);
if ($insert) {
watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
......@@ -528,7 +528,7 @@ function node_delete_confirm_submit($form, &$form_state) {
$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_get_types('name', $node), '%title' => $node->title)));
drupal_set_message(t('@type %title has been deleted.', array('@type' => node_type_get_name($node), '%title' => $node->title)));
}
$form_state['redirect'] = '<front>';
......@@ -598,7 +598,7 @@ 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_get_types('name', $node_revision), '%title' => $node_revision->title, '%revision-date' => format_date($node_revision->revision_timestamp))));
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))));
$form_state['redirect'] = 'node/' . $node_revision->nid . '/revisions';
}
......@@ -615,7 +615,7 @@ function node_revision_delete_confirm_submit($form, &$form_state) {
->execute();
module_invoke_all('node_delete_revision', $node_revision);
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_get_types('name', $node_revision), '%title' => $node_revision->title)));
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)));
$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';
......
......@@ -801,3 +801,35 @@ class NodeSaveTestCase extends DrupalWebTestCase {
$this->assertTrue($node_by_title, t('Node load by node title.'));
}
}
/**
* Tests related to node types.
*/
class NodeTypeTestCase extends DrupalWebTestCase {
function getInfo() {
return array(
'name' => t('Node types'),
'description' => t('Ensures that node type functions work correctly.'),
'group' => t('Node'),
);
}
/**
* Ensure that node type functions (node_type_get_*) work correctly.
*
* Load available node types and validate the returned data.
*/
function testNodeTypeGetFunctions() {
$node_types = node_type_get_types();
$node_names = node_type_get_names();
$this->assertTrue(isset($node_types['article']), t('Node type article is available.'));
$this->assertTrue(isset($node_types['page']), t('Node type page is available.'));
$this->assertEqual($node_types['article']->name, $node_names['article'], t('Correct node type base has been returned.'));
$this->assertEqual($node_types['article'], node_type_get_type('article'), t('Correct node type has been returned.'));
$this->assertEqual($node_types['article']->name, node_type_get_name('article'), t('Correct node type name has been returned.'));
$this->assertEqual($node_types['page']->base, node_type_get_base('page'), t('Correct node type base has been returned.'));
}
}
......@@ -206,7 +206,7 @@ function poll_form($node, $form_state) {
$admin = user_access('administer nodes') || user_access('edit any poll content') || (user_access('edit own poll content') && $user->uid == $node->uid);
$type = node_get_types('type', $node);
$type = node_type_get_type($node);
$form = array(
'#cache' => TRUE,
......
......@@ -46,7 +46,7 @@ class PollTestCase extends DrupalWebTestCase {
$this->drupalPost(NULL, $edit, t('Save'));
$node = $this->drupalGetNodeByTitle($title);
$this->assertText(t('@type @title has been created.', array('@type' => node_get_types('name', 'poll'), '@title' => $title)), 'Poll has been created.');
$this->assertText(t('@type @title has been created.', array('@type' => node_type_get_name('poll'), '@title' => $title)), 'Poll has been created.');
$this->assertTrue($node->nid, t('Poll has been found in the database.'));
return isset($node->nid) ? $node->nid : FALSE;
......@@ -80,7 +80,7 @@ class PollTestCase extends DrupalWebTestCase {
function pollUpdate($nid, $title, $edit) {
// Edit the poll node.
$this->drupalPost('node/' . $nid . '/edit', $edit, t('Save'));
$this->assertText(t('@type @title has been updated.', array('@type' => node_get_types('name', 'poll'), '@title' => $title)), 'Poll has been updated.');
$this->assertText(t('@type @title has been updated.', array('@type' => node_type_get_name('poll'), '@title' => $title)), 'Poll has been updated.');
}
}
......
......@@ -184,7 +184,7 @@ function hook_search($op = 'search', $keys = NULL) {
$results[] = array(
'link' => url('node/' . $item->sid, array('absolute' => TRUE)),
'type' => check_plain(node_get_types('name', $node)),
'type' => check_plain(node_type_get_name($node)),
'title' => $node->title,
'user' => theme('username', $node),
'date' => $node->changed,
......
......@@ -701,7 +701,7 @@ protected function drupalCreateContentType($settings = array()) {
// Find a non-existent random type name.
do {
$name = strtolower($this->randomName(8));
} while (node_get_types('type', $name));
} while (node_type_get_type($name));
// Populate defaults array.
$defaults = array(
......
......@@ -902,7 +902,7 @@ function hook_mail($key, &$message, $params) {
$variables += array(
'%uid' => $node->uid,
'%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
'%node_type' => node_get_types('name', $node),
'%node_type' => node_type_get_name($node),
'%title' => $node->title,
'%teaser' => $node->teaser,
'%body' => $node->body,
......
......@@ -3306,7 +3306,7 @@ function system_update_7016() {
*/
function system_update_7017() {
$ret = array();
$types = node_get_types();
$types = node_type_get_types();
if (count($types)) {
foreach ($types as $type) {
$node_info = theme_get_setting('toggle_node_info_' . $type->type);
......
......@@ -2158,7 +2158,7 @@ function system_mail($key, &$message, $params) {
$variables += array(
'%uid' => $node->uid,
'%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
'%node_type' => node_get_types('name', $node),
'%node_type' => node_type_get_name($node),
'%title' => $node->title,
'%teaser' => $node->teaser,
'%body' => $node->body,
......@@ -2232,7 +2232,7 @@ function system_message_action(&$object, $context = array()) {
$variables = array_merge($variables, array(
'%uid' => $node->uid,
'%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
'%node_type' => check_plain(node_get_types('name', $node)),
'%node_type' => check_plain(node_type_get_name($node)),
'%title' => filter_xss($node->title),
'%teaser' => filter_xss($node->teaser),
'%body' => filter_xss($node->body),
......
......@@ -19,7 +19,7 @@ function taxonomy_overview_vocabularies() {
foreach ($vocabularies as $vocabulary) {
$types = array();
foreach ($vocabulary->nodes as $type) {
$node_type = node_get_types('name', $type);
$node_type = node_type_get_name($type);
$types[] = $node_type ? check_plain($node_type) : check_plain($type);
}
$form[$vocabulary->vid]['#vocabulary'] = $vocabulary;
......@@ -146,7 +146,7 @@ function taxonomy_form_vocabulary(&$form_state, $edit = array()) {
'#type' => 'checkboxes',
'#title' => t('Content types'),
'#default_value' => $edit['nodes'],
'#options' => array_map('check_plain', node_get_types('names')),
'#options' => array_map('check_plain', node_type_get_names()),
'#description' => t('Select content types to categorize using this vocabulary.'),
);
$form['settings'] = array(
......
......@@ -61,7 +61,7 @@ function tracker_page($account = NULL, $set_title = FALSE) {
}
$rows[] = array(
check_plain(node_get_types('name', $node->type)),
check_plain(node_type_get_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),
......
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