Issue #1322108: Invalid argument supplied for foreach() in i18n_forum_menu_local_task...
[project/i18n.git] / i18n_forum / i18n_forum.module
1 <?php
2
3 /**
4 * @file
5 * i18n forum module
6 *
7 * Internationalization (i18n) package.
8 */
9
10 /**
11 * Implements hook_help().
12 */
13 function i18n_forum_help($path, $arg) {
14 if ($path == 'admin/structure/forum') {
15 $vid = variable_get('forum_nav_vocabulary', 0);
16 $vocabulary = taxonomy_vocabulary_load($vid);
17 $name = $vocabulary->machine_name;
18 return t('To translate the forum, <a href="@edit">edit and make it translatable</a>, then <a href="@translate">translate the forum</a> and <a href="@list">its containers and sub-forums</a> on the taxonomy administration page.', array('@edit' => url('admin/structure/taxonomy/' . $name . '/edit'), '@translate' => url('admin/structure/taxonomy/' . $name . '/translate'), '@list' => url('admin/structure/taxonomy/' . $name . '/list')));
19 }
20 }
21
22 /**
23 * Implements hook_menu_local_tasks_alter().
24 */
25 function i18n_forum_menu_local_tasks_alter(&$data, $router_item, $root_path) {
26 // Translate link to 'node/add/forum' on 'forum' sub-pages.
27 if ($root_path == 'forum' || $root_path == 'forum/%') {
28 $tid = (isset($router_item['page_arguments'][0]) ? $router_item['page_arguments'][0]->tid : 0);
29 $forum_term = forum_forum_load($tid);
30 if ($forum_term) {
31 // Loop through all bundles for forum taxonomy vocabulary field.
32 $vid = variable_get('forum_nav_vocabulary', 0);
33 if ($vid && ($vocabulary = taxonomy_vocabulary_load($vid)) && ($field = field_info_field('taxonomy_' . $vocabulary->machine_name))) {
34 foreach ($field['bundles']['node'] as $type) {
35 if (isset($data['actions']['output'][$type])) {
36 $data['actions']['output'][$type]['#link']['title'] = t('Add new @node_type', array('@node_type' => i18n_node_type_name($type, node_type_get_name($type))));
37 }
38 }
39 }
40 }
41 }
42 }
43
44 /**
45 * Implements hook_form_FORM_ID_alter()
46 */
47 function i18n_forum_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) {
48 $vid = variable_get('forum_nav_vocabulary', 0);
49 if ($vid && !isset($form_state['confirm_delete']) && isset($form['vid']) && $form['vid']['#value'] == $vid) {
50 // Only two options for this vocabulary
51 $replacements = array(
52 '@item_name_multiple' => t('forum containers'),
53 '@item_name_multiple_capitalized' => t('Forum containers'),
54 );
55 $form['i18n_translation']['i18n_mode']['#options'] = i18n_translation_options_list($replacements, array(I18N_MODE_LOCALIZE, I18N_MODE_TRANSLATE));
56 }
57 }
58
59 /**
60 * Implements hook_node_view().
61 *
62 * Localize breadcrumb for forum nodes.
63 */
64 function i18n_forum_node_view($node, $view_mode, $langcode) {
65 if (_forum_node_check_node_type($node)) {
66 if ($view_mode == 'full' && node_is_page($node)) {
67 $vid = variable_get('forum_nav_vocabulary', 0);
68 $vocabulary = taxonomy_vocabulary_load($vid);
69 // Breadcrumb navigation
70 $breadcrumb[] = l(t('Home'), NULL);
71 $breadcrumb[] = l(i18n_taxonomy_vocabulary_name($vocabulary), 'forum');
72 if ($parents = taxonomy_get_parents_all($node->forum_tid)) {
73 $parents = array_reverse($parents);
74 foreach ($parents as $parent) {
75 $breadcrumb[] = l(i18n_taxonomy_term_name($parent), 'forum/' . $parent->tid);
76 }
77 }
78 drupal_set_breadcrumb($breadcrumb);
79 }
80 }
81 }
82
83 /**
84 * Translate forums list.
85 */
86 function i18n_forum_preprocess_forum_list(&$variables) {
87 $vid = variable_get('forum_nav_vocabulary', 0);
88 if (i18n_taxonomy_vocabulary_mode($vid)) {
89 foreach ($variables['forums'] as $id => $forum) {
90 $variables['forums'][$id]->description = i18n_string('taxonomy:term:'. $forum->tid .':description', $forum->description);
91 $variables['forums'][$id]->name = i18n_string('taxonomy:term:'. $forum->tid .':name', $forum->name);
92 }
93 }
94 }
95
96
97 /**
98 * Translate forum page.
99 */
100 function i18n_forum_preprocess_forums(&$variables) {
101 $vid = variable_get('forum_nav_vocabulary', 0);
102 if (i18n_taxonomy_vocabulary_mode($vid)) {
103 if (isset($variables['links']['forum'])) {
104 $variables['links']['forum']['title'] = i18n_string('nodetype:type:forum:post_button', 'Post new Forum topic');
105 }
106 // This one is from advanced forum, http://drupal.org/project/advanced_forum
107 if (!empty($variables['forum_description'])) {
108 $variables['forum_description'] = i18n_string('taxonomy:term:'. $variables['tid'] .':description', $variables['forum_description']);
109 }
110 $vocabulary = taxonomy_vocabulary_load($vid);
111 // Translate breadrumb and page title.
112 $title = $vocabulary_name = !empty($vocabulary->name) ? i18n_taxonomy_vocabulary_name($vocabulary) : '';
113 $breadcrumb[] = l(t('Home'), NULL);
114 if ($variables['tid']) {
115 $breadcrumb[] = l($vocabulary_name, 'forum');
116 }
117 if ($variables['parents']) {
118 $variables['parents'] = array_reverse($variables['parents']);
119 foreach ($variables['parents'] as $p) {
120 if ($p->tid == $variables['tid']) {
121 $title = i18n_taxonomy_term_name($p);
122 }
123 else {
124 $breadcrumb[] = l(i18n_taxonomy_term_name($p), 'forum/' . $p->tid);
125 }
126 }
127 }
128 drupal_set_breadcrumb($breadcrumb);
129 drupal_set_title($title);
130 }
131 }