tmgmt_demo.install 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @file
  4. * Installation hooks for tmgmt_demo module.
  5. */
  6. /**
  7. * Implements hook_install().
  8. */
  9. function tmgmt_demo_install() {
  10. include_once DRUPAL_ROOT . '/includes/locale.inc';
  11. // Add German to the language list.
  12. if (!array_key_exists('de', language_list())) {
  13. locale_add_language('de');
  14. }
  15. // Add content type 'translatable'.
  16. if (!array_key_exists('translatable', node_type_get_names())) {
  17. $type = array(
  18. 'type' => 'translatable',
  19. 'name' => 'Translation Demo Type',
  20. 'base' => 'node_content',
  21. 'custom' => 1,
  22. 'modified' => 1,
  23. 'locked' => 0,
  24. );
  25. $type = node_type_set_defaults($type);
  26. node_type_save($type);
  27. node_add_body_field($type);
  28. variable_set('language_content_type_translatable', TRUE);
  29. variable_set('comment_translatable', '0');
  30. }
  31. // Add language skills to the admin user.
  32. $user = user_load(1);
  33. $edit = array(
  34. 'tmgmt_translation_skills' => array(
  35. 'und' => array(
  36. 0 => array(
  37. 'language_from' => 'de',
  38. 'language_to' => 'en',
  39. ),
  40. 1 => array(
  41. 'language_from' => 'en',
  42. 'language_to' => 'de',
  43. ),
  44. ),
  45. ),
  46. );
  47. user_save($user, $edit);
  48. // Add demo content.
  49. $node = new stdClass();
  50. $node->title = 'Second node';
  51. $node->type = 'translatable';
  52. node_object_prepare($node);
  53. $node->language = 'en';
  54. $node->body[LANGUAGE_NONE][0]['value'] = 'Have another try. This text can be
  55. translated as well';
  56. $node->uid = $user->uid;
  57. node_save($node);
  58. $node = new stdClass();
  59. $node->title = 'First node';
  60. $node->type = 'translatable';
  61. node_object_prepare($node);
  62. $node->language = 'en';
  63. $node->body[LANGUAGE_NONE][0]['value'] = 'This text can be translated with TMGMT.
  64. Use the "translate" Tab and choose "Request Translation" to get started';
  65. $node->uid = $user->uid;
  66. node_save($node);
  67. }
  68. /**
  69. * Implements hook_uninstall().
  70. */
  71. function tmgmt_demo_uninstall() {
  72. // Remove the content type created by the demo module.
  73. if (array_key_exists('translatable', node_type_get_names())) {
  74. node_type_delete('translatable');
  75. variable_del('node_preview_translatable');
  76. node_types_rebuild();
  77. menu_rebuild();
  78. }
  79. }