diff options
author | Dries Buytaert <dries@buytaert.net> | 2008-10-06 12:55:56 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2008-10-06 12:55:56 +0000 |
commit | 87567f8916b78b2eb8ed279b728a30ce2dce249a (patch) | |
tree | 097b0e936bc5f07cfeb3fcee7823a23a0be76f33 /modules/translation/translation.module | |
parent | 026af5df34694c8ca5c3708f3fe23fd10ec160cb (diff) | |
download | brdo-87567f8916b78b2eb8ed279b728a30ce2dce249a.tar.gz brdo-87567f8916b78b2eb8ed279b728a30ce2dce249a.tar.bz2 |
- Patch #310212 by justinrandell: killed in _node hook, as well as twelve sable tooth tigers.
Diffstat (limited to 'modules/translation/translation.module')
-rw-r--r-- | modules/translation/translation.module | 104 |
1 files changed, 57 insertions, 47 deletions
diff --git a/modules/translation/translation.module b/modules/translation/translation.module index 79d746e6d..c91a556f2 100644 --- a/modules/translation/translation.module +++ b/modules/translation/translation.module @@ -181,65 +181,75 @@ function translation_link($type, $node = NULL, $teaser = FALSE) { } /** - * Implementation of hook_nodeapi(). - * - * Manages translation information for nodes. + * Implementation of hook_nodeapi_prepare(). */ -function translation_nodeapi(&$node, $op, $teaser, $page) { +function translation_nodeapi_prepare(&$node, $teaser, $page) { // Only act if we are dealing with a content type supporting translations. - if (!translation_supported_type($node->type)) { - return; + if (translation_supported_type($node->type)) { + if (empty($node->nid) && isset($_GET['translation']) && isset($_GET['language']) && + ($source_nid = $_GET['translation']) && ($language = $_GET['language']) && + (user_access('translate content'))) { + // We are translating a node from a source node, so + // load the node to be translated and populate fields. + $node->language = $language; + $node->translation_source = node_load($source_nid); + $node->title = $node->translation_source->title; + $node->body = $node->translation_source->body; + // Let every module add custom translated fields. + node_invoke_nodeapi($node, 'prepare translation'); + } } +} - switch ($op) { - case 'prepare': - if (empty($node->nid) && isset($_GET['translation']) && isset($_GET['language']) && - ($source_nid = $_GET['translation']) && ($language = $_GET['language']) && - (user_access('translate content'))) { - // We are translating a node from a source node, so - // load the node to be translated and populate fields. - $node->language = $language; - $node->translation_source = node_load($source_nid); - $node->title = $node->translation_source->title; - $node->body = $node->translation_source->body; - // Let every module add custom translated fields. - node_invoke_nodeapi($node, 'prepare translation'); +/** + * Implementation of hook_nodeapi_insert(). + */ +function translation_nodeapi_insert(&$node, $teaser, $page) { + // Only act if we are dealing with a content type supporting translations. + if (translation_supported_type($node->type)) { + if (!empty($node->translation_source)) { + if ($node->translation_source->tnid) { + // Add node to existing translation set. + $tnid = $node->translation_source->tnid; } - break; - - case 'insert': - if (!empty($node->translation_source)) { - if ($node->translation_source->tnid) { - // Add node to existing translation set. - $tnid = $node->translation_source->tnid; - } - else { - // Create new translation set, using nid from the source node. - $tnid = $node->translation_source->nid; - db_query("UPDATE {node} SET tnid = %d, translate = %d WHERE nid = %d", $tnid, 0, $node->translation_source->nid); - } - db_query("UPDATE {node} SET tnid = %d, translate = %d WHERE nid = %d", $tnid, 0, $node->nid); + else { + // Create new translation set, using nid from the source node. + $tnid = $node->translation_source->nid; + db_query("UPDATE {node} SET tnid = %d, translate = %d WHERE nid = %d", $tnid, 0, $node->translation_source->nid); } - break; + db_query("UPDATE {node} SET tnid = %d, translate = %d WHERE nid = %d", $tnid, 0, $node->nid); + } + } +} - case 'update': - if (isset($node->translation) && $node->translation && !empty($node->language) && $node->tnid) { - // Update translation information. - db_query("UPDATE {node} SET tnid = %d, translate = %d WHERE nid = %d", $node->tnid, $node->translation['status'], $node->nid); - if (!empty($node->translation['retranslate'])) { - // This is the source node, asking to mark all translations outdated. - db_query("UPDATE {node} SET translate = 1 WHERE tnid = %d AND nid <> %d", $node->tnid, $node->nid); - } +/** + * Implementation of hook_nodeapi_update(). + */ +function translation_nodeapi_update(&$node, $teaser, $page) { + // Only act if we are dealing with a content type supporting translations. + if (translation_supported_type($node->type)) { + if (isset($node->translation) && $node->translation && !empty($node->language) && $node->tnid) { + // Update translation information. + db_query("UPDATE {node} SET tnid = %d, translate = %d WHERE nid = %d", $node->tnid, $node->translation['status'], $node->nid); + if (!empty($node->translation['retranslate'])) { + // This is the source node, asking to mark all translations outdated. + db_query("UPDATE {node} SET translate = 1 WHERE tnid = %d AND nid <> %d", $node->tnid, $node->nid); } - break; - - case 'delete': - translation_remove_from_set($node); - break; + } } } /** + * Implementation of hook_nodeapi_delete(). + */ +function translation_nodeapi_delete(&$node, $teaser, $page) { + // Only act if we are dealing with a content type supporting translations. + if (translation_supported_type($node->type)) { + translation_remove_from_set($node); + } +} + +/** * Remove a node from its translation set (if any) * and update the set accordingly. */ |