function sharedblocks_subscribe_form in Shared Blocks 7
Same name and namespace in other branches
- 6 sharedblocks.module \sharedblocks_subscribe_form()
Form for adding new subscription block.
1 string reference to 'sharedblocks_subscribe_form'
- sharedblocks_menu in ./
sharedblocks.module - Implements hook_menu().
File
- ./
sharedblocks.module, line 242
Code
function sharedblocks_subscribe_form($form, &$form_state, $id = NULL) {
// Populate the default values.
$edit = array(
'id' => NULL,
'name' => '',
'label' => '',
'url' => '',
'update_interval' => 3600,
);
// @todo: this doesn't work if there's an error on the form
if (!empty($form_state['input'])) {
$edit = $form_state['input'];
}
elseif (!is_null($id) && is_numeric($id)) {
$edit = db_select('sharedblocks', 'sb')
->fields('sb')
->condition('id', $id)
->execute()
->fetchAssoc();
}
$form = array();
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => $edit['name'],
'#description' => t('Machine readable name of this block. Alphanumeric and underscore characters only.'),
'#required' => TRUE,
);
$form['url'] = array(
'#type' => 'textfield',
'#title' => t('Subscribe URL'),
'#default_value' => $edit['url'],
'#description' => t('The URL to the block you wish to subscribe to, supplied by publishing site.'),
'#required' => TRUE,
);
$period = drupal_map_assoc(array(
60,
300,
600,
1200,
1800,
3600,
10800,
21600,
32400,
43200,
86400,
172800,
259200,
604800,
1209600,
2419200,
4838400,
9676800,
), 'format_interval');
$form['update_interval'] = array(
'#type' => 'select',
'#title' => t('Refresh rate'),
'#options' => $period,
'#description' => t("How frequently should this block's content be updated? Note that this can only run as often as cron runs."),
'#default_value' => $edit['update_interval'],
);
if (!is_null($id)) {
$form['id'] = array(
'#type' => 'value',
'#value' => $id,
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}