CRM-15578 - Mailing.create API - Set defaults that match UX
authorTim Otten <totten@civicrm.org>
Fri, 6 Feb 2015 19:31:15 +0000 (11:31 -0800)
committerTim Otten <totten@civicrm.org>
Mon, 9 Feb 2015 11:26:50 +0000 (03:26 -0800)
api/v3/Mailing.php
tests/phpunit/api/v3/MailingTest.php

index 42347376b9aa30b4cdf5b26aff29ce527f17bf87..b1711efdf94cc1816c6753932755ed07634da2a7 100755 (executable)
@@ -107,6 +107,32 @@ function _civicrm_api3_mailing_create_spec(&$params) {
   $params['created_id']['api.default'] = 'user_contact_id';
   $params['api.mailing_job.create']['api.default'] = 1;
   $params['api.mailing_job.create']['title'] = 'Schedule Mailing?';
+
+  $params['override_verp']['api.default'] = !CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
+    'track_civimail_replies', NULL, FALSE
+  );
+  $params['visibility']['api.default'] = 'Public Pages';
+  $params['dedupe_email']['api.default'] = TRUE;
+
+  $params['forward_replies']['api.default'] = FALSE;
+  $params['auto_responder']['api.default'] = FALSE;
+  $params['open_tracking']['api.default'] = TRUE;
+  $params['url_tracking']['api.default'] = TRUE;
+
+  $params['header_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('Header', '');
+  $params['footer_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('Footer', '');
+  $params['optout_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('OptOut', '');
+  $params['reply_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('Reply', '');
+  $params['resubscribe_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('Resubscribe', '');
+  $params['unsubscribe_id']['api.default'] = CRM_Mailing_PseudoConstant::defaultComponent('Unsubscribe', '');
+
+  $defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1');
+  foreach ($defaultAddress as $id => $value) {
+    if (preg_match('/"(.*)" <(.*)>/', $value, $match)) {
+      $params['from_email']['api.default'] = $match[2];
+      $params['from_name']['api.default'] = $match[1];
+    }
+  }
 }
 
 /**
index c01ab57af2d3093ff6316662086be3fd61d420e9..1f6cdd95acf1e2c313d28b9afa1a31bf2615e066 100755 (executable)
@@ -52,6 +52,8 @@ class api_v3_MailingTest extends CiviUnitTestCase {
       'body_html' => "<p>This is {contact.display_name}</p>",
       'name' => 'mailing name',
       'created_id' => $this->_contactID,
+      'header_id' => '',
+      'footer_id' => '',
     );
   }