i18n_menu.install 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * @file
  4. * Installation file for i18nmenu module.
  5. */
  6. /**
  7. * Implements hook_install().
  8. */
  9. function i18n_menu_install() {
  10. // Set module weight for it to run after core modules, but before views.
  11. db_query("UPDATE {system} SET weight = 5 WHERE name = 'i18n_menu' AND type = 'module'");
  12. module_load_install('i18n');
  13. i18n_install_create_fields('menu_links', array('language', 'i18n_tsid'));
  14. i18n_install_create_fields('menu_custom', array('language', 'i18n_mode'));
  15. // If updating from D6, module changed name
  16. if (variable_get('i18n_drupal6_update')) {
  17. i18n_menu_update_7000();
  18. }
  19. }
  20. /**
  21. * Implements hook_uninstall().
  22. */
  23. function i18n_menu_uninstall() {
  24. db_drop_field('menu_links', 'language');
  25. db_drop_field('menu_links', 'i18n_tsid');
  26. db_drop_field('menu_custom', 'language');
  27. db_drop_field('menu_custom', 'i18n_mode');
  28. }
  29. /**
  30. * Implements hook_schema_alter().
  31. */
  32. function i18n_menu_schema_alter(&$schema) {
  33. $schema['menu_links']['fields']['language'] = array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => LANGUAGE_NONE);
  34. $schema['menu_links']['fields']['i18n_tsid'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0);
  35. $schema['menu_custom']['fields']['language'] = array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => LANGUAGE_NONE);
  36. $schema['menu_custom']['fields']['i18n_mode'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0);
  37. }
  38. /**
  39. * Update menu items language field from Drupal 6
  40. */
  41. function i18n_menu_update_7000() {
  42. // @todo
  43. }
  44. /**
  45. * Set alter property for menu items with language.
  46. */
  47. function i18n_menu_update_7001() {
  48. // Compile a list of menus with i18n options.
  49. $i18n_menus = array_filter(menu_get_names(), 'i18n_menu_mode');
  50. if ($i18n_menus) {
  51. $query = db_select('menu_links', 'm')
  52. ->fields('m')
  53. ->condition('menu_name', $i18n_menus);
  54. foreach ($query->execute()->fetchAllAssoc('mlid', PDO::FETCH_ASSOC) as $mlid => $item) {
  55. $options = unserialize($item['options']);
  56. if (_i18n_menu_link_check_alter($item) && empty($options['alter'])) {
  57. $options['alter'] = TRUE;
  58. db_update('menu_links')
  59. ->condition('mlid', $mlid)
  60. ->fields(array('options' => serialize($options)))
  61. ->execute();
  62. }
  63. }
  64. }
  65. }