Mailing API - Expose option list for `header_id` and `footer_id`
authorTim Otten <totten@civicrm.org>
Wed, 18 Sep 2019 17:15:36 +0000 (13:15 -0400)
committerTim Otten <totten@civicrm.org>
Wed, 18 Sep 2019 17:15:36 +0000 (13:15 -0400)
CRM/Mailing/DAO/Mailing.php
tests/phpunit/api/v3/MailingTest.php
xml/schema/Mailing/Mailing.xml

index a3bc2c85c9fccb145925b0e9f9e1287ef8e1473b..9f727b0c260d91278d80eb6372b2118868dc8293 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Mailing/Mailing.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:c294c497dac6129fe311fe8484e1e975)
+ * (GenCodeChecksum:aa54484f6e9b8d5ad8e75680f95cfc67)
  */
 
 /**
@@ -405,6 +405,12 @@ class CRM_Mailing_DAO_Mailing extends CRM_Core_DAO {
           'bao' => 'CRM_Mailing_BAO_Mailing',
           'localizable' => 0,
           'FKClassName' => 'CRM_Mailing_DAO_MailingComponent',
+          'pseudoconstant' => [
+            'table' => 'civicrm_mailing_component',
+            'keyColumn' => 'id',
+            'labelColumn' => 'name',
+            'condition' => 'component_type = "Header"',
+          ],
         ],
         'footer_id' => [
           'name' => 'footer_id',
@@ -417,6 +423,12 @@ class CRM_Mailing_DAO_Mailing extends CRM_Core_DAO {
           'bao' => 'CRM_Mailing_BAO_Mailing',
           'localizable' => 0,
           'FKClassName' => 'CRM_Mailing_DAO_MailingComponent',
+          'pseudoconstant' => [
+            'table' => 'civicrm_mailing_component',
+            'keyColumn' => 'id',
+            'labelColumn' => 'name',
+            'condition' => 'component_type = "Footer"',
+          ],
         ],
         'reply_id' => [
           'name' => 'reply_id',
index f8e1d8bc2c9f349c6bff6d6e5d52cd91dc11e86d..6434ffbfd1abdf49f4333a6310d985f6ae539c19 100644 (file)
@@ -132,6 +132,16 @@ class api_v3_MailingTest extends CiviUnitTestCase {
     $this->assertTrue(isset($types['values']['traditional']));
   }
 
+  /**
+   * Check that default header+footer are available.
+   */
+  public function testHeaderFooterOptions() {
+    $headers = $this->callAPISuccess('Mailing', 'getoptions', ['field' => 'header']);
+    $this->assertTrue(in_array('Mailing Header', $headers['values']));
+    $footers = $this->callAPISuccess('Mailing', 'getoptions', ['field' => 'footer']);
+    $this->assertTrue(in_array('Mailing Footer', $footers['values']));
+  }
+
   /**
    * The `template_options` field should be treated a JSON object.
    *
index 0ef0930f0a87702b6b5907387abfa703fafba538..e4f8a0eaeec44211cfe309d8c78d6adaeb7d3db9 100644 (file)
     <name>header_id</name>
     <title>Mailing Header</title>
     <type>int unsigned</type>
+    <pseudoconstant>
+      <table>civicrm_mailing_component</table>
+      <keyColumn>id</keyColumn>
+      <labelColumn>name</labelColumn>
+      <condition>component_type = "Header"</condition>
+    </pseudoconstant>
     <comment>FK to the header component.</comment>
   </field>
   <foreignKey>
     <name>footer_id</name>
     <title>Mailing Footer</title>
     <type>int unsigned</type>
+    <pseudoconstant>
+      <table>civicrm_mailing_component</table>
+      <keyColumn>id</keyColumn>
+      <labelColumn>name</labelColumn>
+      <condition>component_type = "Footer"</condition>
+    </pseudoconstant>
     <comment>FK to the footer component.</comment>
   </field>
   <foreignKey>