is_new = TRUE; // Let other modules do special actions on each field. replicate_clone_fields($clone, $entity_type); // Let other modules do special actions on the global entity. drupal_alter('replicate_entity', $clone, $entity_type, $entity); } return $clone; } /** * Replicate the fields of an entity. * * @param object $entity * The entity for which to clone the fields. * @param string $entity_type * The entity type. */ function replicate_clone_fields(&$entity, $entity_type) { foreach (field_info_fields() as $field_name => $field) { if (isset($entity->$field_name)) { // Here call hook functions. Doesn't use module_invoke because we // want to pass the clone by reference. foreach (module_implements('replicate_field_' . $field['type']) as $module) { $function = $module . '_replicate_field_' . $field['type']; $function($entity, $entity_type, $field_name); } } } } /** * Implements hook_help(). */ function replicate_help($path, $arg) { switch ($path) { case 'admin/help#replicate': // Return a line-break version of the module README.txt. return check_markup(file_get_contents(dirname(__FILE__) . "/README.txt")); } } /** * Implements hook_replicate_entity_ENTITY_TYPE(). */ function replicate_replicate_entity_node(&$entity) { $entity->nid = NULL; $entity->tnid = NULL; $entity->vid = NULL; $entity->created = NULL; $entity->changed = NULL; $entity->path = NULL; $entity->revision_timestamp = NULL; } /** * Implements hook_replicate_entity_ENTITY_TYPE(). */ function replicate_replicate_entity_taxonomy_vocabulary(&$entity) { $entity->vid = NULL; } /** * Implements hook_replicate_entity_ENTITY_TYPE(). */ function replicate_replicate_entity_taxonomy_term(&$entity) { $entity->tid = NULL; } /** * Implements hook_replicate_entity_ENTITY_TYPE(). */ function replicate_replicate_entity_user(&$entity) { $entity->uid = NULL; } /** * Implements hook_replicate_entity_ENTITY_TYPE(). */ function replicate_replicate_entity_comment(&$entity) { $entity->cid = NULL; $entity->created = NULL; $entity->changed = NULL; } /** * Implements hook_replicate_entity_ENTITY_TYPE(). */ function replicate_replicate_entity_file(&$entity) { $entity->fid = NULL; }