Mercurial > defr > drupal > popups_reference
diff popups_reference.module @ 5:e1318a313b1d
Popups: AddnReference 1.3
author | Franck Deroche <franck@defr.org> |
---|---|
date | Thu, 19 Mar 2009 11:34:01 +0100 |
parents | 56772e0a00ae |
children | 990f71344a66 |
line wrap: on
line diff
--- a/popups_reference.module Wed Jan 21 11:19:01 2009 +0100 +++ b/popups_reference.module Thu Mar 19 11:34:01 2009 +0100 @@ -1,5 +1,5 @@ <?php -// $Id: popups_reference.module,v 1.1.2.6 2009/01/18 22:40:33 starbow Exp $ +// $Id: popups_reference.module,v 1.1.2.12 2009/03/07 06:54:25 starbow Exp $ /** * @file @@ -13,7 +13,7 @@ * Modifies the nodereference setting form and the basic node form. */ function popups_reference_form_alter(&$form, $form_state, $form_id) { - if ($form_id == 'content_field_edit_form') { + if ($form_id == 'content_field_edit_form' && $form['#field']['type'] == 'nodereference') { // Add a checkbox to the nodereference settings page. $field_name = $form['#field']['field_name']; $form['field']['show_add_link'] = array( @@ -57,7 +57,8 @@ if ($op == 'insert') { $five = time()+300; // 5 minutes in the future. setcookie("PopupRefNid", $node->nid, $five, '/'); - setcookie("PopupRefTitle", $node->title, $five, '/'); +// setcookie("PopupRefTitle", $node->title, $five, '/'); + setrawcookie("PopupRefTitle", rawurlencode($node->title), $five, '/'); } } @@ -85,8 +86,8 @@ $fields[$field_name]['type'] == 'nodereference' && variable_get('popups_reference_show_add_link_'. $field_name, TRUE)) { $type = $form['type']['#value']; - $field = content_fields($field_name, $form['type']['#value']); - + $field = content_fields($field_name, $type); + $wrapper_id = 'popups-reference-' . _popups_reference_counter(); $links = _popups_reference_links($field, $type, $wrapper_id, $field['widget']['type']); if ($links) { @@ -105,15 +106,15 @@ * @param $field * @param $src_type - the type of base node. * @param $wrapper_id - id for the wrapper around the node reference. - * @param $type - the type of the node being referenced. + * @param $type - the type of widget. * @return Array of html links. */ -function _popups_reference_links($field, $src_type, $wrapper_id, $type) { - if ($type == 'nodereference_select' || $type == 'nodereference_buttons') { +function _popups_reference_links($field, $src_type, $wrapper_id, $widget_type) { + if ($widget_type == 'nodereference_select' || $widget_type == 'nodereference_buttons') { // Target the wrapper for replacing. popups_add_popups(array('a.'.$wrapper_id=>array('targetSelectors'=>array('#'.$wrapper_id)))); } - else if ($type == 'nodereference_autocomplete') { + else if ($widget_type == 'nodereference_autocomplete') { // Don't replace the autocomplete when done. popups_add_popups(array('a.'.$wrapper_id=>array('noUpdate'=>TRUE))); } @@ -130,10 +131,12 @@ $links = array(); $all_types = node_get_types(); foreach ($field['referenceable_types'] as $add_type => $value) { - if (!empty($value) && user_access("create $add_type content")) { + if (!empty($value) && (user_access("create $add_type content") || user_access('administer nodes'))) { + //if (!empty($value) && user_access("create $add_type content")) { drupal_add_js(drupal_get_path('module', 'popups_reference') .'/popups_reference.js'); $path = 'node/add/' . str_replace('_', '-', $add_type); - $links[] = l("Add $add_type", $path, $options); + $name = $all_types[$add_type]->name; + $links[] = l("Add $name", $path, $options); } } return $links;