'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']) && $form['type']['#value'] .'_node_form' == $form_id) || variable_get('popups_reference_show_add_link_'. current(array_keys($form)), FALSE) == TRUE) { // Add the "Add New: Node Type" links. $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, $form['type']['#value']); } } else { popups_reference_alter_item($form, $key, $item, $fields,$form['type']['#value']); } } } } } /** * 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. ' [nid:'. $node->nid .']'), $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']); } function popups_reference_original_url($in_url='') { static $url; if ($in_url) $url = $in_url; return $url; } function popups_reference_popups_add_popups_settings_alter(&$settings){ if (strpos($settings['popups']['originalPath'],'content/js_add_more')!==false && popups_reference_original_url()) $settings['popups']['originalPath'] = popups_reference_original_url(); } /** * 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, $type) { $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)) { $field = content_fields($field_name, $type); if (!$type) { $type = $form[$field_name][0]['#type_name']; } // we may have multiple fields in case of 'unlimited' foreach ($form[$field_name] as $key => $value) { if (is_numeric($key)) { // add link $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[$field_name][$key]['#prefix'] .= '