'checkbox', '#default_value' => variable_get('popups_reference_show_add_link_'. $field_name, TRUE), '#title' => t('Show the "Add New: Node Type" Popup links'), '#description' => t("Activate Popups:Add and Reference behavior for this reference.") ); $form['#submit'][] = '_popups_reference_manage_fields_submit'; } elseif (isset($form['type'])) { // Add the "Add New: Node Type" links. $node = $form['#node']; if ($form['type']['#value'] .'_node_form' == $form_id) { $fields = content_fields(); foreach ($form as $key => $item) { if (is_array($item)) { $type = $item['#type']; if ($type == 'fieldset') { // Loop through all the subitems. foreach ($form[$key] as $subkey => $subitem) { popups_reference_alter_item($form[$key], $subkey, $subitem, $fields); } } else { popups_reference_alter_item($form, $key, $item, $fields); } } } } } } /** * Implementation of hook_nodeapi(). * Add cookies with node info when a new node is created. * These cookies will be found by the popups_reference behavior and used * to select the newly created node in the reference widget. */ function popups_reference_nodeapi($node, $op) { if ($op == 'insert') { $five = time()+300; // 5 minutes in the future. setcookie("PopupRefNid", $node->nid, $five, '/'); setrawcookie("PopupRefTitle", rawurlencode($node->title), $five, '/'); } } /** * Submit added to the the nodereference settings form. * Set a variable for each nodereference field. */ function _popups_reference_manage_fields_submit($form, &$form_state) { $field_name = $form['#field']['field_name']; variable_set('popups_reference_show_add_link_'. $field_name, $form_state['values']['show_add_link']); } /** * Run on every element in the basic node form. * Wrap the enabled nodereference fields, and add the popup links. * * @param $form - the form (or fieldgroup). * @param $key - form element name. * @param $item - the form element array. * @param $fields - all fields info. */ function popups_reference_alter_item(&$form, $key, $item, $fields) { $field_name = strstr($key, 'field_'); // Check if $key starts with 'field_'; if (isset($fields[$field_name]) && $fields[$field_name]['type'] == 'nodereference' && variable_get('popups_reference_show_add_link_'. $field_name, TRUE)) { $type = $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) { // Put the nodereference widget and links in an wrapper. // Makes it easy to find for Ahah targeting, and popups_reference behavior selecting. $form[$key]['#prefix'] = '