summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-08-11 15:50:56 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-08-11 15:50:56 +0000
commit84afe0d9275834a716edd826e8224e40cafa3746 (patch)
tree120beeede2cb7ad5d220927ba1aae56e44a98ad7 /modules
parent9c0e6e92426a061f78e6dfe685c7c37c7f72bc62 (diff)
downloadbrdo-84afe0d9275834a716edd826e8224e40cafa3746.tar.gz
brdo-84afe0d9275834a716edd826e8224e40cafa3746.tar.bz2
#545306 by alexanderpas: De-op hook_node_type().
Diffstat (limited to 'modules')
-rw-r--r--modules/book/book.module38
-rw-r--r--modules/comment/comment.module56
-rw-r--r--modules/node/content_types.inc19
-rw-r--r--modules/node/node.api.php50
-rw-r--r--modules/node/node.module8
-rw-r--r--modules/taxonomy/taxonomy.module29
6 files changed, 116 insertions, 84 deletions
diff --git a/modules/book/book.module b/modules/book/book.module
index af5b51e9d..9f2e6f241 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -1078,31 +1078,27 @@ function book_type_is_allowed($type) {
}
/**
- * Implement hook_node_type().
+ * Implement hook_node_type_update().
*
* Update book module's persistent variables if the machine-readable name of a
* node type is changed.
*/
-function book_node_type($op, $type) {
- switch ($op) {
- case 'update':
- if (!empty($type->old_type) && $type->old_type != $type->type) {
- // Update the list of node types that are allowed to be added to books.
- $allowed_types = variable_get('book_allowed_types', array('book'));
- $key = array_search($type->old_type, $allowed_types);
-
- if ($key !== FALSE) {
- $allowed_types[$type->type] = $allowed_types[$key] ? $type->type : 0;
- unset($allowed_types[$key]);
- variable_set('book_allowed_types', $allowed_types);
- }
-
- // Update the setting for the "Add child page" link.
- if (variable_get('book_child_type', 'book') == $type->old_type) {
- variable_set('book_child_type', $type->type);
- }
- }
- break;
+function book_node_type_update($type) {
+ if (!empty($type->old_type) && $type->old_type != $type->type) {
+ // Update the list of node types that are allowed to be added to books.
+ $allowed_types = variable_get('book_allowed_types', array('book'));
+ $key = array_search($type->old_type, $allowed_types);
+
+ if ($key !== FALSE) {
+ $allowed_types[$type->type] = $allowed_types[$key] ? $type->type : 0;
+ unset($allowed_types[$key]);
+ variable_set('book_allowed_types', $allowed_types);
+ }
+
+ // Update the setting for the "Add child page" link.
+ if (variable_get('book_child_type', 'book') == $type->old_type) {
+ variable_set('book_child_type', $type->type);
+ }
}
}
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index 06f13dea1..1681f7ea6 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -211,38 +211,38 @@ function comment_fieldable_info() {
return $return;
}
-
/**
- * Implement hook_node_type().
+ * Implement hook_node_type_insert().
*/
-function comment_node_type($op, $info) {
- switch ($op) {
- case 'insert':
- field_attach_create_bundle('comment_node_' . $info->type);
- break;
+function comment_node_type_insert($info) {
+ field_attach_create_bundle('comment_node_' . $info->type);
+}
- case 'update':
- if (!empty($info->old_type) && $info->type != $info->old_type) {
- field_attach_rename_bundle('comment_node_' . $info->old_type, 'comment_node_' . $info->type);
- }
- break;
+/**
+ * Implement hook_node_type_update().
+ */
+function comment_node_type_update($info) {
+ if (!empty($info->old_type) && $info->type != $info->old_type) {
+ field_attach_rename_bundle('comment_node_' . $info->old_type, 'comment_node_' . $info->type);
+ }
+}
- case 'delete':
- field_attach_delete_bundle('comment_node_' . $info->type);
-
- $settings = array(
- 'comment',
- 'comment_default_mode',
- 'comment_default_per_page',
- 'comment_anonymous',
- 'comment_subject_field',
- 'comment_preview',
- 'comment_form_location',
- );
- foreach ($settings as $setting) {
- variable_del($setting . '_' . $info->type);
- }
- break;
+/**
+ * Implement hook_node_type_delete().
+ */
+function comment_node_type_delete($info) {
+ field_attach_delete_bundle('comment_node_' . $info->type);
+ $settings = array(
+ 'comment',
+ 'comment_default_mode',
+ 'comment_default_per_page',
+ 'comment_anonymous',
+ 'comment_subject_field',
+ 'comment_preview',
+ 'comment_form_location',
+ );
+ foreach ($settings as $setting) {
+ variable_del($setting . '_' . $info->type);
}
}
diff --git a/modules/node/content_types.inc b/modules/node/content_types.inc
index 0a0e0e692..207a3d864 100644
--- a/modules/node/content_types.inc
+++ b/modules/node/content_types.inc
@@ -349,10 +349,23 @@ function node_type_form_submit($form, &$form_state) {
}
/**
- * Implement hook_node_type().
+ * Implement hook_node_type_insert().
*/
-function node_node_type($op, $info) {
- if ($op != 'delete' && !empty($info->old_type) && $info->old_type != $info->type) {
+function node_node_type_insert($info) {
+ if (!empty($info->old_type) && $info->old_type != $info->type) {
+ $update_count = node_type_update_nodes($info->old_type, $info->type);
+
+ if ($update_count) {
+ drupal_set_message(format_plural($update_count, 'Changed the content type of 1 post from %old-type to %type.', 'Changed the content type of @count posts from %old-type to %type.', array('%old-type' => $info->old_type, '%type' => $info->type)));
+ }
+ }
+}
+
+/**
+ * Implement hook_node_type_update().
+ */
+function node_node_type_update($info) {
+ if (!empty($info->old_type) && $info->old_type != $info->type) {
$update_count = node_type_update_nodes($info->old_type, $info->type);
if ($update_count) {
diff --git a/modules/node/node.api.php b/modules/node/node.api.php
index 818528082..24ccf1ffa 100644
--- a/modules/node/node.api.php
+++ b/modules/node/node.api.php
@@ -626,35 +626,45 @@ function hook_ranking() {
/**
+ * Act on node type creation.
+ *
+ * This hook allows modules to take action when a node type is created.
+ *
+ * @param $info
+ * The node type object which is being created.
+ */
+function hook_node_type_insert($info) {
+}
+
+/**
* Act on node type changes.
*
* This hook allows modules to take action when a node type is modified.
*
- * @param $op
- * What is being done to $info. Possible values:
- * - "delete"
- * - "insert"
- * - "update"
* @param $info
- * The node type object on which $op is being performed.
- */
-function hook_node_type($op, $info) {
-
- switch ($op) {
- case 'delete':
- variable_del('comment_' . $info->type);
- break;
- case 'update':
- if (!empty($info->old_type) && $info->old_type != $info->type) {
- $setting = variable_get('comment_' . $info->old_type, COMMENT_NODE_OPEN);
- variable_del('comment_' . $info->old_type);
- variable_set('comment_' . $info->type, $setting);
- }
- break;
+ * The node type object which is being modified.
+ */
+function hook_node_type_update($info) {
+ if (!empty($info->old_type) && $info->old_type != $info->type) {
+ $setting = variable_get('comment_' . $info->old_type, COMMENT_NODE_OPEN);
+ variable_del('comment_' . $info->old_type);
+ variable_set('comment_' . $info->type, $setting);
}
}
/**
+ * Act on node type deletion.
+ *
+ * This hook allows modules to take action when a node type is deleted.
+ *
+ * @param $info
+ * The node type object which is being deleted.
+ */
+function hook_node_type_delete($info) {
+ variable_del('comment_' . $info->type);
+}
+
+/**
* Define access restrictions.
*
* This hook allows node modules to limit access to the node types they
diff --git a/modules/node/node.module b/modules/node/node.module
index b66b423f0..40023b9af 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -431,7 +431,7 @@ function node_type_save($info) {
field_attach_rename_bundle($type->old_type, $type->type);
}
node_configure_fields($type);
- module_invoke_all('node_type', 'update', $type);
+ module_invoke_all('node_type_update', $type);
return SAVED_UPDATED;
}
else {
@@ -442,7 +442,7 @@ function node_type_save($info) {
field_attach_create_bundle($type->type);
node_configure_fields($type);
- module_invoke_all('node_type', 'insert', $type);
+ module_invoke_all('node_type_insert', $type);
return SAVED_NEW;
}
}
@@ -517,7 +517,7 @@ function node_type_delete($type) {
db_delete('node_type')
->condition('type', $type)
->execute();
- module_invoke_all('node_type', 'delete', $info);
+ module_invoke_all('node_type_delete', $info);
}
/**
@@ -2614,7 +2614,7 @@ function node_access_needs_rebuild($rebuild = NULL) {
* large number of nodes).
* hook_update_N and any form submit handler are safe contexts to use the
* 'batch mode'. Less decidable cases (such as calls from hook_user,
- * hook_taxonomy, hook_node_type...) might consider using the non-batch mode.
+ * hook_taxonomy, etc...) might consider using the non-batch mode.
*/
function node_access_rebuild($batch_mode = FALSE) {
db_delete('node_access')->execute();
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index ba349e623..f78a409b6 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -929,10 +929,17 @@ function taxonomy_node_save($node, $terms) {
}
/**
- * Implement hook_node_type().
+ * Implement hook_node_type_insert().
*/
-function taxonomy_node_type($op, $info) {
- if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) {
+function taxonomy_node_type_insert($info) {
+ drupal_static_reset('taxonomy_term_count_nodes');
+}
+
+/**
+ * Implement hook_node_type_update().
+ */
+function taxonomy_node_type_update($info) {
+ if (!empty($info->old_type) && $info->type != $info->old_type) {
db_update('taxonomy_vocabulary_node_type')
->fields(array(
'type' => $info->type,
@@ -940,11 +947,17 @@ function taxonomy_node_type($op, $info) {
->condition('type', $info->old_type)
->execute();
}
- elseif ($op == 'delete') {
- db_delete('taxonomy_vocabulary_node_type')
- ->condition('type', $info->type)
- ->execute();
- }
+ drupal_static_reset('taxonomy_term_count_nodes');
+}
+
+/**
+ * Implement hook_node_type_delete().
+ */
+function taxonomy_node_type_delete($info) {
+ db_delete('taxonomy_vocabulary_node_type')
+ ->condition('type', $info->type)
+ ->execute();
+
drupal_static_reset('taxonomy_term_count_nodes');
}