You are here

function dfp_admin_form_submit in Doubleclick for Publishers (DFP) 7

Same name and namespace in other branches
  1. 7.2 dfp.admin.inc \dfp_admin_form_submit()

Submit handler ensures that targeting values are saved with the "dfp" prefix.

1 string reference to 'dfp_admin_form_submit'
dfp_admin_settings in ./dfp.admin.inc
Form builder for the global DFP settings form.

File

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

Code

function dfp_admin_form_submit($form, &$form_state) {

  // Since the targeting form is reusable it isn't already in the settings
  // array so we grab it here.
  $form_state['values']['dfp_targeting'] = $form_state['values']['targeting'];
  unset($form_state['values']['targeting']);

  // Attach (or delete) an instance of the dfp_ad_categories term_reference
  // field for each vocabulary that should (or should not) have DFP Ad
  // Categories enabled.
  foreach ($form_state['values']['dfp_enable_ad_categories_bundles'] as $bundle => $enable) {
    $existing_instance = field_read_instance('taxonomy_term', 'field_dfp_ad_categories', $bundle);
    $enable = $enable && !$existing_instance && $form_state['values']['dfp_enable_ad_categories'];
    if ($enable) {
      $instance = array(
        'field_name' => 'field_dfp_ad_categories',
        'entity_type' => 'taxonomy_term',
        'label' => t('DFP Ad Category'),
        'bundle' => $bundle,
        'required' => FALSE,
        'widget' => array(
          'type' => 'options_select',
        ),
      );
      field_create_instance($instance);
    }
    elseif (!$enable && $existing_instance) {

      // Delete this field instance, but be certain not to delete the field.
      field_delete_instance($existing_instance, FALSE);
    }
  }
}