function hosting_alias_form_data in Hosting 6.2
Same name and namespace in other branches
- 7.4 alias/hosting_alias.module \hosting_alias_form_data()
- 7.3 alias/hosting_alias.module \hosting_alias_form_data()
Alter the node form for a site to add the aliases and redirection items.
Parameters
$form: The form to alter, should come from hook_form_alter().
1 call to hosting_alias_form_data()
- hosting_alias_form_alter in alias/
hosting_alias.module - Implementation of hook_form_alter().
File
- alias/
hosting_alias.module, line 91 - Allow sites to have domain aliases that they can be accessed with.
Code
function hosting_alias_form_data(&$form, &$form_state) {
if (user_access('create site aliases')) {
// List the automatic aliasses first.
$automatic_aliases = hosting_alias_get_aliases($form['#node'], HOSTING_ALIAS_AUTOMATIC);
if (sizeof($automatic_aliases)) {
foreach ($automatic_aliases as $link) {
$links[] = l($link, "http://{$link}");
}
$form['aliases_automatic'] = array(
'#type' => 'item',
'#title' => t('Automatic domain aliases'),
'#value' => implode(', ', $links),
'#weight' => 10,
);
}
// Add a wrapper for the aliases and more button.
$form['aliases_wrapper'] = array(
'#tree' => FALSE,
'#title' => t('Domain Aliases'),
'#type' => 'fieldset',
'#prefix' => '<div class="clear-block" id="hosting-aliases-wrapper">',
'#suffix' => '</div>',
);
$form['aliases_wrapper']['aliases'] = array(
'#prefix' => '<div id="hosting-aliases">',
'#suffix' => '</div>',
'#tree' => TRUE,
);
// Get the list of existing aliases, either from form_state or the node.
if (isset($form_state['aliases'])) {
$aliases = array_filter($form_state['aliases']);
}
elseif (isset($form['#node']->aliases)) {
$aliases = array_filter($form['#node']->aliases);
}
else {
$aliases = array();
}
// Figure out the alias count
if (isset($form_state['alias_count'])) {
$alias_count = $form_state['alias_count'] + 1;
}
else {
$alias_count = max(1, empty($aliases) ? 1 : count($aliases) + 1);
}
// Add alias textfields
for ($delta = 0; $delta < $alias_count; $delta++) {
$form['aliases_wrapper']['aliases'][$delta] = array(
'#type' => 'textfield',
'#default_value' => $aliases[$delta],
);
}
// "Add Alias" button
$form['aliases_wrapper']['add_alias'] = array(
'#type' => 'submit',
'#value' => t('Add an alias'),
'#description' => t("Click here to add another alias."),
'#weight' => 1,
'#submit' => array(
'hosting_alias_add_alias_submit',
),
// If no javascript action.
'#ahah' => array(
'path' => 'hosting_alias/js',
'wrapper' => 'hosting-aliases-wrapper',
'method' => 'replace',
'effect' => 'fade',
),
);
// Redirection Domain
$options = array();
$options[0] = t('No redirection');
if (isset($form['#node']->title)) {
$options[$form['#node']->title] = $form['#node']->title;
}
if (!empty($aliases)) {
$options += array_combine($aliases, $aliases);
}
if (!empty($automatic_aliases)) {
$options += array_combine($automatic_aliases, $automatic_aliases);
}
$default = isset($form_state['values']['redirection']) ? $form_state['values']['redirection'] : $form['#node']->redirection;
$form['aliases_wrapper']['redirection'] = array(
'#type' => 'select',
'#title' => t('Redirect all domain aliases to'),
'#options' => $options,
'#default_value' => $default,
'#weight' => -1,
);
return $form;
}
}