Commit 84afe0d9 authored by webchick's avatar webchick

#545306 by alexanderpas: De-op hook_node_type().

parent 9c0e6e92
......@@ -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);
}
}
}
......
......@@ -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);
}
}
......
......@@ -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) {
......
......@@ -625,35 +625,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.
*
......
......@@ -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();
......
......@@ -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');
}
......
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