| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: node_edit_form.inc,v 1.10.2.7 2010/07/20 20:49:21 merlinofchaos Exp $ 3 4 /** 5 * @file 6 * 7 * Plugin to provide a node_edit_form context 8 */ 9 10 /** 11 * Plugins are described by creating a $plugin array which will be used 12 * by the system that includes this file. 13 */ 14 $plugin = array( 15 'title' => t("Node edit form"), 16 'description' => t('A node edit form.'), 17 'context' => 'ctools_context_create_node_edit_form', 18 'settings form' => 'ctools_context_node_edit_form_settings_form', 19 'settings form validate' => 'ctools_context_node_edit_form_settings_form_validate', 20 'settings form validate' => 'ctools_context_node_edit_form_settings_form_validate', 21 'settings form submit' => 'ctools_context_node_edit_form_settings_form_submit', 22 'defaults' => array('nid' => ''), 23 'keyword' => 'node_edit', 24 'context name' => 'node_edit_form', 25 'convert list' => 'ctools_context_node_edit_convert_list', 26 'convert' => 'ctools_context_node_edit_convert', 27 'placeholder form' => array( 28 '#type' => 'textfield', 29 '#description' => t('Enter the node ID of a node for this argument:'), 30 ), 31 ); 32 33 /** 34 * It's important to remember that $conf is optional here, because contexts 35 * are not always created from the UI. 36 */ 37 function ctools_context_create_node_edit_form($empty, $node = NULL, $conf = FALSE) { 38 static $created; 39 $context = new ctools_context(array('form', 'node_edit', 'node_form', 'node', 'node_edit_form')); 40 $context->plugin = 'node_edit_form'; 41 42 if ($empty || (isset($created) && $created)) { 43 return $context; 44 } 45 $created = TRUE; 46 47 if ($conf) { 48 // In this case, $node is actually our $conf array. 49 $nid = is_array($node) && isset($node['nid']) ? $node['nid'] : (is_object($node) ? $node->nid : 0); 50 51 if (module_exists('translation')) { 52 if ($translation = module_invoke('translation', 'node_nid', $nid, $GLOBALS['language']->language)) { 53 $nid = $translation; 54 $reload = TRUE; 55 } 56 } 57 58 if (is_array($node) || !empty($reload)) { 59 $node = node_load($nid); 60 } 61 } 62 63 if (!empty($node)) { 64 ctools_include('form'); 65 $form_id = $node->type . '_node_form'; 66 67 $form_state = array('want form' => TRUE, 'args' => array($node)); 68 69 $file = drupal_get_path('module', 'node') . '/node.pages.inc'; 70 include_once './' . $file; 71 // This piece of information can let other modules know that more files 72 // need to be included if this form is loaded from cache: 73 $form_state['form_load_files'] = array($file); 74 75 $form = ctools_build_form($form_id, $form_state); 76 77 // Fill in the 'node' portion of the context 78 $context->data = $node; 79 $context->title = $node->title; 80 $context->argument = isset($node->nid) ? $node->nid : $node->type; 81 82 $context->form = $form; 83 $context->form_state = &$form_state; 84 $context->form_id = $form_id; 85 $context->form_title = $node->title; 86 $context->node_type = $node->type; 87 $context->restrictions['type'] = array($node->type); 88 return $context; 89 } 90 } 91 92 function ctools_context_node_edit_form_settings_form($conf) { 93 if (empty($conf)) { 94 $conf = array( 95 'nid' => '', 96 ); 97 } 98 99 $form['node'] = array( 100 '#prefix' => '<div class="no-float">', 101 '#suffix' => '</div>', 102 '#title' => t('Enter the title or NID of a node'), 103 '#type' => 'textfield', 104 '#maxlength' => 512, 105 '#autocomplete_path' => 'ctools/autocomplete/node', 106 '#weight' => -10, 107 ); 108 109 if (!empty($conf['nid'])) { 110 $info = db_fetch_object(db_query("SELECT * FROM {node} n WHERE n.nid = %d", $conf['nid'])); 111 if ($info) { 112 $link = l(t("'%title' [node id %nid]", array('%title' => $info->title, '%nid' => $info->nid)), "node/$info->nid", array('attributes' => array('target' => '_blank', 'title' => t('Open in new window')), 'html' => TRUE)); 113 $form['node']['#description'] = t('Currently set to !link', array('!link' => $link)); 114 } 115 } 116 117 $form['nid'] = array( 118 '#type' => 'value', 119 '#value' => $conf['nid'], 120 ); 121 122 $form['set_identifier'] = array( 123 '#type' => 'checkbox', 124 '#default_value' => FALSE, 125 '#title' => t('Reset identifier to node title'), 126 '#description' => t('If checked, the identifier will be reset to the node title of the selected node.'), 127 ); 128 129 return $form; 130 } 131 132 /** 133 * Validate a node. 134 */ 135 function ctools_context_node_edit_form_settings_form_validate($form, &$form_values, &$form_state) { 136 // Validate the autocomplete 137 if (empty($form_values['nid']) && empty($form_values['node'])) { 138 form_error($form['node'], t('You must select a node.')); 139 return; 140 } 141 142 if (empty($form_values['node'])) { 143 return; 144 } 145 146 $nid = $form_values['node']; 147 $preg_matches = array(); 148 $match = preg_match('/\[nid: (\d+)\]/', $nid, $preg_matches); 149 if (!$match) { 150 $match = preg_match('/^nid: (\d+)/', $nid, $preg_matches); 151 } 152 153 if ($match) { 154 $nid = $preg_matches[1]; 155 } 156 if (is_numeric($nid)) { 157 $node = db_fetch_object(db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.nid = %d"), $nid)); 158 } 159 else { 160 $node = db_fetch_object(db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE LOWER(n.title) = LOWER('%s')"), $nid)); 161 } 162 163 if (!$node) { 164 form_error($form['node'], t('Invalid node selected.')); 165 } 166 else { 167 form_set_value($form['nid'], $node->nid, $form_state); 168 // $form_values['nid'] = $node->nid; 169 } 170 } 171 172 function ctools_context_node_edit_form_settings_form_submit($form, &$form_values, &$form_state) { 173 if ($form_values['set_identifier']) { 174 $node = node_load($form_values['nid']); 175 $form_state['values']['context']['identifier'] = $node->title; 176 } 177 178 // Don't let this be stored. 179 unset($form_values['set_identifier']); 180 } 181 182 /** 183 * Provide a list of ways that this context can be converted to a string. 184 */ 185 function ctools_context_node_edit_convert_list() { 186 // Pass through to the "node" context convert list. 187 $plugin = ctools_get_context('node'); 188 return ctools_context_node_convert_list(); 189 } 190 191 /** 192 * Convert a context into a string. 193 */ 194 function ctools_context_node_edit_convert($context, $type) { 195 // Pass through to the "node" context convert list. 196 $plugin = ctools_get_context('node'); 197 return ctools_context_node_convert($context, $type); 198 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |