Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
02c1eeee
Commit
02c1eeee
authored
Jan 30, 2010
by
webchick
Browse files
#684202
by catch: Added Entity insert/delete/update hooks, to support caching.
parent
b1d0d134
Changes
7
Hide whitespace changes
Inline
Side-by-side
includes/common.inc
View file @
02c1eeee
...
...
@@ -6575,6 +6575,19 @@ function entity_path($entity_type, $entity) {
return
$info
[
'path callback'
](
$entity
);
}
}
/**
* Invokes entity insert/update hooks.
*
* @param $op
* One of 'insert' or 'update'.
* @param $entity_type
* The entity type; e.g. 'node' or 'user'.
* @param $entity
* The entity object being operated on.
*/
function
entity_invoke
(
$op
,
$entity_type
,
$entity
)
{
module_invoke_all
(
'entity_'
.
$op
,
$entity
,
$entity_type
);
}
/**
* Performs one or more XML-RPC request(s).
...
...
includes/file.inc
View file @
02c1eeee
...
...
@@ -512,11 +512,13 @@ function file_save(stdClass $file) {
drupal_write_record
(
'file'
,
$file
);
// Inform modules about the newly added file.
module_invoke_all
(
'file_insert'
,
$file
);
entity_invoke
(
'insert'
,
'file'
,
$file
);
}
else
{
drupal_write_record
(
'file'
,
$file
,
'fid'
);
// Inform modules that the file has been updated.
module_invoke_all
(
'file_update'
,
$file
);
entity_invoke
(
'update'
,
'file'
,
$file
);
}
return
$file
;
...
...
modules/comment/comment.module
View file @
02c1eeee
...
...
@@ -1370,6 +1370,7 @@ function comment_save($comment) {
field_attach_update
(
'comment'
,
$comment
);
// Allow modules to respond to the updating of a comment.
module_invoke_all
(
'comment_update'
,
$comment
);
entity_invoke
(
'update'
,
'comment'
,
$comment
);
// Add an entry to the watchdog log.
watchdog
(
'content'
,
'Comment: updated %subject.'
,
array
(
'%subject'
=>
$comment
->
subject
),
WATCHDOG_NOTICE
,
l
(
t
(
'view'
),
'comment/'
.
$comment
->
cid
,
array
(
'fragment'
=>
'comment-'
.
$comment
->
cid
)));
}
...
...
@@ -1453,6 +1454,7 @@ function comment_save($comment) {
// Tell the other modules a new comment has been submitted.
module_invoke_all
(
'comment_insert'
,
$comment
);
entity_invoke
(
'insert'
,
'comment'
,
$comment
);
// Add an entry to the watchdog log.
watchdog
(
'content'
,
'Comment: added %subject.'
,
array
(
'%subject'
=>
$comment
->
subject
),
WATCHDOG_NOTICE
,
l
(
t
(
'view'
),
'comment/'
.
$comment
->
cid
,
array
(
'fragment'
=>
'comment-'
.
$comment
->
cid
)));
}
...
...
modules/node/node.module
View file @
02c1eeee
...
...
@@ -1049,6 +1049,7 @@ function node_save($node) {
$function
(
'node'
,
$node
);
module_invoke_all
(
'node_'
.
$op
,
$node
);
entity_invoke
(
$op
,
'node'
,
$node
);
// Update the node access table for this node.
node_access_acquire_grants
(
$node
);
...
...
modules/system/system.api.php
View file @
02c1eeee
...
...
@@ -220,6 +220,32 @@ function hook_entity_load($entities, $type) {
}
}
/**
* Act on entities when inserted.
*
* Generic insert hook called for all entity types via entity_invoke().
*
* @param $entity
* The entity object.
* @param $type
* The type of entity being inserted (i.e. node, user, comment).
*/
function
hook_entity_insert
(
$entity
,
$type
)
{
}
/**
* Act on entities when updated.
*
* Generic update hook called for all entity types via entity_invoke().
*
* @param $entity
* The entity object.
* @param $type
* The type of entity being updated (i.e. node, user, comment).
*/
function
hook_entity_update
(
$entity
,
$type
)
{
}
/**
* Define administrative paths.
*
...
...
modules/taxonomy/taxonomy.module
View file @
02c1eeee
...
...
@@ -338,12 +338,14 @@ function taxonomy_vocabulary_save($vocabulary) {
if
(
!
empty
(
$vocabulary
->
vid
)
&&
!
empty
(
$vocabulary
->
name
))
{
$status
=
drupal_write_record
(
'taxonomy_vocabulary'
,
$vocabulary
,
'vid'
);
module_invoke_all
(
'taxonomy_vocabulary_update'
,
$vocabulary
);
entity_invoke
(
'update'
,
'taxonomy_vocabulary'
,
$vocabulary
);
}
elseif
(
empty
(
$vocabulary
->
vid
))
{
$status
=
drupal_write_record
(
'taxonomy_vocabulary'
,
$vocabulary
);
field_attach_create_bundle
(
'taxonomy_term'
,
$vocabulary
->
machine_name
);
taxonomy_vocabulary_create_field
(
$vocabulary
);
module_invoke_all
(
'taxonomy_vocabulary_insert'
,
$vocabulary
);
entity_invoke
(
'insert'
,
'taxonomy_vocabulary'
,
$vocabulary
);
}
cache_clear_all
();
...
...
@@ -470,11 +472,13 @@ function taxonomy_term_save($term) {
$status
=
drupal_write_record
(
'taxonomy_term_data'
,
$term
,
'tid'
);
field_attach_update
(
'taxonomy_term'
,
$term
);
module_invoke_all
(
'taxonomy_term_update'
,
$term
);
entity_invoke
(
'update'
,
'taxonomy_term'
,
$term
);
}
else
{
$status
=
drupal_write_record
(
'taxonomy_term_data'
,
$term
);
field_attach_insert
(
'taxonomy_term'
,
$term
);
module_invoke_all
(
'taxonomy_term_insert'
,
$term
);
entity_invoke
(
'insert'
,
'taxonomy_term'
,
$term
);
}
db_delete
(
'taxonomy_term_hierarchy'
)
...
...
modules/user/user.module
View file @
02c1eeee
...
...
@@ -483,6 +483,7 @@ function user_save($account, $edit = array(), $category = 'account') {
}
user_module_invoke
(
'update'
,
$edit
,
$user
,
$category
);
entity_invoke
(
'update'
,
'user'
,
$user
);
}
else
{
// Allow 'uid' to be set by the caller. There is no danger of writing an
...
...
@@ -515,6 +516,7 @@ function user_save($account, $edit = array(), $category = 'account') {
field_attach_insert
(
'user'
,
$object
);
user_module_invoke
(
'insert'
,
$edit
,
$user
,
$category
);
entity_invoke
(
'insert'
,
'user'
,
$user
);
// Note, we wait with saving the data column to prevent module-handled
// fields from being saved there.
...
...
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