function dynamic_background_node_form_alter in Dynamic Background 7.2
Same name and namespace in other branches
- 6 modules/dynamic_background_node/dynamic_background_node.module \dynamic_background_node_form_alter()
- 7 modules/dynamic_background_node/dynamic_background_node.module \dynamic_background_node_form_alter()
Implements hook_form_alter().
Hooks into the selected content types an insert a form selection option of background images uploaded by the site administrator.
File
- modules/
dynamic_background_node/ dynamic_background_node.module, line 84 - This module provides the node administrations with the option to use different dynamic background images for each node.
Code
function dynamic_background_node_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['type']['#value'])) {
// Enable all content types by default.
$settings = variable_get('dynamic_background_node', array());
dynamic_background_default_content_types($settings);
if (isset($settings['settings']['content_types'][$form['type']['#value']]) && $settings['settings']['content_types'][$form['type']['#value']]) {
// Add new field.set, will be shown as a vertical tab.
$form['additional_settings']['dynamic_background'] = array(
'#type' => 'fieldset',
'#title' => t('Node background'),
'#collapsed' => FALSE,
'#collapsible' => TRUE,
'#tree' => TRUE,
);
// Find the current node's id.
$nid = -1;
if (isset($form['#node']) && isset($form['#node']->nid)) {
$nid = $form['#node']->nid;
}
// Add the image selection part of the form.
$form['additional_settings']['dynamic_background'] += dynamic_background_image_selector_form('node', $nid);
// Allow user to upload a image.
if (user_access('dynamic background upload node')) {
// Load settings and find the number of images.
$settings = variable_get('dynamic_background_node', array());
$no_of_images = isset($settings['upload']['no_of_images']) ? $settings['upload']['no_of_images'] : 1;
// Only proceed if the form is needed.
if ($no_of_images > 0) {
// Add user upload form.
$upload_form = dynamic_background_user_upload_form('node', $nid, $no_of_images);
$form['additional_settings']['dynamic_background'] += $upload_form['form'];
// Add submission function.
$form['#submit'][] = $upload_form['submit'];
}
}
// Add some style to the image selection.
drupal_add_css(drupal_get_path('module', 'dynamic_background_node') . '/css/dynamic_background_node.admin.css');
}
}
}