| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id$ 3 4 /** 5 * @file 6 * 7 * main file, only one hook_form_alter 8 * to change several settings 9 * 10 * TODO: Divide everything in individual functions 11 * for easier maintainance 12 */ 13 14 /** 15 * Implementation of hook_form_alter() 16 * 17 * Some code taken from http://drupal.org/node/225955 18 */ 19 function nodeformsettings_form_alter(&$form, $form_state, $form_id) { 20 //$form['form_array'] = array('#value' => '<pre>'. print_r($form, 1) . '</pre>'); 21 if ($form_id == 'node_type_form') { 22 23 // To set height of body textarea (1 for textfield) 24 $form['submission']['submission_body_rows'] = array( 25 '#title' => t("Body field size"), 26 '#type' => 'textfield', 27 '#size' => 5, 28 '#default_value' => variable_get('submission_body_rows_'. $form['#node_type']->type, '20'), 29 '#description' => t("Amount of rows to determine the height of the body field. Enter 1 to get a textfield instead of a textarea.") 30 ); 31 32 // Option to hide the node title 33 $form['workflow']['hidetitle'] = array( 34 '#type' => 'radios', 35 '#title' => t("Hide the node title"), 36 '#options' => array(0 => t("Show the node title"), 1 => t("Hide the node title")), 37 '#description' => t("This setting controlls wether or not the node title is displayed when viewing the node. The title field is going to appear on the 'create node' form regardless of these settings. To avoid its display and automatically create nodetitles ou can use the module !url", array('!url' => l(t('Automatic Nodetitles'), 'http://drupal.org/project/auto_nodetitle', $options = array('attributes' => array('target' => '_blank'))))), 38 '#default_value' => variable_get('hidetitle_'. $form['#node_type']->type, 0), 39 ); 40 41 // Comments form Settings 42 if (isset($form['identity']['type'])) { 43 $form['comment']['commentformsettings_author'] = array( 44 '#type' => 'radios', 45 '#title' => t("Comment author name"), 46 '#options' => array(1 => t("Disabled"),0 => t("Enabled")), 47 '#default_value' => variable_get('commentformsettings_author_'. $form['#node_type']->type, 0), 48 ); 49 $form['comment']['commentformsettings_preview'] = array( 50 '#type' => 'radios', 51 '#title' => t("Preview button"), 52 '#options' => array(1 => t("Disabled"),0 => t("Enabled")), 53 '#default_value' => variable_get('commentformsettings_preview_'. $form['#node_type']->type, 0), 54 '#description' => t("Important: If you set the Preview button to <em>Required</em> you need to show the button here"), 55 ); 56 $form['comment']['commentformsettings_title'] = array( 57 '#type' => 'radios', 58 '#title' => t("Hide the word 'Comment'"), 59 '#options' => array(1 => t("Disabled"),0 => t("Enabled")), 60 '#default_value' => variable_get('commentformsettings_title_'. $form['#node_type']->type, 0), 61 ); 62 $form['comment']['commentformsettings_inputformat'] = array( 63 '#type' => 'radios', 64 '#title' => t("Input Format Fieldset"), 65 '#options' => array(1 => t("Disabled"),0 => t("Enabled")), 66 '#default_value' => variable_get('commentformsettings_inputformat_'. $form['#node_type']->type, 0), 67 ); 68 $form['comment']['commentformsettings_size'] = array( 69 '#type' => 'textfield', 70 '#title' => t("Size of the comment textarea"), 71 '#default_value' => variable_get('commentformsettings_size_'. $form['#node_type']->type, 15), 72 ); 73 $form['comment']['commentformsettings_submit'] = array( 74 '#type' => 'textfield', 75 '#title' => t("Submit button title"), 76 '#default_value' => t(variable_get('commentformsettings_submit_'. $form['#node_type']->type, "Save")), 77 ); 78 79 // Anonymous comments settings 80 $form['comment']['commentformsettings_anonymousname'] = array( 81 '#type' => 'radios', 82 '#title' => t("Anonymous comment Name field"), 83 '#options' => array(1 => t("Disabled"),0 => t("Enabled")), 84 '#default_value' => variable_get('commentformsettings_anonymousname_'. $form['#node_type']->type, 0), 85 '#description' => t("If disabled, the Comment Form for anonymous users will not show the Name field. You should use this with caution, because you might have comments without knowing who posted them"), 86 ); 87 $form['comment']['commentformsettings_anonymousmail'] = array( 88 '#type' => 'radios', 89 '#title' => t("Anonymous comment E-mail field"), 90 '#options' => array(1 => t("Disabled"),0 => t("Enabled")), 91 '#default_value' => variable_get('commentformsettings_anonymousmail_'. $form['#node_type']->type, 0), 92 '#description' => t("If disabled, the Comment Form for anonymous users will not show the E-mail field."), 93 ); 94 $form['comment']['commentformsettings_anonymoushomepage'] = array( 95 '#type' => 'radios', 96 '#title' => t("Anonymous comment Homepage field"), 97 '#options' => array(1 => t("Disabled"),0 => t("Enabled")), 98 '#default_value' => variable_get('commentformsettings_anonymoushomepage_'. $form['#node_type']->type, 0), 99 '#description' => t("If disabled, the Comment Form for anonymous users will not show the Homepage field."), 100 ); 101 } 102 103 // Node Form Settings 104 $form['nodeformsettings'] = array( 105 '#type' => 'fieldset', 106 '#title' => t("Node form settings"), 107 '#collapsible' => TRUE, 108 '#collapsed' => TRUE, 109 '#group' => 'nodeformsettings', 110 ); 111 $form['nodeformsettings']['nodeformsettings_splitsummary'] = array( 112 '#title' => t("Split Summary Button"), 113 '#type' => 'radios', 114 '#options' => array(1 => t("Disabled"),0 => t("Enabled")), 115 '#default_value' => variable_get('nodeformsettings_splitsummary_'. $form['#node_type']->type, 0), 116 ); 117 $form['nodeformsettings']['nodeformsettings_inputformat'] = array( 118 '#title' => t("Input Form Fieldset"), 119 '#type' => 'radios', 120 '#options' => array(1 => t("Disabled"),0 => t("Enabled")), 121 '#default_value' => variable_get('nodeformsettings_inputformat_'. $form['#node_type']->type, 0), 122 ); 123 $form['nodeformsettings']['nodeformsettings_revisionlog'] = array( 124 '#title' => t("Revision log message field"), 125 '#type' => 'radios', 126 '#options' => array( 127 '0' => t("Enabled (if revisions are enabled)"), 128 '1' => t("Only show when user has <a href=\"!url\">View Revisions permission</a>", array('!url' => url('admin/user/permissions', array('fragment' => 'edit-1-view-revisions-wrapper')))), 129 '2' => t("Disabled (for all users)")), 130 '#default_value' => variable_get('nodeformsettings_revisionlog_'. $form['#node_type']->type, 0), 131 ); 132 $form['nodeformsettings']['nodeformsettings_preview'] = array( 133 '#title' => t("Preview Button"), 134 '#type' => 'radios', 135 '#options' => array(1 => t("Disabled"),0 => t("Enabled")), 136 '#default_value' => variable_get('nodeformsettings_preview_'. $form['#node_type']->type, ''), 137 '#disabled' => FALSE, 138 ); 139 if(variable_get('node_preview', 1)) { 140 variable_set('nodeformsettings_preview_'. $form['#node_type']->type, 0); 141 $form['nodeformsettings']['nodeformsettings_preview']['#disabled'] = TRUE; 142 $form['nodeformsettings']['nodeformsettings_preview']['#description'] = t('If you want to disable the Preview button, go to !url and change the "Preview Post" option to "Optional"', array('!url' => l(t('Post settings'), 'admin/content/node-settings'))); 143 } 144 $form['nodeformsettings']['nodeformsettings_cancel'] = array( 145 '#title' => t("Show a Cancel Button"), 146 '#type' => 'radios', 147 '#options' => array(1 => t("Disabled"),0 => t("Enabled")), 148 '#default_value' => variable_get('nodeformsettings_cancel_'. $form['#node_type']->type, 1), 149 ); 150 $form['nodeformsettings']['nodeformsettings_submit'] = array( 151 '#title' => t("Submit button title"), 152 '#type' => 'textfield', 153 '#default_value' => t(variable_get('nodeformsettings_submit_'. $form['#node_type']->type, 'Save')), 154 ); 155 156 // jQuery effect for hidding/showing options dynamically 157 // We do this to hide the anonymous options if the radio is not set to users 'might leave their information' 158 drupal_add_js(drupal_get_path('module', 'nodeformsettings') .'/nodeformsettings.js'); 159 160 $form['comment']['comment_anonymous']['#prefix'] = '<div class="nodeformsettings-radios">'; 161 $form['comment']['comment_anonymous']['#suffix'] = '</div>'; 162 $css_class .= 'nodeformsettings-show-settings'; 163 if(user_access('post comments', drupal_anonymous_user())) { 164 $can_comment = variable_get('comment_anonymous_' . $form['#node_type']->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT); 165 if(!$can_comment) { 166 $css_class .= ' js-hide'; 167 } 168 if($form['comment']['comment_anonymous']['#default_value'] == $can_comment) { 169 $form['comment']['commentformsettings_anonymousname']['#prefix'] = '<div class="' . $css_class . '">'; 170 $form['comment']['commentformsettings_anonymousname']['#suffix'] = '</div>'; 171 $form['comment']['commentformsettings_anonymousmail']['#prefix'] = '<div class="' . $css_class . '">'; 172 $form['comment']['commentformsettings_anonymousmail']['#suffix'] = '</div>'; 173 $form['comment']['commentformsettings_anonymoushomepage']['#prefix'] = '<div class="' . $css_class . '">'; 174 $form['comment']['commentformsettings_anonymoushomepage']['#suffix'] = '</div>'; 175 } 176 } 177 else { 178 $css_class .= ' js-hide'; 179 $form['comment']['commentformsettings_anonymousname']['#prefix'] = '<div class="' . $css_class . '">'; 180 $form['comment']['commentformsettings_anonymousname']['#suffix'] = '</div>'; 181 $form['comment']['commentformsettings_anonymousmail']['#prefix'] = '<div class="' . $css_class . '">'; 182 $form['comment']['commentformsettings_anonymousmail']['#suffix'] = '</div>'; 183 $form['comment']['commentformsettings_anonymoushomepage']['#prefix'] = '<div class="' . $css_class . '">'; 184 $form['comment']['commentformsettings_anonymoushomepage']['#suffix'] = '</div>'; 185 } 186 187 // For node preview options 188 $form['comment']['comment_preview']['#prefix'] = '<div class="nodeformsettings-radios-preview">'; 189 $form['comment']['comment_preview']['#suffix'] = '</div>'; 190 $css_class_preview .= 'nodeformsettings-show-preview'; 191 $preview = variable_get('comment_preview_' . $form['#node_type']->type, COMMENT_PREVIEW_REQUIRED); 192 if(!$preview) { 193 $css_class_preview .= ' js-hide'; 194 } 195 if($form['comment']['comment_preview']['#default_value'] == $preview) { 196 $form['comment']['commentformsettings_preview']['#prefix'] = '<div class="' . $css_class_preview . '">'; 197 $form['comment']['commentformsettings_preview']['#suffix'] = '</div>'; 198 } 199 else { 200 $css_class_preview = 'nodeformsettings-show-preview'; 201 $form['comment']['commentformsettings_preview']['#prefix'] = '<div class="' . $css_class_preview . '">'; 202 $form['comment']['commentformsettings_preview']['#suffix'] = '</div>'; 203 } 204 205 // We do this to order all the options, if we don't do this, the options make no sense 206 $form['comment']['comment']['#weight'] = 0; 207 $form['comment']['comment_default_mode']['#weight'] = 1; 208 $form['comment']['comment_default_order']['#weight'] = 2; 209 $form['comment']['comment_default_per_page']['#weight'] = 3; 210 $form['comment']['comment_controls']['#weight'] = 4; 211 $form['comment']['comment_anonymous']['#weight'] = 5; 212 $form['comment']['commentformsettings_anonymousname']['#weight'] = 6; 213 $form['comment']['commentformsettings_anonymousmail']['#weight'] = 7; 214 $form['comment']['commentformsettings_anonymoushomepage']['#weight'] = 8; 215 $form['comment']['comment_subject_field']['#weight'] = 9; 216 $form['comment']['commentformsettings_author']['#weight'] = 10; 217 $form['comment']['comment_preview']['#weight'] = 11; 218 $form['comment']['commentformsettings_preview']['#weight'] = 12; 219 $form['comment']['comment_form_location']['#weight'] = 13; 220 $form['comment']['commentformsettings_title']['#weight'] = 14; 221 $form['comment']['commentformsettings_inputformat']['#weight'] = 15; 222 $form['comment']['commentformsettings_size']['#weight'] = 16; 223 $form['comment']['commentformsettings_submit']['#weight'] = 17; 224 } 225 226 if($form_id == 'node_configure') { 227 if(variable_get('node_preview', '') == 0) { 228 $form['node_preview']['#description'] = t("If you change this setting to Required, the Preview button of all your content types will be set to Enabled"); 229 } 230 if(variable_get('node_preview', '') == 1) { 231 $types = node_get_types(); 232 foreach($types as $type => $value) { 233 variable_set("nodeformsettings_preview_$type", 0); 234 } 235 } 236 } 237 238 if(isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) { 239 $node = $form['#node']; 240 241 // Change the default height of the body field 242 if(1 == variable_get('submission_body_rows_'. $node->type, '') && $form['body_field']['body']) { 243 $form['body_field']['body']['#type'] = 'textfield'; 244 } 245 else if(variable_get('submission_body_rows_'. $node->type, '') && $form['body_field']['body']) { 246 $form['body_field']['body']['#rows'] = variable_get('submission_body_rows_'. $node->type, ''); 247 } 248 249 // Node settings 250 // Hide the 'Split Summary at Cursor' button 251 if(variable_get('nodeformsettings_splitsummary_'. $node->type, '') == 1) { 252 $form['body_field']['teaser_include'] = array( 253 '#type' => 'value', 254 '#value' => TRUE, 255 ); 256 } 257 // Hide the Input Format Fieldset 258 if(variable_get('nodeformsettings_inputformat_'. $node->type, '') == 1) { 259 unset($form['body_field']['format']); 260 } 261 262 // Hide the Revision log message field 263 if(variable_get('nodeformsettings_revisionlog_'. $node->type, '') == 1) { 264 $form['revision_information']['#access'] = user_access('view revisions'); 265 } 266 elseif(variable_get('nodeformsettings_revisionlog_'. $node->type, '') == 2) { 267 $form['revision_information']['#access'] = FALSE; 268 } 269 270 // Hide the preview button 271 if(variable_get('nodeformsettings_preview_'. $node->type, '') == 1) { 272 unset($form['buttons']['preview']); 273 } 274 // Change the default value for the submit button 275 if(variable_get('nodeformsettings_submit_'. $node->type, '')) { 276 $form['buttons']['submit']['#value'] = t(variable_get('nodeformsettings_submit_'. $node->type, '')); 277 } 278 279 // Show a Cancel link 280 // Patch from http://drupal.org/node/116939 281 // Thanks to rkerr http://drupal.org/user/20129 and quicksketch (http://drupal.org/user/35821) 282 if(!variable_get('nodeformsettings_cancel_'. $node->type, '')) { 283 // Generate a URL for the cancel link. 284 if (!isset($_REQUEST['destination']) || $_REQUEST['destination'] == $_GET['q']) { 285 $url['path'] = !empty($node->nid) ? 'node/'. $node->nid : '<front>'; 286 } 287 else { 288 // parse url to split it up to its components 289 $url = parse_url(urldecode($_REQUEST['destination'])); 290 } 291 292 $form['buttons']['cancel'] = array( 293 '#type' => 'markup', 294 '#value' => l(t('Cancel'), $url['path'], array('query' => $url['query'], 'fragment' => $url['fragment'], 'attributes' => array('class' => 'form-button form-button-cancel'))), 295 '#weight' => 51 296 ); 297 } 298 } 299 300 if('comment_form' == $form_id) { 301 // on comment_form there's no $form['#node'] so we can't load the $node->type 302 // we just take the argument 303 // since we don't have node/nid when creating a comment on a separate form 304 // we have to filter the two cases to check what argument to take and load 305 // the node 306 // TODO: find a better way to do this 307 308 if(arg(0) == 'node' && is_numeric(arg(1))) { 309 $node = node_load(arg(1)); 310 } 311 if(arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2))) { 312 $node = node_load(arg(2)); 313 } 314 // User profile (When using content profile) 315 if(module_exists('content_profile')) { 316 if(arg(0) == 'user' && is_numeric(arg(1))) { 317 $content = array(); 318 foreach (content_profile_get_types('names') as $type => $type_name) { 319 $node = content_profile_load($type, arg(1)); 320 if($node){ break; } 321 } 322 } 323 } 324 325 // Comments settings 326 if(variable_get('commentformsettings_author_'. $node->type, '') == 1) { 327 unset($form['_author']); 328 } 329 if(variable_get('commentformsettings_preview_'. $node->type, '') == 1) { 330 unset($form['preview']); 331 } 332 if(variable_get('commentformsettings_title_'. $node->type, '') == 1) { 333 unset($form['comment_filter']['comment']['#title']); 334 } 335 if(variable_get('commentformsettings_inputformat_'. $node->type, '') == 1) { 336 unset($form['comment_filter']['format']); 337 } 338 339 // For anonymous comments 340 if(variable_get('commentformsettings_anonymousname_'. $node->type, '') == 1) { 341 unset($form['name']); 342 } 343 if(variable_get('commentformsettings_anonymousmail_'. $node->type, '') == 1) { 344 unset($form['mail']); 345 } 346 if(variable_get('commentformsettings_anonymoushomepage_'. $node->type, '') == 1) { 347 unset($form['homepage']); 348 } 349 if(variable_get('comment_preview_'. $node->type, 1) == 0) { 350 $form['submit']['#value'] = t(variable_get('commentformsettings_submit_'. $node->type, "Save")); 351 } 352 $form['comment_filter']['comment']['#rows'] = variable_get('commentformsettings_size_'. $node->type, 15); 353 } 354 355 } 356 357 /** 358 * From http://drupal.org/node/426482 359 */ 360 function nodeformsettings_preprocess_page(&$vars) { 361 // Titles are ignored by content type when they are not desired in the design. 362 $vars['original_title'] = $vars['title']; 363 if(variable_get('hidetitle_'. $vars['node']->type, '') == 1) { 364 $vars['title'] = ''; 365 } 366 367 } 368
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |