| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* image_attach_default.module
|
| 7 |
*
|
| 8 |
* This module will allow an administrator to set up a default image to be attached
|
| 9 |
* to nodes that are set up to allow image attachments.
|
| 10 |
*/
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Implementation of hook_form_alter()
|
| 14 |
*
|
| 15 |
* @param string ID of the form being altered
|
| 16 |
* @param array Actual Form being altered
|
| 17 |
* @return void
|
| 18 |
* @author Craig Gardner
|
| 19 |
**/
|
| 20 |
function image_attach_default_form_alter($form_id, &$form) {
|
| 21 |
if ($form_id == 'image_attach_admin_settings') {
|
| 22 |
$content_types = node_get_types();
|
| 23 |
|
| 24 |
$form['image_attach_existing']['#weight'] = -1;
|
| 25 |
|
| 26 |
// Create the new form elements
|
| 27 |
$form['content_type_defaults'] = array(
|
| 28 |
'#type' => 'fieldset',
|
| 29 |
'#title' => t('Default Values'),
|
| 30 |
'#weight' => 0,
|
| 31 |
'#description' => t('Choose a default image to be displayed for each content type;')
|
| 32 |
);
|
| 33 |
foreach ($content_types as $name => $content) {
|
| 34 |
// Make sure we are allowed to attach images to this content type
|
| 35 |
if (variable_get('image_attach_'. $name, '0') == 1) {
|
| 36 |
$form['content_type_defaults']['picker']["image_attach_{$name}_default"] = array(
|
| 37 |
'#type' => 'select',
|
| 38 |
'#title' => t($content->name),
|
| 39 |
'#options' => _image_attach_get_image_nodes(),
|
| 40 |
'#default_value' => variable_get("image_attach_{$name}_default", "0"),
|
| 41 |
);
|
| 42 |
} // end if (variable_get('image_attach_'. $name), '0' == 1)
|
| 43 |
} // end foreach ($content_types as $name => $content)
|
| 44 |
} // end if ($form_id == 'image_attach_admin_settings')
|
| 45 |
elseif (isset($form['type']) && $form['type']['#value'] != 'image') {
|
| 46 |
$form['image_attach']['iid']['#default_value'] = variable_get("image_attach_{$form['type']['#value']}_default", "0");
|
| 47 |
} // end elseif (isset($form['type']) && $form['type']['#value'] != 'image')
|
| 48 |
} // end function image_attach_default_form_alter()
|