Commit 78b447ea authored by JonBob's avatar JonBob

#69472: Change type prefix from "content-" to "content_" to assist in theming

of forms. Those using views.module may have to re-save views after this change.
Custom node templates will need to be renamed.
parent 392fc8b1
...@@ -184,3 +184,41 @@ function content_update_5() { ...@@ -184,3 +184,41 @@ function content_update_5() {
function content_update_6() { function content_update_6() {
return array(update_sql('DELETE FROM {cache}')); return array(update_sql('DELETE FROM {cache}'));
} }
/**
* Rename the "content-" prefix to "content_" to aid in form theming.
*/
function content_update_7() {
$ret = array();
$type_result = db_query("SELECT type_name FROM {node_type} WHERE type_name LIKE 'content-%%'");
if (db_num_rows($type_result)) {
// Multi-part update
if (!isset($_SESSION['content_update_7'])) {
$_SESSION['content_update_7'] = 0;
$_SESSION['content_update_7_max'] = db_num_rows($type_result);
}
$type = db_fetch_object($type_result);
$old_type_name = $type->type_name;
$new_type_name = str_replace('content-', 'content_', $old_type_name);
$ret[] = update_sql("UPDATE {node} SET type = '". $new_type_name ."' WHERE type = '". $old_type_name ."'");
$ret[] = update_sql("UPDATE {node_type} SET type_name = '". $new_type_name ."' WHERE type_name = '". $old_type_name ."'");
$ret[] = update_sql("UPDATE {node_field_instance} SET type_name = '". $new_type_name ."' WHERE type_name = '". $old_type_name ."'");
$ret[] = update_sql("UPDATE {vocabulary_node_types} SET type = '". $new_type_name ."' WHERE type = '". $old_type_name ."'");
$variable_result = db_query("SELECT name, value FROM {variable} WHERE name LIKE '%%%s%%' OR value LIKE '%%%s%%'", $old_type_name, $old_type_name);
while ($variable = db_fetch_object($variable_result)) {
$new_name = str_replace($old_type_name, $new_type_name, $variable->name);
$new_value = str_replace($old_type_name, $new_type_name, $variable->value);
db_query("UPDATE {variable} SET name = '%s', value = '%s' WHERE name = '%s'", $new_name, $new_value, $variable->name);
}
$ret[] = update_sql('DELETE FROM {cache}');
$_SESSION['content_update_7']++;
$ret['#finished'] = $_SESSION['content_update_7'] / $_SESSION['content_update_7_max'];
return $ret;
}
}
...@@ -723,7 +723,7 @@ function _content_type_info($reset = FALSE) { ...@@ -723,7 +723,7 @@ function _content_type_info($reset = FALSE) {
$info['content types'][$type['type_name']] = $type; $info['content types'][$type['type_name']] = $type;
} }
dprint_r($info);
cache_set('content_type_info', serialize($info), CACHE_PERMANENT); cache_set('content_type_info', serialize($info), CACHE_PERMANENT);
} }
} }
...@@ -769,7 +769,7 @@ function content_database_info($field) { ...@@ -769,7 +769,7 @@ function content_database_info($field) {
$db_info['table'] = 'node_data_'. $field['field_name']; $db_info['table'] = 'node_data_'. $field['field_name'];
} }
else { else {
$db_info['table'] = 'node_'. strtr($field['type_name'], '-', '_'); $db_info['table'] = 'node_'. $field['type_name'];
} }
if (is_array($columns) && count($columns)) { if (is_array($columns) && count($columns)) {
...@@ -956,7 +956,7 @@ function content_views_argument_handler($op, &$query, $argtype, $arg = '') { ...@@ -956,7 +956,7 @@ function content_views_argument_handler($op, &$query, $argtype, $arg = '') {
// The table name used here is the Views alias for the table, not the actual // The table name used here is the Views alias for the table, not the actual
// table name. // table name.
$table = 'node_data_'. $field['field_name']; $table = 'node_data_'. $field['field_name'];
switch ($op) { switch ($op) {
case 'summary': case 'summary':
...@@ -997,7 +997,7 @@ function content_views_argument_handler($op, &$query, $argtype, $arg = '') { ...@@ -997,7 +997,7 @@ function content_views_argument_handler($op, &$query, $argtype, $arg = '') {
} }
$view = module_invoke($module, 'field_view_item', $field, $item); $view = module_invoke($module, 'field_view_item', $field, $item);
// Strip any links that appear in the view, so that the new link we create works here. // Strip any links that appear in the view, so that the new link we create works here.
$view = preg_replace('!</?a(\s+[^>]*)?>!i', '', $view); $view = preg_replace('!</?a(\s+[^>]*)?>!i', '', $view);
...@@ -1032,6 +1032,15 @@ function content_pathauto_node($op, $node = NULL) { ...@@ -1032,6 +1032,15 @@ function content_pathauto_node($op, $node = NULL) {
case 'values': case 'values':
$results = array(); $results = array();
// Get node output (filtered and with module-specific fields).
if (node_hook($node, 'view')) {
node_invoke($node, 'view', false, false);
}
else {
$node = node_prepare($node, false);
}
// Allow modules to change $node->body before viewing.
node_invoke_nodeapi($node, 'view', false, false);
// Get node output (filtered and with module-specific fields). // Get node output (filtered and with module-specific fields).
if (node_hook($node, 'view')) { if (node_hook($node, 'view')) {
node_invoke($node, 'view', false, false); node_invoke($node, 'view', false, false);
...@@ -1044,7 +1053,7 @@ function content_pathauto_node($op, $node = NULL) { ...@@ -1044,7 +1053,7 @@ function content_pathauto_node($op, $node = NULL) {
foreach (content_fields() as $field) { foreach (content_fields() as $field) {
$items = $node->$field['field_name']; $items = $node->$field['field_name'];
$results['['. $field['field_name'] .']'] = pathauto_cleanstring($items[0]['view']); $results['['. $field['field_name'] .']'] = pathauto_cleanstring(strip_tags($items[0]['view']));
} }
return $results; return $results;
......
...@@ -139,7 +139,7 @@ function _content_admin_type_edit_submit($form_id, $form_values) { ...@@ -139,7 +139,7 @@ function _content_admin_type_edit_submit($form_id, $form_values) {
$form_values['type_name'] = drupal_strtolower($form_values['type_name']); $form_values['type_name'] = drupal_strtolower($form_values['type_name']);
$form_values['type_name'] = str_replace(array(' ', '-'), '_', $form_values['type_name']); $form_values['type_name'] = str_replace(array(' ', '-'), '_', $form_values['type_name']);
$form_values['type_name'] = preg_replace('/[^a-z0-9_]/', '', $form_values['type_name']); $form_values['type_name'] = preg_replace('/[^a-z0-9_]/', '', $form_values['type_name']);
$form_values['type_name'] = 'content-'. $form_values['type_name']; $form_values['type_name'] = 'content_'. $form_values['type_name'];
$form_values['type_name'] = substr($form_values['type_name'], 0, 32); $form_values['type_name'] = substr($form_values['type_name'], 0, 32);
if (isset($types[$form_values['type_name']])) { if (isset($types[$form_values['type_name']])) {
$counter = 0; $counter = 0;
...@@ -154,7 +154,7 @@ function _content_admin_type_edit_submit($form_id, $form_values) { ...@@ -154,7 +154,7 @@ function _content_admin_type_edit_submit($form_id, $form_values) {
switch ($GLOBALS['db_type']) { switch ($GLOBALS['db_type']) {
case 'mysql': case 'mysql':
case 'mysqli': case 'mysqli':
db_query("CREATE TABLE {node_". strtr($form_values['type_name'], '-', '_') ."} ( db_query("CREATE TABLE {node_". $form_values['type_name'] ."} (
vid int unsigned NOT NULL default '0', vid int unsigned NOT NULL default '0',
nid int unsigned NOT NULL default '0', nid int unsigned NOT NULL default '0',
PRIMARY KEY (vid) PRIMARY KEY (vid)
...@@ -162,7 +162,7 @@ function _content_admin_type_edit_submit($form_id, $form_values) { ...@@ -162,7 +162,7 @@ function _content_admin_type_edit_submit($form_id, $form_values) {
break; break;
case 'pgsql': case 'pgsql':
db_query("CREATE TABLE {node_". strtr($form_values['type_name'], '-', '_') ."} ( db_query("CREATE TABLE {node_". $form_values['type_name'] ."} (
vid integer unsigned NOT NULL default '0', vid integer unsigned NOT NULL default '0',
nid integer unsigned NOT NULL default '0', nid integer unsigned NOT NULL default '0',
PRIMARY KEY (vid) PRIMARY KEY (vid)
...@@ -213,7 +213,7 @@ function _content_admin_type_delete_submit($form_id, $form_values) { ...@@ -213,7 +213,7 @@ function _content_admin_type_delete_submit($form_id, $form_values) {
db_query("DELETE FROM {node_field_instance} WHERE type_name = '%s'", $form_values['type_name']); db_query("DELETE FROM {node_field_instance} WHERE type_name = '%s'", $form_values['type_name']);
db_query("DELETE FROM {node_type} WHERE type_name = '%s'", $form_values['type_name']); db_query("DELETE FROM {node_type} WHERE type_name = '%s'", $form_values['type_name']);
db_query("DROP TABLE {node_". strtr($form_values['type_name'], '-', '_') ."}"); db_query("DROP TABLE {node_". $form_values['type_name'] ."}");
drupal_set_message(t('Deleted content type %type.', array('%type' => theme('placeholder', $type['label'])))); drupal_set_message(t('Deleted content type %type.', array('%type' => theme('placeholder', $type['label']))));
content_clear_type_cache(); content_clear_type_cache();
......
...@@ -65,9 +65,9 @@ function hook_field_info() { ...@@ -65,9 +65,9 @@ function hook_field_info() {
* include a "sortable" parameter to indicate to views.module that the * include a "sortable" parameter to indicate to views.module that the
* column contains ordered information. Details of other information that can * column contains ordered information. Details of other information that can
* be passed to the database layer can be found at content_db_add_column(). * be passed to the database layer can be found at content_db_add_column().
* - The "filters" operation should return an array whose values are 'filters' * - The "filters" operation should return an array whose values are 'filters'
* definitions as expected by views.module (see Views Documentation). * definitions as expected by views.module (see Views Documentation).
* When proving several filters, it is recommended to use the 'name' * When proving several filters, it is recommended to use the 'name'
* attribute in order to let the user distinguish between them. If no 'name' * attribute in order to let the user distinguish between them. If no 'name'
* is specified for a filter, the key of the filter will be used instead. * is specified for a filter, the key of the filter will be used instead.
*/ */
......
...@@ -275,7 +275,7 @@ function nodereference_autocomplete($field_name, $string = '') { ...@@ -275,7 +275,7 @@ function nodereference_autocomplete($field_name, $string = '') {
foreach (_nodereference_potential_references($field, TRUE) as $key => $value) { foreach (_nodereference_potential_references($field, TRUE) as $key => $value) {
if (stristr($value->title, $string)) { if (stristr($value->title, $string)) {
$matches[$value->title] = check_plain('('. str_replace('content-', '', $value->type) .') '. $value->title); $matches[$value->title] = check_plain('('. str_replace('content_', '', $value->type) .') '. $value->title);
} }
} }
......
...@@ -41,8 +41,8 @@ may theme the entire node as a unit. This allows you to affect field order, to ...@@ -41,8 +41,8 @@ may theme the entire node as a unit. This allows you to affect field order, to
change the HTML structure to something more complicated, like a table, or even change the HTML structure to something more complicated, like a table, or even
to exclude fields from the presentation entirely. The setup for theming a node to exclude fields from the presentation entirely. The setup for theming a node
is simpler than for theming a field; simply create a file called is simpler than for theming a field; simply create a file called
"node-content-foo.tpl.php" where "content-foo" is the content type name as "node-content_foo.tpl.php" where "content_foo" is the content type name as
listed on the administration page. For an example of the typical contents of listed on the administration page. For an example of the typical contents of
this file, investigate the included example here this file, investigate the included example here
("node-content-example.tpl.php") or the "node.tpl.php" file that comes with ("node-content_example.tpl.php") or the "node.tpl.php" file that comes with
your theme. your theme.
\ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<div class="content"> <div class="content">
Here's the body: Here's the body:
<?php print $field_body[0]['view']; ?> <?php print $field_body[0]['view']; ?>
And some footnotes: And some footnotes:
<ul> <ul>
<?php <?php
......
...@@ -212,7 +212,7 @@ function userreference_widget($op, &$node, $field, &$node_field) { ...@@ -212,7 +212,7 @@ function userreference_widget($op, &$node, $field, &$node_field) {
$node_field[$delta]['uid'] = $uid; $node_field[$delta]['uid'] = $uid;
} }
else { else {
unset($node_field[$delta]); unset($node_field[$delta]);
} }
} }
} }
...@@ -257,4 +257,3 @@ function _userreference_filter_handler($op, $filterinfo) { ...@@ -257,4 +257,3 @@ function _userreference_filter_handler($op, $filterinfo) {
$options = array_merge($options, _userreference_potential_references($filterinfo['extra']['field'])); $options = array_merge($options, _userreference_potential_references($filterinfo['extra']['field']));
return $options; return $options;
} }
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