Fix for Testing 123 form alter

  1. /**
  2.  * Implementation of hook form alter
  3.  */  
  4. function capsa_form_alter($form_id, &$form) {
  5.   global $user;
  6.  
  7.   // Get List of TYPES that we provide CAPSA features for
  8.   $capsa_types = get_capsa_types();
  9.  
  10.   // hide input format for body and comments except for admins
  11.   // We need to allow admins the ability to create PHP nodes and to see
  12.   // the selected input format for nodes.
  13.   $form['body_filter']['format']['#access'] = user_access('administer nodes');
  14.   $form['comment_filter']['format']['#access'] = user_access('administer nodes');
  15.  
  16.   switch ($form_id) {
  17.    
  18.     case 'node_type_form':            
  19.       // Add node type config to allow for CAPSA Tweaks
  20.       $form['capsa'] = array(
  21.         '#type' => 'fieldset',  
  22.         '#title' => t('CAPSA'),
  23.       );
  24.       $form['capsa']['capsa_tweaks'] = array(
  25.         '#type' => 'checkbox',
  26.         '#title' => t('Enable CAPSA form tweaks'),
  27.         '#default_value' => variable_get('capsa_tweaks_'. $form['#node_type']->type, 0),
  28.         '#description' => t('Check this box to enable CAPSA form tweaks for this node type.')
  29.       );  
  30.       // Add node type config to allow for CAPSA Management
  31.       //    - this adds to list pulled by get_capsa_types()
  32.       $form['capsa']['capsa_manage'] = array(
  33.         '#type' => 'checkbox',
  34.         '#title' => t('Enable CAPSA system to manage this node type'),
  35.         '#default_value' => variable_get('capsa_manage_'. $form['#node_type']->type, 0),
  36.         '#description' => t('Check this box to enable CAPSA Management for this node type.')
  37.       );
  38.       break;
  39.      
  40.     case 'views_filters':
  41.       // remove Views type filter options for types that are not capsa types
  42.    /*   foreach ($form['filter0']['#options'] as $key => $option) {
  43.         if ($key != '**ALL**' && !in_array($key, $capsa_types)) unset($form['filter0']['#options'][$key]);
  44.       }  */
  45.       break;
  46.    
  47.     // if it's the input filter admin page, increase maxlength for
  48.     // Rich Text Editor allowed html tags text input (filter id 13)
  49.     case 'filter_admin_configure':
  50.       $form['filter_html']['allowed_html_13']['#type'] = 'textarea';
  51.       $form['filter_html']['allowed_html_13']['#rows'] = 3;
  52.       $form['filter_html']['allowed_html_13']['#maxlength'] = 2056;
  53.       break;
  54.    
  55.     // set default for Workflow Access settings page for anon/auth to be off by default
  56.     case 'workflow_state_add_form':
  57.       foreach ($form['fields'] as $key=>$type) {
  58.         if (is_array($form['fields'][$key]) && $key != 'types') {
  59.           foreach ($type as $fkey=>$field) {
  60.             foreach ($field as $ckey=>$cbox) {
  61.               foreach ($cbox['#default_value'] as $dvkey=>$value) {
  62.                 if ($value === 1 || $value == 2) unset($form['fields'][$key][$fkey][$ckey]['#default_value'][$dvkey]);
  63.       }}}}}
  64.       break;
  65.    
  66.     // remove Views type filter options for types that are not capsa types
  67.     case 'views_filters':
  68.       foreach ($form['filter0']['#options'] as $key => $option) {
  69.         if ($key != '**ALL**' && !in_array($key, $capsa_types)) unset($form['filter0']['#options'][$key]);
  70.       }
  71.       break;
  72.      
  73.     // highlight the IMAGE RIGHTS notice with css
  74.     case 'image_node_form':
  75.       // move category below image rights
  76.       $form['taxonomy']['#weight'] = 1.5;
  77.  
  78.       // add surrounding div to highlight image rights field
  79.       $form['field_image_rights']['#prefix'] = '<div class="notice">' . "\n";
  80.       $form['field_image_rights']['#suffix'] = "\n" . '</div>';
  81.       break;
  82.   }
  83.  
  84.   // ====== CAPSA TWEAKS ==========  
  85.  
  86.   if (isset($form['type']['#value']) && $form_id == $form['type']['#value'] .'_node_form') {
  87.     // check if this content_type has CAPSA Tweaks enabled  
  88.     if ((variable_get('capsa_tweaks_'. $form['type']['#value'], 0) == 1) &&
  89.         // make sure it's a node edit or add form
  90.         // or a clone form (BT 2007-10-09)
  91.         ((arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'edit') ||
  92.           (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'clone') ||
  93.           (arg(0) == 'node' && arg(1) == 'add'))) {
  94.  
  95.       /**
  96.        *  Hide formatting guidelines on edit/create node form
  97.        *  - grab all CCK fields that are set to text
  98.        *  - check to see if the type is set to textarea
  99.        *  - check to see if a format is defined and if so:
  100.        *  - set access to false in order to hide the fieldset
  101.        */
  102.       $ctype = $form['type']['#value'];
  103.       $content_type = content_types($ctype); //in content.module
  104.  
  105.       foreach ($content_type['fields'] as $field) {
  106.         for ($i=0; $i < count($form[$field['field_name']]); $i++) {
  107.           // foreach CCK field we check to see if it is defined as text and the type is a textarea
  108.           if (($field['type'] == 'text') && ($form[$field['field_name']][$i]['value']['#type'] == 'textarea')) {
  109.             // next we check to see if a format is set
  110.             if (is_array($form[$field['field_name']][$i]['format'])) {
  111.               // set the #access to false in order to hide it
  112.               $form[$field['field_name']][$i]['format']['#access'] = false;
  113.             }
  114.           }
  115.         }
  116.       }
  117.      
  118.       //  Add preview/submit buttons at top of edit form
  119.       $path = drupal_get_path('module', 'capsa') .'/capsa.js';
  120.       drupal_add_js($path);
  121.  
  122.       // ..and if it's an edit form - if we are admins let add the delete button as well
  123.       if (user_access('administer nodes')) {
  124.         if (!empty($form['nid']['#value'])) {  //edit
  125.           $path = drupal_get_path('module', 'capsa') .'/capsa_edit.js';
  126.           drupal_add_js($path);
  127.         }
  128.       }  
  129.       // and if we aren't admin; then remove the std delete button (at bottom)
  130.       else unset($form['delete']);
  131.            
  132.       // add div that jquery can reference to insert buttons at top of form
  133.       $form['topspacer'] = array(
  134.         '#type' => 'markup',
  135.         '#value' => ' ',
  136.         '#weight' => -25,
  137.         '#prefix' => '<div id="topbuttons">',
  138.         '#suffix' => '</div>',
  139.       );
  140.      
  141.       // remove LOG field
  142.       unset($form['log']);
  143.  
  144.       // make title a textarea so we can use tinymce spellcheck
  145.       $form['title']['#type'] = 'textarea';
  146.       $form['title']['#rows'] = 2;
  147.     }
  148.   }
  149.   // ==== end CAPSA TWEAKS =====
  150.  
  151.  
  152.   // ===== ALL CAPSA TYPES =======
  153.   if (in_array(str_replace('_node_form', '', $form_id), $capsa_types) && stristr($form_id, '_node_form')) {
  154.    
  155.      // add Plagiarism Policy signoff
  156.     $form['capsa_policy_signoff'] = array(
  157.       '#type'           => 'checkbox',
  158.       '#title'          => variable_get('capsa_signoff_waiver', t('Define waiver in CAPSA admin configuration.')),
  159.       '#default_value'  => db_result(db_query("SELECT checked FROM {capsa_signoff} WHERE nid = %d", arg(1))),
  160.       '#weight'         => -20,
  161.       '#prefix'         => '<br /><div class="notice"><strong>'. t('Plagiarism Policy') .'</strong>',
  162.       '#suffix'         => "\n" . '</div>',  
  163.       '#validate'      => array('_capsa_policy_node_validate' => array()),
  164.     );
  165.    
  166.     // "remove" surrrounding "Categories" fieldset for Topic
  167.     $form['taxonomy']['#collapsible'] = FALSE;
  168.     $form['taxonomy']['#attributes'] = array('class' => 'fieldsetstripped');
  169.    
  170.     // remove Workflow from node/edit
  171.     //    - we do this to prevent WFS change (only) from creating a new Rev since this is preferred and matches
  172.     //      what happens if done from WF tab.
  173.     unset($form['workflow']);
  174.  
  175.     // expand metatags field, re-position it
  176.     $form['nodewords']['#collapsed'] = FALSE;
  177.     $form['nodewords']['#weight'] = 3.1;
  178.  
  179.   }
  180.   // ==== end CAPSA TYPES ===========
  181.  
  182.   // ALL node forms
  183.   if (isset($form['#id']) && ($form['#id'] == 'node-form') && arg(0) == 'node') {
  184.     // this was collapsed by default on old CAPSA but latest pathauto rev has it expanded so lets force it back to collapsed
  185.     $form['path']['#collapsed'] = true;
  186.   }
  187. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.