function domain_source_form_alter in Domain Access 5
Same name and namespace in other branches
- 8 domain_source/domain_source.module \domain_source_form_alter()
- 6.2 domain_source/domain_source.module \domain_source_form_alter()
- 7.3 domain_source/domain_source.module \domain_source_form_alter()
- 7.2 domain_source/domain_source.module \domain_source_form_alter()
Implement hook_form_alter()
File
- domain_source/
domain_source.module, line 20 - Creates a source domain for linking to content from other domains.
Code
function domain_source_form_alter($form_id, &$form) {
// Apply to all node editing forms, but make sure we are not on the CCK field configuration form.
// See http://drupal.org/node/186624.
if ($form['#id'] == 'node-form' && !$form['#node']->cck_dummy_node_form) {
global $_domain;
$options = array();
$domains = domain_domains();
$show = FALSE;
if (user_access('set domain access')) {
$show = TRUE;
foreach ($domains as $domain) {
$options[$domain['domain_id']] = check_plain($domain['sitename']);
}
}
else {
if (user_access('view domain publishing') && variable_get('domain_options', 0) == 3) {
global $user;
// Get the user's allowed domains.
foreach ($domains as $domain) {
if ($user->domain_user[$domain['domain_id']] != 0 && $domain['domain_id'] == $user->domain_user[$domain['domain_id']]) {
$options[$domain['domain_id']] = $domain['sitename'];
}
}
// Is this node assigned to a source that the user can control?
$source = $form['#node']->domain_source;
if (isset($source)) {
if ($user->domain_user[$source] == $source) {
$show = TRUE;
}
else {
$form['domain']['domain_source_notes'] = array(
'#value' => '<label><b>' . t('Source domain:') . '</b></label><div class="description">' . t('This content is assigned to %domain and cannot be reassigned.', array(
'%domain' => $domains[$source]['sitename'],
)) . '</div>',
);
}
}
}
}
// Determine how to show the form element.
if ($show) {
$form['domain']['domain_source'] = array(
'#type' => 'select',
'#title' => t('Source domain'),
'#options' => $options,
'#default_value' => isset($form['#node']->domain_source) ? $form['#node']->domain_source : $_domain['domain_id'],
'#description' => t('This affiliate will be used to write links to this content from other affiliates, as needed.'),
);
}
else {
$form['domain']['domain_source'] = array(
'#type' => 'value',
'#value' => isset($form['#node']->domain_source) ? $form['#node']->domain_source : $_domain['domain_id'],
);
}
}
else {
if ($form_id == 'domain_content_form') {
global $_domain;
$options = array();
$domains = domain_domains();
$show = FALSE;
if (user_access('set domain access')) {
foreach ($domains as $domain) {
$options[$domain['domain_id']] = $domain['sitename'];
}
$form['domain']['domain_source'] = array(
'#type' => 'select',
'#title' => t('Source domain'),
'#options' => $options,
'#default_value' => $_domain['domain_id'],
'#description' => t('This affiliate will be linked to from other affiliates, as needed.'),
);
$form['#validate']['domain_source_validate'] = array();
$form['#submit']['domain_source_update_nodes'] = array();
}
}
}
}