On this page
function hook_entity_insert
hook_entity_insert($entity, $type)
Act on entities when inserted.
Parameters
$entity: The entity object.
$type: The type of entity being inserted (i.e. node, user, comment).
Related topics
File
- modules/system/system.api.php, line 328
- Hooks provided by Drupal core and the System module.
Code
function hook_entity_insert($entity, $type) {
// Insert the new entity into a fictional table of all entities.
$info = entity_get_info($type);
list($id) = entity_extract_ids($type, $entity);
db_insert('example_entity')
->fields(array(
'type' => $type,
'id' => $id,
'created' => REQUEST_TIME,
'updated' => REQUEST_TIME,
))
->execute();
}
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_entity_insert/7.x