@@ -332,169 +332,38 @@ function dosomething_helpers_form_extras(&$form, &$form_state) {
332332
333333 // If this is a node create form, display help text and exit out of extras.
334334 if (!isset($form['nid']['#value'])) {
335- $form['custom'] = array(
336- '#markup' => t('The signup data form and custom settings for this !type will be available upon save.', array('!type' => $type)),
337- '#weight' => 60,
338- );
339335 return;
340336 }
341-
342- // Set prefix for custom variables.
343- $prefix = dosomething_helpers_get_custom_var_prefix($type, $form['nid']['#value']);
344337 $form['custom'] = array(
345338 '#type' => 'fieldset',
346339 '#title' => t('Custom settings'),
347340 '#weight' => 80,
348341 '#collapsible' => TRUE,
349342 '#collapsed' => TRUE,
350343 );
351- $pitch_page_label = $prefix . 'pitch_page_label';
352- $form['custom'][$pitch_page_label] = array(
353- '#type' => 'textfield',
354- '#title' => t('Signup Form Button Label'),
355- '#default_value' => variable_get($pitch_page_label),
356- '#description' => t('If set, this will override the label on the signup form.'),
357- );
358- $form['custom']['styles'] = array(
344+ $form['custom']['optins'] = array(
359345 '#type' => 'fieldset',
360- '#title' => t('Styles'),
346+ '#title' => t('Third Party Opt-ins'),
347+ '#description' => t('Custom campaign opt-in values.'),
361348 '#collapsible' => TRUE,
362349 '#collapsed' => TRUE,
363350 );
364- $alt_color = $prefix . 'alt_color';
365- $form['custom']['styles'][$alt_color] = array(
351+ $form['custom']['optins']['mailchimp_grouping_id'] = array(
366352 '#type' => 'textfield',
367- '#title' => t('Alt color'),
368- '#default_value' => variable_get($alt_color),
369- '#field_prefix' => '#',
370- '#size' => 6,
353+ '#title' => t('MailChimp Grouping ID'),
354+ '#default_value' => variable_get('dosomething_signup_nid_' . $form['nid']['#value'] . '_mailchimp_grouping_id'),
355+ '#disabled' => TRUE,
371356 );
372-
373- if ($type == 'campaign') {
374- $form['custom']['optins'] = array(
375- '#type' => 'fieldset',
376- '#title' => t('Third Party Opt-ins'),
377- '#description' => t('Custom campaign opt-in values.'),
378- '#collapsible' => TRUE,
379- '#collapsed' => TRUE,
380- );
381- $form['custom']['optins']['mailchimp_grouping_id'] = array(
382- '#type' => 'textfield',
383- '#title' => t('MailChimp Grouping ID'),
384- '#default_value' => variable_get('dosomething_signup_nid_' . $form['nid']['#value'] . '_mailchimp_grouping_id'),
385- '#disabled' => TRUE,
386- );
387- $form['custom']['optins']['mailchimp_group_name'] = array(
388- '#type' => 'textfield',
389- '#title' => t('MailChimp Group Name'),
390- '#default_value' => variable_get('dosomething_signup_nid_' . $form['nid']['#value'] . '_mailchimp_group_name'),
391- '#disabled' => TRUE,
392- );
393- $form['custom']['optins']['mobilecommons'] = array(
394- '#type' => 'textfield',
395- '#title' => t('MobileCommons Opt-in Path'),
396- '#default_value' => variable_get('dosomething_signup_nid_' . $form['nid']['#value'] . '_mobilecommons_id'),
397- '#disabled' => TRUE,
398- );
399- }
400-
401- $form['#submit'][] = 'dosomething_helpers_save_custom_vars';
402- }
403-
404- /**
405- * Returns string of prefix used to identify a campaign or campaign group's custom variables.
406- */
407- function dosomething_helpers_get_custom_var_prefix($type, $nid) {
408- return "dosomething_{$type}_nid_{$nid}_";
409- }
410-
411- /**
412- * Saves custom variables.
413- */
414- function dosomething_helpers_save_custom_vars(&$form, &$form_state) {
415- $values = $form_state['values'];
416- $nid = $values['nid'];
417- // Gather all possible custom vars.
418- $type = $form['type']['#value'];
419- $prefix = dosomething_helpers_get_custom_var_prefix($type, $nid);
420- $variables = array(
421- 'alt_color',
422- 'alt_bg_fid',
423- 'pitch_page_label',
357+ $form['custom']['optins']['mailchimp_group_name'] = array(
358+ '#type' => 'textfield',
359+ '#title' => t('MailChimp Group Name'),
360+ '#default_value' => variable_get('dosomething_signup_nid_' . $form['nid']['#value'] . '_mailchimp_group_name'),
361+ '#disabled' => TRUE,
362+ );
363+ $form['custom']['optins']['mobilecommons'] = array(
364+ '#type' => 'textfield',
365+ '#title' => t('MobileCommons Opt-in Path'),
366+ '#default_value' => variable_get('dosomething_signup_nid_' . $form['nid']['#value'] . '_mobilecommons_id'),
367+ '#disabled' => TRUE,
424368 );
425- foreach ($variables as $variable) {
426- $$variable = "{$prefix}{$variable}";
427- // Save alt color and pitch page label.
428- if (in_array($variable, array('alt_color', 'pitch_page_label'))) {
429- dosomething_helpers_save_custom_var($$variable, $values[$$variable]);
430- }
431- }
432-
433- // If a bg fid is set, or if a value already exists:
434- if (!empty($values[$alt_bg_fid]) || variable_get($alt_bg_fid)) {
435- // Save the bg fid.
436- dosomething_helpers_save_alt_bg_fid($alt_bg_fid, $nid, $values[$alt_bg_fid], $type);
437- }
438- }
439-
440- /**
441- * Handles saving a given variable $varname with given $value.
442- *
443- * @param string $varname
444- * The variable.name field to save (or delete).
445- * @param string $value
446- * The variable.value to save. If empty, deletes variable $varname.
447- */
448- function dosomething_helpers_save_custom_var($varname, $value) {
449- if (empty($value)) {
450- variable_del($varname);
451- }
452- else {
453- variable_set($varname, $value);
454- }
455- }
456-
457- /**
458- * Handles saving a given $fid as alt_bg_fid variable for given node $nid.
459- *
460- * @param int $nid
461- * The node nid associated with the fid.
462- * @param int $fid
463- * The file fid to save.
464- */
465- function dosomething_helpers_save_alt_bg_fid($varname, $nid, $fid, $type) {
466- // Get current value.
467- $current_value = variable_get($varname);
468- $module = "dosomething_{$type}";
469-
470- // If it's the same, nothing to see here. Keep moving.
471- if ($current_value == $fid) {
472- return;
473- }
474- // If we had a value and now we don't:
475- if (empty($fid) && is_numeric($current_value)) {
476- $file = file_load($current_value);
477- // Decrease the file's usage.
478- file_usage_delete($file, $module, 'node', $nid);
479- // Delete the variable.
480- variable_del($varname);
481- return;
482- }
483- // If we've made this far, we've got a new file to save.
484- $file = file_load($fid);
485- // And a value to set.
486- variable_set($varname, $fid);
487- // If file status not permanent, make it permanent.
488- if ($file->status != FILE_STATUS_PERMANENT) {
489- $file->status = FILE_STATUS_PERMANENT;
490- file_save($file);
491- }
492- // Increase file usage to avoid errors per https://drupal.org/comment/6866102.
493- file_usage_add($file, $module, 'node', $nid);
494- // If there was a file before:
495- if ($file = file_load($current_value)) {
496- // Decrease its usage.
497- file_usage_delete($file, $module, 'node', $nid);
498- }
499369}
500-
0 commit comments