Skip to content
This repository was archived by the owner on Oct 29, 2020. It is now read-only.

Commit b06f6a8

Browse files
Merge pull request #2752 from aaronschachter/signup_form_text_variable
Signup Form copy text variable
2 parents 21eb4af + 9ebb2f0 commit b06f6a8

File tree

4 files changed

+43
-160
lines changed

4 files changed

+43
-160
lines changed

lib/modules/dosomething/dosomething_campaign/dosomething_campaign.module

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ function dosomething_campaign_admin_paths() {
225225
* Page access callback for admin custom settings form.
226226
*/
227227
function dosomething_campaign_admin_custom_settings_page_access($node) {
228-
if ($node->type != 'campaign') { return FALSE; }
228+
$settings_nodes = array('campaign', 'campaign_group');
229+
if (!in_array($node->type, $settings_nodes)) { return FALSE; }
229230

230231
return (user_access('edit any campaign content') || user_access('bypass node access'));
231232
}

lib/modules/dosomething/dosomething_campaign/dosomething_campaign.theme.inc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,8 @@ function dosomething_campaign_preprocess_signup_data_form(&$vars) {
313313
* The corresponding entity wrapper for the node in $vars.
314314
*/
315315
function dosomething_campaign_preprocess_pitch_page(&$vars, &$wrapper) {
316-
// Check for a signup button label override.
317-
$label_varname = 'dosomething_campaign_nid_' . $vars['nid']. '_pitch_page_label';
318-
$label = variable_get($label_varname, '');
316+
// Check for a signup button copy override.
317+
$label = $vars['campaign']->variables['signup_button_copy'];
319318
// If no override:
320319
if (empty($label)) {
321320
// Don't pass the $label parameter, using the default defined in function.

lib/modules/dosomething/dosomething_helpers/dosomething_helpers.module

Lines changed: 18 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -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-

lib/modules/dosomething/dosomething_helpers/dosomething_helpers.variable.inc

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ function dosomething_helpers_variable_form($form, &$form_state, $node) {
3939
'#default_value' => $vars['alt_image_campaign_cover_nid'],
4040
'#size' => 6,
4141
);
42+
$form['styles']['signup_button_copy'] = array(
43+
'#type' => 'textfield',
44+
'#title' => t('Signup Button Copy'),
45+
'#description' => t('Override the copy on the signup button.'),
46+
'#default_value' => $vars['signup_button_copy'],
47+
'#size' => 20,
48+
);
4249
$form['actions'] = array(
4350
'#type' => 'actions',
4451
'submit' => array(
@@ -61,15 +68,19 @@ function dosomething_helpers_variable_form_submit(&$form, &$form_state) {
6168
foreach ($values as $name => $value) {
6269
// Save to the variable table.
6370
dosomething_helpers_set_variable($node, $name, $value);
64-
6571
}
72+
drupal_set_message("Updated.");
6673
}
6774

68-
function dosomething_helpers_get_default_variables() {
75+
/**
76+
* Returns array of all variable names.
77+
*/
78+
function dosomething_helpers_get_variable_names() {
6979
return array(
70-
'alt_bg_fid' => NULL,
71-
'alt_color' => NULL,
72-
'alt_image_campaign_cover_nid' => NULL,
80+
'alt_bg_fid',
81+
'alt_color',
82+
'alt_image_campaign_cover_nid',
83+
'signup_button_copy',
7384
);
7485
}
7586

@@ -80,7 +91,10 @@ function dosomething_helpers_get_default_variables() {
8091
* Keyed by the variable name.
8192
*/
8293
function dosomething_helpers_get_variables($nid) {
83-
$vars = array();
94+
// Initialize array with NULL defaults.
95+
foreach (dosomething_helpers_get_variable_names() as $name) {
96+
$vars[$name] = NULL;
97+
}
8498
// Query for variable records for given $node.
8599
$result = db_select('dosomething_helpers_variable', 'v')
86100
->fields('v')
@@ -91,7 +105,7 @@ function dosomething_helpers_get_variables($nid) {
91105
foreach ($result as $record) {
92106
$vars[$record->name] = $record->value;
93107
}
94-
return array_merge(dosomething_helpers_get_default_variables(), $vars);
108+
return $vars;
95109
}
96110

97111
/**

0 commit comments

Comments
 (0)