/**
* Implementation of hook form alter
*/
function capsa_form_alter($form_id, &$form) {
global $user;
// Get List of TYPES that we provide CAPSA features for
$capsa_types = get_capsa_types();
// hide input format for body and comments except for admins
// We need to allow admins the ability to create PHP nodes and to see
// the selected input format for nodes.
$form['body_filter']['format']['#access'] = user_access('administer nodes');
$form['comment_filter']['format']['#access'] = user_access('administer nodes');
switch ($form_id) {
case 'node_type_form':
// Add node type config to allow for CAPSA Tweaks
$form['capsa'] = array(
'#type' => 'fieldset',
'#title' => t('CAPSA'),
);
$form['capsa']['capsa_tweaks'] = array(
'#type' => 'checkbox',
'#title' => t('Enable CAPSA form tweaks'),
'#default_value' => variable_get('capsa_tweaks_'. $form['#node_type']->type, 0),
'#description' => t('Check this box to enable CAPSA form tweaks for this node type.')
);
// Add node type config to allow for CAPSA Management
// - this adds to list pulled by get_capsa_types()
$form['capsa']['capsa_manage'] = array(
'#type' => 'checkbox',
'#title' => t('Enable CAPSA system to manage this node type'),
'#default_value' => variable_get('capsa_manage_'. $form['#node_type']->type, 0),
'#description' => t('Check this box to enable CAPSA Management for this node type.')
);
break;
case 'views_filters':
// remove Views type filter options for types that are not capsa types
/* foreach ($form['filter0']['#options'] as $key => $option) {
if ($key != '**ALL**' && !in_array($key, $capsa_types)) unset($form['filter0']['#options'][$key]);
} */
break;
// if it's the input filter admin page, increase maxlength for
// Rich Text Editor allowed html tags text input (filter id 13)
case 'filter_admin_configure':
$form['filter_html']['allowed_html_13']['#type'] = 'textarea';
$form['filter_html']['allowed_html_13']['#rows'] = 3;
$form['filter_html']['allowed_html_13']['#maxlength'] = 2056;
break;
// set default for Workflow Access settings page for anon/auth to be off by default
case 'workflow_state_add_form':
foreach ($form['fields'] as $key=>$type) {
if (is_array($form['fields'][$key]) && $key != 'types') {
foreach ($type as $fkey=>$field) {
foreach ($field as $ckey=>$cbox) {
foreach ($cbox['#default_value'] as $dvkey=>$value) {
if ($value === 1 || $value == 2) unset($form['fields'][$key][$fkey][$ckey]['#default_value'][$dvkey]);
}}}}}
break;
// remove Views type filter options for types that are not capsa types
case 'views_filters':
foreach ($form['filter0']['#options'] as $key => $option) {
if ($key != '**ALL**' && !in_array($key, $capsa_types)) unset($form['filter0']['#options'][$key]);
}
break;
// highlight the IMAGE RIGHTS notice with css
case 'image_node_form':
// move category below image rights
$form['taxonomy']['#weight'] = 1.5;
// add surrounding div to highlight image rights field
$form['field_image_rights']['#prefix'] = '<div class="notice">' . "\n";
$form['field_image_rights']['#suffix'] = "\n" . '</div>';
break;
}
// ====== CAPSA TWEAKS ==========
if (isset($form['type']['#value']) && $form_id == $form['type']['#value'] .'_node_form') {
// check if this content_type has CAPSA Tweaks enabled
if ((variable_get('capsa_tweaks_'. $form['type']['#value'], 0) == 1) &&
// make sure it's a node edit or add form
// or a clone form (BT 2007-10-09)
((arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'edit') ||
(arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'clone') ||
(arg(0) == 'node' && arg(1) == 'add'))) {
/**
* Hide formatting guidelines on edit/create node form
* - grab all CCK fields that are set to text
* - check to see if the type is set to textarea
* - check to see if a format is defined and if so:
* - set access to false in order to hide the fieldset
*/
$ctype = $form['type']['#value'];
$content_type = content_types($ctype); //in content.module
foreach ($content_type['fields'] as $field) {
for ($i=0; $i < count($form[$field['field_name']]); $i++) {
// foreach CCK field we check to see if it is defined as text and the type is a textarea
if (($field['type'] == 'text') && ($form[$field['field_name']][$i]['value']['#type'] == 'textarea')) {
// next we check to see if a format is set
if (is_array($form[$field['field_name']][$i]['format'])) {
// set the #access to false in order to hide it
$form[$field['field_name']][$i]['format']['#access'] = false;
}
}
}
}
// Add preview/submit buttons at top of edit form
$path = drupal_get_path('module', 'capsa') .'/capsa.js';
drupal_add_js($path);
// ..and if it's an edit form - if we are admins let add the delete button as well
if (user_access('administer nodes')) {
if (!empty($form['nid']['#value'])) { //edit
$path = drupal_get_path('module', 'capsa') .'/capsa_edit.js';
drupal_add_js($path);
}
}
// and if we aren't admin; then remove the std delete button (at bottom)
else unset($form['delete']);
// add div that jquery can reference to insert buttons at top of form
$form['topspacer'] = array(
'#type' => 'markup',
'#value' => ' ',
'#weight' => -25,
'#prefix' => '<div id="topbuttons">',
'#suffix' => '</div>',
);
// remove LOG field
unset($form['log']);
// make title a textarea so we can use tinymce spellcheck
$form['title']['#type'] = 'textarea';
$form['title']['#rows'] = 2;
}
}
// ==== end CAPSA TWEAKS =====
// ===== ALL CAPSA TYPES =======
if (in_array(str_replace('_node_form', '', $form_id), $capsa_types) && stristr($form_id, '_node_form')) {
// add Plagiarism Policy signoff
$form['capsa_policy_signoff'] = array(
'#type' => 'checkbox',
'#title' => variable_get('capsa_signoff_waiver', t('Define waiver in CAPSA admin configuration.')),
'#default_value' => db_result(db_query("SELECT checked FROM {capsa_signoff} WHERE nid = %d", arg(1))),
'#weight' => -20,
'#prefix' => '<br /><div class="notice"><strong>'. t('Plagiarism Policy') .'</strong>',
'#suffix' => "\n" . '</div>',
'#validate' => array('_capsa_policy_node_validate' => array()),
);
// "remove" surrrounding "Categories" fieldset for Topic
$form['taxonomy']['#collapsible'] = FALSE;
$form['taxonomy']['#attributes'] = array('class' => 'fieldsetstripped');
// remove Workflow from node/edit
// - we do this to prevent WFS change (only) from creating a new Rev since this is preferred and matches
// what happens if done from WF tab.
unset($form['workflow']);
// expand metatags field, re-position it
$form['nodewords']['#collapsed'] = FALSE;
$form['nodewords']['#weight'] = 3.1;
}
// ==== end CAPSA TYPES ===========
// ALL node forms
if (isset($form['#id']) && ($form['#id'] == 'node-form') && arg(0) == 'node') {
// this was collapsed by default on old CAPSA but latest pathauto rev has it expanded so lets force it back to collapsed
$form['path']['#collapsed'] = true;
}
}