You are here

function ad_owners_form_alter in Advertisement 6.3

Same name and namespace in other branches
  1. 6 owners/ad_owners.module \ad_owners_form_alter()
  2. 6.2 owners/ad_owners.module \ad_owners_form_alter()
  3. 7 owners/ad_owners.module \ad_owners_form_alter()

Implementation of hook_form_alter().

File

owners/ad_owners.module, line 118
Enhances the ad module to support ad owners.

Code

function ad_owners_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'ad_' . arg(4) . '_global_settings' || $form_id == 'ad_no_global_settings') {
    if (!isset($form['adtype'])) {
      $form['adtype'] = array(
        '#type' => 'value',
        '#value' => arg(4),
      );
    }
    $perms = ad_owners_default_permissions();
    $form['permissions'] = array(
      '#type' => 'fieldset',
      '#title' => t('Permissions'),
      '#collapsible' => TRUE,
      '#description' => t('Select which permissions will be automatically granted to new owners of <em>!type</em> advertisements, per role.  If a user is a member of multiple roles, he will get all default permissions defined for each role he is a member of.', array(
        '!type' => ad_get_types('name', arg(4)),
      )),
    );
    $roles = user_roles(TRUE);
    foreach ($roles as $rid => $role) {
      $defaults = variable_get("ad_default_permissions_{$rid}_" . $form['adtype']['#value'], $perms['default']);
      $form['permissions']["role-{$rid}"] = array(
        '#type' => 'fieldset',
        '#title' => $role,
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      $form['permissions']["role-{$rid}"]["default_permissions_{$rid}"] = array(
        '#type' => 'checkboxes',
        '#title' => t('Default permissions for users in the <em>!role</em> role', array(
          '!role' => $role,
        )),
        '#options' => drupal_map_assoc($perms['all']),
        '#default_value' => $defaults,
      );
    }
    if (isset($form['save'])) {
      $form['save']['#weight'] = 10;
    }
    if (isset($form['#submit']) && is_array($form['#submit'])) {
      $form['#submit'] = array_merge(array(
        'ad_owners_settings_submit',
      ), $form['#submit']);
    }
    else {
      $form['#submit'] = array(
        'ad_owners_settings_submit',
      );
    }
  }
}