You are here

function google_admanager_admin_settings_form in DFP Small Business (Google Ad Manager) 6.3

Same name and namespace in other branches
  1. 5 google_admanager.module \google_admanager_admin_settings_form()
  2. 6 google_admanager.module \google_admanager_admin_settings_form()
  3. 6.2 google_admanager.admin.inc \google_admanager_admin_settings_form()
  4. 7.2 google_admanager.admin.inc \google_admanager_admin_settings_form()

Implementation of hook_admin_settings() for configuring the module.

2 string references to 'google_admanager_admin_settings_form'
google_admanager_form_alter in ./google_admanager.module
Implementation of hook_form_alter().
google_admanager_menu in ./google_admanager.module
Implementation of hook_menu().

File

./google_admanager.admin.inc, line 47
Admin functionality.

Code

function google_admanager_admin_settings_form(&$form_state) {
  ctools_include('dependent');
  ctools_include('plugins');
  $form = array();
  $plugins = ctools_get_plugins('google_admanager', 'ad_providers');
  $methods = array_map('_google_admanager_admin_map_methods', $plugins);
  $form['google_admanager_delivery_method'] = array(
    '#type' => 'select',
    '#title' => t('Delivery method'),
    '#default_value' => variable_get('google_admanager_delivery_method', 'gam'),
    '#options' => $methods,
    '#description' => t('Determine the method on how the Ads will be delivered to the site.'),
  );
  foreach ($plugins as $name => $plugin) {
    if (isset($plugin['admin form']) && function_exists($plugin['admin form'])) {
      $conf = variable_get('google_admanager_' . $name, $plugin['defaults']);
      $settings = $plugin['admin form']($form_state, $conf);
      foreach (element_children($settings) as $key) {
        $settings[$key] = array_merge($settings[$key], array(
          '#process' => array(
            'ctools_dependent_process',
          ),
          '#dependency' => array(
            'edit-google-admanager-delivery-method' => array(
              $name,
            ),
          ),
        ));
      }
      $settings['#tree'] = TRUE;
      $form['google_admanager_' . $name] = $settings;
    }
  }
  $form_state['storage']['ad_slots'] = isset($form_state['storage']['ad_slots']) ? $form_state['storage']['ad_slots'] : variable_get('google_admanager_ad_slots', array_fill(0, 3, array(
    'name' => '',
    'width' => '',
    'height' => '',
  )));
  if (empty($form_state['storage']['ad_slots'])) {
    $form_state['storage']['ad_slots'] = array_fill(0, 3, array(
      'name' => '',
      'width' => '',
      'height' => '',
    ));
  }
  $form['google_admanager_ad_slots'] = array(
    '#type' => 'item',
    '#title' => t('Ad slots'),
    '#tree' => TRUE,
    '#theme' => 'google_admanager_ad_slots',
    '#element_validate' => array(
      '_google_admanager_admin_settings_ad_slots_clean',
    ),
  );
  foreach ($form_state['storage']['ad_slots'] as $id => $ad_slot) {
    $form['google_admanager_ad_slots'][$id]['name'] = array(
      '#type' => 'textfield',
      '#default_value' => !empty($ad_slot['name']) ? $ad_slot['name'] : '',
      '#size' => 60,
    );
    $form['google_admanager_ad_slots'][$id]['width'] = array(
      '#type' => 'textfield',
      '#default_value' => !empty($ad_slot['width']) ? $ad_slot['width'] : '',
      '#size' => 6,
    );
    $form['google_admanager_ad_slots'][$id]['height'] = array(
      '#type' => 'textfield',
      '#default_value' => !empty($ad_slot['height']) ? $ad_slot['height'] : '',
      '#size' => 6,
    );
    $form['google_admanager_ad_slots'][$id]['delete'] = array(
      '#type' => 'submit',
      '#value' => t('delete'),
      '#submit' => array(
        '_google_admanager_admin_settings_del_ad_slot',
      ),
      '#name' => 'google-admanager-ad-slot-delete-' . $id,
      '#key' => $id,
      '#disabled' => count($form_state['storage']['ad_slots']) == 1,
    );
  }
  $form['add_ad_slot'] = array(
    '#type' => 'submit',
    '#value' => t('Add slot'),
    '#submit' => array(
      '_google_admanager_admin_settings_add_ad_slot',
    ),
  );
  $form['google_admanager_noblock'] = array(
    '#type' => 'checkbox',
    '#title' => t('Don\'t create blocks'),
    '#default_value' => variable_get('google_admanager_noblock', FALSE),
    '#description' => t('This option allow you to use only superslot. Handful when you have dozens of ad slots or more. <strong>Switch on/off this option may reset blocks positions.</strong>'),
  );
  $form['google_admanager_noheader'] = array(
    '#type' => 'checkbox',
    '#title' => t('Don\'t output JavaScript into the header scope'),
    '#default_value' => variable_get('google_admanager_noheader', FALSE),
    '#description' => t('By default the required JavaScript code is placed in the \'header\' scope. For better performance, many user put that $scripts variable in the bottom of page.tpl.php, that prevents GAM from working. If you use this tweak, then enable this option, the required JavaScript is available in the $gam variable that you can put at the top of your page.tpl.php file.'),
  );
  $form['google_admanager_nodetype_attributes'] = array(
    '#type' => 'checkbox',
    '#title' => t('Expose node type as atttribute'),
    '#default_value' => variable_get('google_admanager_nodetype_attributes', FALSE),
    '#description' => t('This option allows you to target whole content types as an attribute within Google Ad Manager'),
  );
  if (module_exists('taxonomy')) {

    // Get an array of vocabularies
    $vocabs = taxonomy_get_vocabularies();

    // Build the form item defaults
    $vocab_form_item = array(
      '#title' => t('Expose vocabularies as attributes'),
      '#description' => t('Enabling a vocabulary will allow you to target terms within the vocabulary from Google Ad Manager'),
    );

    // If vocabs are empty, insert a prompt form item
    if (empty($vocabs)) {
      $form['google_admanager_vocab_attributes'] = array(
        '#type' => 'item',
        '#value' => '<span class="error">' . t('You must have at least 1 vocabulary for this feature to work.') . '</span>',
      ) + $vocab_form_item;
    }
    else {

      // Build a list of vocabularies as "vid => name" pairs
      $options = array();
      foreach ($vocabs as $v) {
        $options[$v->vid] = $v->name;
      }

      // Create a form item of checkboxes
      $form['google_admanager_vocab_attributes'] = array(
        '#type' => 'checkboxes',
        '#default_value' => variable_get('google_admanager_vocab_attributes', array()),
        '#options' => $options,
      ) + $vocab_form_item;
    }
  }
  $form_state['storage']['custom_vars'] = isset($form_state['storage']['custom_vars']) ? $form_state['storage']['custom_vars'] : variable_get('google_admanager_custom_variables', array_fill(0, 3, array(
    'key' => '',
    'value' => '',
  )));
  if (empty($form_state['storage']['custom_vars'])) {
    $form_state['storage']['custom_vars'] = array_fill(0, 3, array(
      'key' => '',
      'value' => '',
    ));
  }
  $form['custom_variables'] = array(
    '#type' => 'item',
    '#title' => t('Custom Variables'),
  );
  $form['custom_variables']['google_admanager_custom_variables'] = array(
    '#tree' => TRUE,
    '#element_validate' => array(
      '_google_admanager_admin_settings_custom_variables_clean',
    ),
    '#theme' => 'google_admanager_custom_variables',
    '#prefix' => '<div id="google-admanager-admin-settings-form-wrapper">',
    '#suffix' => '</div>',
  );
  foreach ($form_state['storage']['custom_vars'] as $key => $vars) {
    $form['custom_variables']['google_admanager_custom_variables'][$key]['key'] = array(
      '#type' => 'textfield',
      '#default_value' => $vars['key'],
      '#size' => 16,
    );
    $form['custom_variables']['google_admanager_custom_variables'][$key]['value'] = array(
      '#type' => 'textfield',
      '#default_value' => $vars['value'],
      '#size' => 64,
    );
    $form['custom_variables']['google_admanager_custom_variables'][$key]['delete'] = array(
      '#type' => 'submit',
      '#value' => t('delete'),
      '#submit' => array(
        '_google_admanager_admin_settings_del_variable',
      ),
      '#name' => 'openx-site-vars-delete-' . $key,
      '#key' => $key,
      '#disabled' => count($form_state['storage']['custom_vars']) == 1,
    );
  }
  $form['custom_variables']['add_row'] = array(
    '#type' => 'submit',
    '#value' => t('Add variable'),
    '#submit' => array(
      '_google_admanager_admin_settings_add_variable',
    ),
  );
  $form['custom_variables']['token_vars_tree'] = array(
    '#theme' => 'token_tree',
    '#token_types' => array(
      'node',
      'user',
    ),
  );
  return system_settings_form($form);
}