mysite_edit_form($edit, $page, $only = 'personal')
mysite.module, line 1605
Form function for mysite_edit().
$edit The values passed to the form by mysite_edit(). Perhaps this should be a reference &$edit?
$page The current page of the mysite collection.
$only A string value indicating which parts of the form are active
function mysite_edit_form($edit, $page, $only = 'personal') {
$submenu = mysite_edit_menu();
$path = drupal_get_path('module', 'mysite') .'/plugins';
// get the variables we need to check
$types = variable_get('mysite_content', NULL);
$form = array();
$form['mysite_edit'] = array(
'#type' => 'fieldset',
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['mysite_edit']['page'] = array('#type' => 'value', '#value' => $page);
// personal settings
if ($only == 'personal') {
$form['mysite_edit']['title'] = array(
'#type' => 'textfield',
'#title' => t('Personal page title'),
'#default_value' => $edit['title'],
'#weight' => -10,
'#size' => 40,
'#maxlength' => 80,
'#required' => TRUE,
'#description' => t('Naming each page helps you personalize the site.')
);
$form['mysite_edit']['status'] = array(
'#type' => 'radios',
'#title' => t('Allow others to see this personal page'),
'#default_value' => $edit['status'],
'#options' => array(0 => t('No'), 1 => t('Yes'))
);
}
else {
$form['mysite_edit']['title'] = array('#type' => 'value', '#value' => $edit['title']);
$form['mysite_edit']['status'] = array('#type' => 'value', '#value' => $edit['status']);
}
// theme settings
if ($only == 'theme') {
$themes = variable_get('mysite_theme_settings', array());
if (!empty($types['theme']) && !empty($themes)) {
mysite_load_includes('types', 'theme');
$allowed = mysite_type_theme_data($themes);
$form['mysite_edit']['theme'] = array(
'#type' => 'radios',
'#title' => t('Theme'),
'#default_value' => $edit['theme'],
'#options' => $allowed['name'],
'#description' => array('desc' => t('Select a theme for your personal page.'), 'screens' => $allowed['screenshot'])
);
$form['#theme'] = 'mysite_edit_theme';
}
else {
$form['mysite_edit']['theme'] = array('#type' => 'hidden', '#value' => $edit['theme']);
}
}
else {
$form['mysite_edit']['theme'] = array('#type' => 'hidden', '#value' => $edit['theme']);
}
// layout settings
if ($only == 'layout') {
$options = array();
$images = array();
$details = array();
$layouts = mysite_load_includes('layouts');
$path = drupal_get_path('module', 'mysite');
foreach ($layouts as $key => $value) {
$layout = module_invoke('mysite_layout', $value);
$options[$value] = $layout['name'];
$images[$value] = theme_image($path .'/plugins/layouts/'. $layout['image'], $layout['name'], $layout['name']);
$details[$value] = $layout['description'];
}
$description = array('desc' => t('Select a layout for your personal page.'), 'images' => $images, 'details' => $details);
if ($options != array('default')) {
$form['mysite_edit']['layout'] = array(
'#type' => 'radios',
'#title' => t('Layout'),
'#default_value' => $edit['layout'],
'#options' => $options,
'#description' => $description
);
$form['#theme'] = 'mysite_edit_layout';
}
else {
$form['mysite_edit']['layout'] = array('#type' => 'hidden', '#value' => $edit['layout']);
}
}
else {
$form['mysite_edit']['layout'] = array('#type' => 'hidden', '#value' => $edit['layout']);
}
// style settings
if ($only == 'style') {
$options = array();
$samples = array();
$styles = mysite_load_includes('styles'); // load these, since they affect display
foreach ($styles as $style) {
$options[$style] = ucwords($style);
$samples[$style] = 'mysite-'. $style .'-edit';
}
if ($options != array('default')) {
$form['mysite_edit']['style'] = array(
'#type' => 'radios',
'#title' => t('Style'),
'#default_value' => $edit['style'],
'#options' => $options,
'#description' => array('desc' => t('Select a style for your personal page.'), 'samples' => $samples)
);
$form['#theme'] = 'mysite_edit_style';
}
else {
$form['mysite_edit']['style'] = array('#type' => 'hidden', '#value' => $edit['style']);
}
}
else {
$form['mysite_edit']['style'] = array('#type' => 'hidden', '#value' => $edit['style']);
}
// format settings
if ($only == 'format') {
$options = array();
$samples = array();
$formats = mysite_load_includes('formats');
foreach ($formats as $format) {
$data = module_invoke('mysite_theme', $format);
$options[$format] = $data['format'];
$samples[$format] = $data['sample'];
}
if ($options != array('default')) {
$form['mysite_edit']['format'] = array(
'#type' => 'radios',
'#title' => t('Content format'),
'#prefix' => t('This setting will be the default for new content on this page. You may configure individual items to use different formats.'),
'#default_value' => $edit['format'],
'#options' => $options,
'#description' => array('desc' => t('Select a format for this personal page.'), 'samples' => $samples)
);
$form['mysite_edit']['format_update'] = array(
'#type' => 'checkbox',
'#title' => t('Update all content to this format'),
'#return_value' => 1,
'#default_value' => 1,
'#description' => t("Set all page content to use the selected format?")
);
$form['#theme'] = 'mysite_edit_format';
}
else {
$form['mysite_edit']['format'] = array('#type' => 'hidden', '#value' => $edit['format']);
}
}
else {
$form['mysite_edit']['format'] = array('#type' => 'hidden', '#value' => $edit['format']);
}
// Set the pointer for the "Save and Continue" button
// Arrays don't let you set the pointer by key??
$list = array_keys($submenu[$page]);
while ($only != current($list)) {
next($list);
}
$next = next($list);
if ($next === FALSE) {
$next = reset($list);
}
$pages = mysite_get_pages($edit['uid']);
if (count($pages) > 1) {
// Flag to set all pages to this value.
$form['mysite_edit']['set_all'] = array(
'#type' => 'checkbox',
'#title' => t('Use these settings for all pages in my collection.'),
'#checked' => FALSE,
);
}
else {
$form['mysite_edit']['set_all'] = array('#type' => 'value', '#value' => 0);
}
// hidden values
$form['mysite_edit']['only'] = array('#type' => 'value', '#value' => $only);
$form['mysite_edit']['next'] = array('#type' => 'value', '#value' => $next);
$form['mysite_edit']['uid'] = array('#type' => 'value', '#value' => $edit['uid']);
$form['mysite_edit']['submit'] = array('#type' => 'submit', '#submit' => TRUE, '#value' => t('Save and view changes'));
$form['mysite_edit']['continue'] = array('#type' => 'submit', '#submit' => TRUE, '#value' => t('Save settings and continue >>'));
return $form;
}