Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
290
Merge Requests
290
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
84afe0d9
Commit
84afe0d9
authored
Aug 11, 2009
by
webchick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#545306
by alexanderpas: De-op hook_node_type().
parent
9c0e6e92
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
116 additions
and
84 deletions
+116
-84
modules/book/book.module
modules/book/book.module
+17
-21
modules/comment/comment.module
modules/comment/comment.module
+28
-28
modules/node/content_types.inc
modules/node/content_types.inc
+16
-3
modules/node/node.api.php
modules/node/node.api.php
+30
-20
modules/node/node.module
modules/node/node.module
+4
-4
modules/taxonomy/taxonomy.module
modules/taxonomy/taxonomy.module
+21
-8
No files found.
modules/book/book.module
View file @
84afe0d9
...
...
@@ -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
);
}
}
}
...
...
modules/comment/comment.module
View file @
84afe0d9
...
...
@@ -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
)
;
}
}
...
...
modules/node/content_types.inc
View file @
84afe0d9
...
...
@@ -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
)
{
...
...
modules/node/node.api.php
View file @
84afe0d9
...
...
@@ -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.
*
...
...
modules/node/node.module
View file @
84afe0d9
...
...
@@ -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
();
...
...
modules/taxonomy/taxonomy.module
View file @
84afe0d9
...
...
@@ -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'
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment