comparison noderef_view.module @ 2:25a0c2fcbcfb

Don't wrap the field in a div, it may cause problems. Instead, we just go back in the DOM 'till we find the div holding the real data. It's not really all that good, but, it seems to do the job.
author Franck Deroche <franck@defr.org>
date Fri, 23 Jan 2009 18:57:45 +0100
parents 71a07534c366
children 9372c6448311
comparison
equal deleted inserted replaced
1:71a07534c366 2:25a0c2fcbcfb
108 * @return 108 * @return
109 * TRUE si l'element a été modifié, FALSE sinon. 109 * TRUE si l'element a été modifié, FALSE sinon.
110 */ 110 */
111 function noderef_view_alter_item(&$form, $key, $field) { 111 function noderef_view_alter_item(&$form, $key, $field) {
112 if (is_array($field) && $field['type'] == 'nodereference') { 112 if (is_array($field) && $field['type'] == 'nodereference') {
113 list($link, $id) = _noderef_view_get_link($field); 113 $link = _noderef_view_get_link($field);
114 if (!empty($link)) { 114 if (!empty($link)) {
115 $form[$key]['#prefix'] .= "<div id='noderef_view_link_{$id}'>"; 115 $suffix = $link;
116 $form[$key]['#suffix'] = $link .'</div>'. $form[$key]['#suffix']; 116 if (isset($form[$key]['#suffix'])) {
117 $form[$key]['#suffix'] = $suffix . $form[$key]['#suffix'];
118 }
119 else {
120 $form[$key]['#suffix'] = $suffix;
121 }
117 return TRUE; 122 return TRUE;
118 } 123 }
119 } 124 }
120 return FALSE; 125 return FALSE;
121 } 126 }
126 * @return 131 * @return
127 * - Un lien vers la vue si une vue est associée 132 * - Un lien vers la vue si une vue est associée
128 * - Une chaine vide sinon 133 * - Une chaine vide sinon
129 */ 134 */
130 function _noderef_view_get_link($field) { 135 function _noderef_view_get_link($field) {
131 static $id = 0;
132 $path = ''; 136 $path = '';
133 // Check if there's a view associated with this field 137 // Check if there's a view associated with this field
134 if (isset($field['advanced_view']) && $field['advanced_view'] !== '--') { 138 if (isset($field['advanced_view']) && $field['advanced_view'] !== '--') {
135 $view = views_get_view($field['advanced_view']); 139 $view = views_get_view($field['advanced_view']);
136 // Try to find a path for this view, looking at the displays 140 // Try to find a path for this view, looking at the displays
137 $path = ''; 141 $path = '';
138 foreach($view->display as $display) { 142 foreach($view->display as $display) {
139 if (is_array($display->display_options) 143 if (is_array($display->display_options)
140 && isset($display->display_options['path'])) { 144 && isset($display->display_options['path'])) {
141 $path = $display->display_options['path']; 145 $path = $display->display_options['path'];
142 break; 146 break;
143 } 147 }
144 } 148 }
145 } 149 }
146 // If we found a view with a suitable display, then link to it 150 // If we found a view with a suitable display, then link to it
147 if (!empty($path)) { 151 if (!empty($path)) {
148 $id++;
149 popups_add_popups(); 152 popups_add_popups();
150 $options = array( 153 $options = array(
151 'attributes' => array( 154 'attributes' => array('class' => 'popups noderef_view_link'),
152 'class' => 'popups noderef_view_link',
153 'rel' => 'noderef_view_link_'. $id),
154 'query' => array('destination' => 'node') 155 'query' => array('destination' => 'node')
155 ); 156 );
156 $path = l(t('Search'), $path, $options); 157 $path = l(t('Search'), $path, $options);
157 } 158 }
158 return array($path, $id); 159 return $path;
159 } 160 }
160 161