function ad_form_alter in Advertisement 6
Same name and namespace in other branches
- 5.2 ad.module \ad_form_alter()
- 5 ad.module \ad_form_alter()
- 6.3 ad.module \ad_form_alter()
- 6.2 ad.module \ad_form_alter()
- 7 ad.module \ad_form_alter()
Implementation of hook_form_alter().
File
- ./
ad.module, line 713 - An advertising system for Drupal powered websites.
Code
function ad_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'ad_node_form') {
$adtypes = ad_get_types('data');
if (isset($form['adtype']) && isset($form['adtype']['#value'])) {
$adtype = $form['adtype']['#value'];
if (isset($adtypes[$adtype])) {
// Valid advertisement type selected.
return;
}
}
if (sizeof($adtypes) == 1) {
// Auto select the appropriate advertisement type.
drupal_goto('node/add/ad/' . key($adtypes));
}
else {
foreach ($adtypes as $key => $adtype) {
$out = '<dt>' . l($adtype['name'], "node/add/ad/{$key}", array(
'title' => t('Add a !key', array(
'!key' => $adtype['name'],
)),
)) . '</dt>';
$out .= '<dd>' . $adtype['description'] . '</dd>';
$item[$key] = $out;
}
if (isset($item)) {
$output = t('Choose from the following advertisement types:');
$output .= '<dl>' . implode('', $item) . '</dl>';
}
else {
$output = t('You are not allowed to create advertisements.');
}
$form = array();
$form['select'] = array(
'#value' => $output,
);
$form['#tree'] = FALSE;
$form['#programmed'] = FALSE;
}
}
if ($form_id == 'taxonomy_form_vocabulary') {
// Remove taxonomy form options not applicable for ad groups.
if ($form['vid']['#value'] == _ad_get_vid()) {
$form['help_ad_vocab'] = array(
'#value' => t('This vocabulary was automatically created for use by the ad module. Only applicable options are available.'),
'#weight' => -1,
);
$form['nodes']['ad'] = array(
'#type' => 'checkbox',
'#title' => t('ad group'),
'#value' => 1,
'#attributes' => array(
'disabled' => '',
),
'#description' => t('Type %type is required to use this vocabulary.', array(
'%type' => t('ad group'),
)),
);
$form['tags']['#description'] = t('If enabled, ads are categorized by typing ad group names instead of choosing them from a list.');
$form['multiple']['#description'] = t('If enabled, allows ads to have more than one ad group (always true for free tagging).');
$form['required']['#description'] = t('If enabled, every ad <strong>must</strong> be assigned to at least one ad group.');
$form['hierarchy'] = array(
'#type' => 'value',
'#value' => 0,
);
unset($form['relations']);
}
else {
unset($form['nodes']['ad']);
}
}
else {
if ($form_id == 'taxonomy_form_term') {
if ($form['vid']['#value'] == _ad_get_vid()) {
$form['name']['#title'] = t('Ad group name');
$form['name']['#description'] = t('The name for this ad group. Example: "Linux".');
$form['description']['#description'] = t('A description of the ad group.');
$form['description']['#required'] = TRUE;
$form['weight']['#description'] = t('In listings, the heavier ad groups will sink and the lighter ad groups will be positioned nearer the top.');
unset($form['synonyms']);
}
}
}
}