function dynamic_banner_admin_form in Dynamic Banner 7
Same name and namespace in other branches
- 6 includes/callbacks.inc \dynamic_banner_admin_form()
- 7.2 dynamic_banner.module \dynamic_banner_admin_form()
- 8.x dynamic_banner.module \dynamic_banner_admin_form()
The main form dealing with dynamic banner There is now only one form for dynamic banner to deal with unlink in the d6 version
INPUT: arg(4) is from the url path of this form
1 string reference to 'dynamic_banner_admin_form'
- dynamic_banner_menu in ./
dynamic_banner.module - Implements hook_menu(). it is key to note here access arguments is referring to permissions
File
- includes/
callbacks.inc, line 337 - Dynamic Banner Admin Pages and various other functions to make them work Most of the code in this file was derived from path module
Code
function dynamic_banner_admin_form($form, &$form_state) {
$dbid = arg(4);
// the last portion of the url there must be a better way of doing this
// This is used by the file handler, It is needed to accept files
$form['#attributes'] = array(
'enctype' => "multipart/form-data",
);
$file_path = drupal_get_path('module', 'file');
// default the variables here
$banner = NULL;
// prevent bugs nulify the variable
$default_flag = FALSE;
// enable variable in this scope
// hide it so that the user may not change this element
$form['dbid'] = array(
'#type' => 'hidden',
'#required' => FALSE,
);
if ($dbid == '') {
// this will disable the path field for the default banner
if (strrpos($_GET['q'], "/default")) {
drupal_set_title(t('Default Banner'));
// load the default if there is one
$banner = dynamic_banner_find_load_default();
}
else {
drupal_set_title(t('New Banner'));
$form['dbid']['#value'] = NULL;
}
}
else {
// The dbid is set so a banner must exist load it
$banner = dynamic_banner_load_banner($dbid);
drupal_set_title(t("Edit Banner") . " '" . $banner->path . "'");
$form['dbid']['#value'] = $dbid;
}
// this will prevent the used from changing this field once the default has been loaded
// it deals with a bug if the person chose to edit the specific banner for default rather than pressing default
if ($banner && $banner->path == 'DEFAULT') {
$default_flag = TRUE;
}
// disable the path form element when the default flag is out
if (!$default_flag) {
$form['path'] = array(
'#type' => 'textfield',
'#title' => t('Banner Path'),
'#default_value' => $banner ? $banner->path : "",
'#size' => 45,
'#maxlength' => 250,
'#description' => t('Specify an existing url path you wish to put a banner on. For example: home, user* (wild card), content! (random). Enter a path as it appears in the url of your site.'),
'#field_prefix' => url(NULL, array(
'absolute' => TRUE,
)) . (variable_get('clean_url', 0) ? '' : '?q='),
'#required' => TRUE,
);
}
else {
$form['path'] = array(
'#type' => 'hidden',
'#title' => t('Banner Path'),
'#value' => 'DEFAULT',
);
}
// if the module exists add the autocomplete path
// i might have to do my own autocomplete here cause mpac doesnt really do what i need it to do
if (module_exists('mpac')) {
$form['path']['#autocomplete_path'] = 'mpac/autocomplete/alias';
}
$form['image_type'] = array(
'#type' => 'radios',
'#options' => drupal_map_assoc(array(
t('Use Existing Image(s)'),
t('Upload New Image(s)'),
)),
'#title' => t('Choose image type.'),
);
if ($banner && isset($banner->imgurl)) {
$form['image_type']['#default_value'] = t('Use Existing Image(s)');
}
if ($banner && isset($banner->imgfid)) {
$form['image_type']['#default_value'] = t('Upload New Image(s)');
}
/**
* Note: There are two form elements for the same thing
* They are both not required but only one is needed for proper handling
* When we are loading an old banner load the url into imgurl
* When we are uploading a new image the validator will upload the image store it and fill in imgurl for you
* Only use one method no mix and matching
* When reading the data use checks to see which method was used
*/
$form['imgurl'] = array(
'#type' => 'textfield',
'#title' => t('Typeout the url of the image'),
'#default_value' => $banner ? $banner->imgurl : '',
'#description' => t('Specify an image(s) for the banner to display.'),
'#field_prefix' => url(NULL, array(
'absolute' => TRUE,
)) . (variable_get('clean_url', 0) ? '' : '?q='),
//'#required' => TRUE,
'#states' => array(
'visible' => array(
':input[name="image_type"]' => array(
'value' => t('Use Existing Image(s)'),
),
),
),
);
/**
* Since upon pressing the delete button on the image the fid is set to 0
* We need to save is because we still need to delete that image.
*/
$form['oldimagefid'] = array(
'#type' => 'hidden',
'#required' => FALSE,
'#value' => $banner ? $banner->imgfid : '',
);
$form['image'] = array(
'#title' => t('Choose Image File'),
'#type' => 'managed_file',
'#default_value' => $banner ? $banner->imgfid : '',
'#attached' => array(
'js' => array(
$file_path . '/file.js',
),
),
'#progress_indicator' => 'throbber',
'#progress_message' => NULL,
'#upload_location' => variable_get('dynamic_banner_file_save_path', BANNER_DEFAULT_SAVE_LOCATION),
'#description' => t('Specify an image(s) for the banner to display.'),
//'#required' => TRUE,
'#states' => array(
'visible' => array(
':input[name="image_type"]' => array(
'value' => t('Upload New Image(s)'),
),
),
),
);
$form['#validate'][] = 'dynamic_banner_upload_image_validate';
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text'),
'#default_value' => $banner ? $banner->text : '',
'#maxlength' => 250,
'#size' => 45,
'#description' => t('Specify the text to associate with this banner [comma seperated for randoms, also must match amount of elements from images] (optional).'),
'#required' => FALSE,
);
$form['link'] = array(
'#type' => 'textfield',
'#title' => t('Link'),
'#default_value' => $banner ? $banner->link : '',
'#maxlength' => 250,
'#size' => 45,
'#description' => t('Specify the link you want your banner to point to (optional).'),
'#required' => FALSE,
);
$form['mode'] = array(
'#type' => 'radios',
'#title' => t('Mode'),
'#options' => drupal_map_assoc(array(
t('normal'),
t('time_based'),
t('rotating'),
t('fade'),
)),
'#default_value' => $banner ? $banner->mode : BANNER_DEFAULT_BANNER_MODE,
'#description' => t('What mode do you want this banner to display under (this is different than display setting)'),
'#required' => TRUE,
);
/*
$form['time_on'] = array(
'#type' => 'date',
'#title' => t('Start Time'),
'#description' => t('Specify the time you want your banner to start displaying (optional).'),
'#required' => FALSE,
'#states' => array(
'visible' => array(
':input[name="mode"]' => array('value' => t('time_based')),
),
),
);
$form['time_off'] = array(
'#type' => 'date',
'#title' => t('End Time'),
'#description' => t('Specify the time you want your banner to stop displaying (optional).'),
'#required' => FALSE,
'#states' => array(
'visible' => array(
':input[name="mode"]' => array('value' => t('time_based')),
),
),
);*/
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save Banner'),
);
return $form;
}