You are here

function dfp_admin_settings in Doubleclick for Publishers (DFP) 7.2

Same name and namespace in other branches
  1. 7 dfp.admin.inc \dfp_admin_settings()

Form builder for the global DFP settings form.

1 string reference to 'dfp_admin_settings'
dfp_menu in ./dfp.module
Implements hook_menu().

File

./dfp.admin.inc, line 11
Admin forms and functinality for DFP ads.

Code

function dfp_admin_settings($form, $form_state) {

  // Make sure that all the necessary files are included even on ajax callbacks.
  form_load_include($form_state, 'inc', 'dfp', 'plugins/export_ui/dfp_ctools_export_ui');
  $form['settings'] = array(
    '#type' => 'vertical_tabs',
  );
  $form['#validate'][] = 'dfp_admin_form_validate';
  $form['#submit'][] = 'dfp_admin_form_submit';

  // Default tag settings.
  $form['global_tag_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Global Tag Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#group' => 'settings',
    '#attached' => array(
      'js' => array(
        'vertical-tabs' => drupal_get_path('module', 'dfp') . '/dfp.admin.js',
      ),
    ),
  );
  $form['global_tag_settings']['dfp_network_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Network ID'),
    '#default_value' => variable_get('dfp_network_id', ''),
    '#required' => TRUE,
    '#description' => t('The Network ID to use on all tags. According to Google this value should begin with a /.'),
  );
  $form['global_tag_settings']['dfp_default_adunit'] = array(
    '#type' => 'textfield',
    '#title' => t('Default Ad Unit Pattern'),
    '#required' => FALSE,
    '#maxlength' => 255,
    '#default_value' => variable_get('dfp_default_adunit', ''),
    '#description' => t('Use the tokens below to define how the default ad unit should display. This can be overridden on each tag. The network id will be included automatically. Example: [current-page:url:args:value:0]/[current-page:url:args:value:1]/[dfp_tag:slot]'),
  );
  $form['global_tag_settings']['dfp_click_url'] = array(
    '#type' => 'textfield',
    '#title' => t('DFP Click URL (Sync mode only)'),
    '#default_value' => variable_get('dfp_click_url', ''),
    '#description' => t('Sets a click URL on each DFP tag. Useful for intercepting ad click calls for reporting. Values beginning with http:// are treated as absolute; otherwise relative to current site domain.'),
    '#states' => array(
      'enabled' => array(
        'input[name="dfp_async_rendering"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  $form['global_tag_settings']['tokens'] = array(
    '#theme' => 'token_tree',
    '#token_types' => array(
      'dfp_tag',
      'node',
      'term',
      'user',
    ),
    '#global_types' => TRUE,
    '#click_insert' => TRUE,
    '#dialog' => TRUE,
  );
  $form['global_tag_settings']['dfp_async_rendering'] = array(
    '#type' => 'checkbox',
    '#title' => t('Render ads asynchronously'),
    '#default_value' => variable_get('dfp_async_rendering', 1),
    '#description' => t('This can speed up page rendering time by loading page content without waiting for ads to load.'),
  );
  $form['global_tag_settings']['dfp_disable_init_load'] = array(
    '#type' => 'checkbox',
    '#title' => t('Disable initial ad load'),
    '#default_value' => variable_get('dfp_disable_init_load', 0),
    '#description' => t('(Async mode only) Disables the initial fetch of ads from Google when the page is first loaded. Calls to refresh() can still be used to fetch ads.'),
    '#states' => array(
      'enabled' => array(
        'input[name="dfp_async_rendering"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['global_tag_settings']['dfp_single_request'] = array(
    '#type' => 'checkbox',
    '#title' => t('Combine all ad requests into a single request'),
    '#default_value' => variable_get('dfp_single_request', 1),
    '#description' => t('This can speed up page rendering time by limiting the number of external requests.'),
  );
  $form['global_tag_settings']['dfp_enable_ad_categories'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable DFP Ad Categories'),
    '#default_value' => variable_get('dfp_enable_ad_categories', 0),
    '#description' => t('Example: if you have an "animals" vocabulary and you want to target the same ads to "dogs", "cats" and "hamsters" you can edit each of those terms and set the DFP Ad Category to "pets". Whenever the taxonomy terms are included as targeting values, anything tagged "cats" will target "pets" instead.'),
  );
  if (!module_exists('taxonomy')) {
    $form['global_tag_settings']['dfp_enable_ad_categories']['disabled'] = TRUE;
    $form['global_tag_settings']['dfp_enable_ad_categories']['#default_value'] = 0;
    $form['global_tag_settings']['dfp_enable_ad_categories']['#description'] .= t('This requires the taxonomy module which is currently disabled.');
  }
  $bundles = field_info_bundles('taxonomy_term');
  $options = array();
  foreach ($bundles as $key => $value) {
    if ($key != 'dfp_ad_categories') {
      $options[$key] = $value['label'];
    }
  }
  $form['global_tag_settings']['dfp_enable_ad_categories_bundles'] = array(
    '#type' => 'checkboxes',
    '#options' => $options,
    '#prefix' => '<div style="margin-left: 20px">',
    '#suffix' => '</div>',
    '#default_value' => variable_get('dfp_enable_ad_categories_bundles', array()),
    '#description' => t('Select the vocabularies on which DFP Ad Categories should be enabled.'),
    '#states' => array(
      'visible' => array(
        'input[name="dfp_enable_ad_categories"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['global_tag_settings']['dfp_token_cache_enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t("Enable DFP Token cache"),
    '#disabled' => !module_exists('entity_modified'),
    '#default_value' => module_exists('entity_modified') ? variable_get("dfp_token_cache_enabled", TRUE) : FALSE,
    '#description' => t('DFP custom cache for token replacements. Requires Entity Modified module.'),
  );
  $form['global_tag_settings']['dfp_token_cache_lifetime'] = array(
    '#type' => 'textfield',
    '#title' => t("Token cache lifetime"),
    '#size' => 6,
    '#default_value' => variable_get("dfp_token_cache_lifetime", 0),
    '#description' => t('The time, in seconds, that the DFP token cache will be valid for. The token cache will always be cleared at the next system cron run after this time period, or when this form is saved.'),
    '#states' => array(
      'visible' => array(
        'input[name="dfp_token_cache_enabled"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );

  // Global display options.
  $form['global_display_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Global Display Options'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#group' => 'settings',
  );
  $form['global_display_options']['dfp_default_slug'] = array(
    '#type' => 'textfield',
    '#title' => t('Global Slug'),
    '#default_value' => variable_get('dfp_default_slug', ''),
    '#required' => FALSE,
    '#description' => t('Slug all ad tags with this label. Example: Advertisement', array(
      '@tag' => '<none>',
    )),
  );
  $form['global_display_options']['dfp_collapse_empty_divs'] = array(
    '#type' => 'radios',
    '#title' => t('Collapse empty divs'),
    '#default_value' => variable_get('dfp_collapse_empty_divs', 1),
    '#options' => array(
      0 => t('Never'),
      1 => t('Collapse only if no ad is served'),
      2 => t('Expand only if an ad is served'),
    ),
    '#description' => t('<dl><dt>Never</dt><dd>Never collapse ad slots.</dd><dt>Collapse only</dt><dd>Collapse before any ad is loaded. Useful if ad slots will get filled most of the time.</dd><dt>Expand only</dt><dd>Collapse all divs on the page before any ads are fetched and expand if an ad is loaded into the ad slot. Useful if ad slots will stay empty most of the time.</dd></dl>'),
  );
  $form['global_display_options']['dfp_slug_placement'] = array(
    '#type' => 'checkbox',
    '#title' => t('Hide slug if no ad is served (recommended)'),
    '#default_value' => variable_get('dfp_slug_placement', 1),
    '#states' => array(
      'visible' => array(
        'input[name="dfp_collapse_empty_divs"]' => array(
          '!value' => 0,
        ),
      ),
    ),
  );
  $form['global_display_options']['dfp_set_centering'] = array(
    '#type' => 'checkbox',
    '#title' => t('Set DFP Ad Centering'),
    '#default_value' => variable_get('dfp_set_centering', 0),
    '#description' => t('Enables/disables centering of ads. This mode must be set before the service is enabled. Centering is disabled by default. In legacy gpt_mobile.js, centering is enabled by default.'),
  );

  // Global targeting options.
  $form['targeting_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Global Targeting'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#group' => 'settings',
  );
  $existing_targeting = _dfp_targeting_get_existing($form_state, variable_get('dfp_targeting', array()));
  _dfp_targeting_form($form['targeting_settings'], $existing_targeting);

  // @todo: Modify this to match "Global Targeting" using a table.
  // Global viewport breakpoints.
  $form['global_viewport_breakpoints'] = array(
    '#type' => 'fieldset',
    '#title' => t('Global Viewports'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#group' => 'settings',
  );
  $form['global_viewport_breakpoints']['dfp_viewport_help'] = array(
    '#prefix' => '<div class="dfp-viewport-help">',
    '#markup' => t('Mobile is the default so any other values will override mobile when the value entered is greater than the width of the window.'),
    '#suffix' => '</div>',
  );

  // Add the ability to set a breakpoint target based on desktop, tablet, and
  // mobile breakpoints. Mobile will be the default value.
  foreach (_dfp_targeting_viewport_breakpoints() as $viewport) {
    $form['global_viewport_breakpoints']['dfp_viewport_' . $viewport . '_breakpoint'] = array(
      '#type' => 'textfield',
      '#title' => strtoupper(t($viewport)),
      '#default_value' => variable_get('dfp_viewport_' . $viewport . '_breakpoint', ''),
      '#attributes' => array(
        'maxlength' => 4,
        'size' => 4,
      ),
      '#size' => 4,
      '#description' => t('The value entered will be compared the the clientWidth using: ">".'),
    );
  }

  // AdTest Settings
  $form['adtest'] = array(
    '#type' => 'fieldset',
    '#title' => t('Ad Test Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#group' => 'settings',
  );
  $form['adtest']['dfp_adtest_adunit'] = array(
    '#type' => 'textfield',
    '#title' => t('Ad Unit Pattern for Ad Tests'),
    '#description' => t('Override the Ad Unit value for all the ad tags on a page by adding ?adtest=true to the URL. Use the tokens below to define how the ad unit should display. Example: [dfp_tag:network_id]/test/[dfp_tag:slot]'),
    '#default_value' => variable_get('dfp_adtest_adunit', ''),
  );
  $form['adtest']['tokens'] = array(
    '#theme' => 'token_tree',
    '#token_types' => array(
      'dfp_tag',
      'node',
      'term',
      'user',
    ),
    '#global_types' => TRUE,
    '#click_insert' => TRUE,
    '#dialog' => TRUE,
  );

  // Google Tag Manager.
  $form['gtm'] = array(
    '#type' => 'fieldset',
    '#title' => t('Google Tag Manager'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#weight' => 30,
    '#group' => 'settings',
  );
  $form['gtm']['dfp_gtm_container_id'] = array(
    '#type' => 'textfield',
    '#title' => t('GTM Container ID'),
    '#default_value' => variable_get('dfp_gtm_container_id', ''),
    '#required' => FALSE,
    '#description' => t('Your Google tag manager container id, without the GTM- prefix'),
  );
  $form['gtm']['dfp_gtm_admin_pages'] = array(
    '#type' => 'checkbox',
    '#title' => t('Ignore admin pages'),
    '#default_value' => variable_get('dfp_gtm_admin_pages', TRUE),
    '#description' => t('Prevent loading ads on admin pages.'),
  );
  return system_settings_form($form);
}