You are here

function ad_channel_form_alter in Advertisement 5.2

Same name and namespace in other branches
  1. 6.3 channel/ad_channel.module \ad_channel_form_alter()
  2. 6.2 channel/ad_channel.module \ad_channel_form_alter()
  3. 7 channel/ad_channel.module \ad_channel_form_alter()

Implementation of hook_form_alter(). Generate a form for selecting channels to associate with an advertisement.

File

channel/ad_channel.module, line 124
Ad Channel

Code

function ad_channel_form_alter($form_id, &$form) {
  if (isset($form['type']) && $form_id == 'ad_node_form') {
    $fieldset = FALSE;
    $containers = _ad_channel_get_containers();
    foreach ($containers as $container) {
      $channels = _ad_channel_get_container_channels($container->conid);
      if (!empty($channels)) {
        if ($container->conid) {
          $fieldset = TRUE;
        }
        if ($fieldset) {
          $form['channel'][$container->conid] = array(
            '#type' => 'fieldset',
            '#title' => $container->name,
            '#collapsible' => FALSE,
            '#collapsed' => FALSE,
          );
        }
        foreach ($channels as $channel) {
          if (is_object($form['#node'])) {
            $node = $form['#node'];
            $default = isset($node->channel[$channel->chid]);
          }
          else {
            $default = 0;
          }
          $form['channel'][$container->conid]["channel-{$channel->chid}"] = array(
            '#type' => 'checkbox',
            '#title' => $channel->name,
            '#description' => $channel->description,
            '#default_value' => $default,
          );
        }
      }
    }
    if (is_array($form['channel']) && !empty($form['channel'])) {
      if (!empty($form['channel'])) {
        $form['channel'] += array(
          '#type' => 'fieldset',
          '#title' => t('Channels'),
          '#collapsible' => TRUE,
          '#collapsed' => FALSE,
        );
      }
      $form['channel']['#weight'] = -3;
      $form['channel']['#tree'] = TRUE;
    }
    $form['priority'] = array(
      '#type' => 'fieldset',
      '#access' => user_access('configure ad premiere status'),
      '#title' => t('Priority'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['priority']['premiere'] = array(
      '#type' => 'checkbox',
      '#access' => user_access('configure ad premiere status'),
      '#title' => t('Premiere'),
      '#description' => t('An active premiere advertisement will ovverride all other non-premiere advertisements in the same channel.  As long as one or more premiere advertisements are active in a channel, non-premiere advertisements will not be displayed in that channel.'),
      '#default_value' => $node->premiere,
    );
    $form['priority']['#weight'] = -1;
  }
}