From: eileen Date: Sun, 27 Oct 2019 22:17:13 +0000 (+1300) Subject: Add call to getSearchFieldMetadata X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2c3ccaa9e28c603d93690c9054941a2953073001;p=civicrm-core.git Add call to getSearchFieldMetadata --- diff --git a/CRM/Mailing/BAO/Query.php b/CRM/Mailing/BAO/Query.php index aadb018caf..348415c180 100644 --- a/CRM/Mailing/BAO/Query.php +++ b/CRM/Mailing/BAO/Query.php @@ -127,6 +127,21 @@ class CRM_Mailing_BAO_Query { } } + /** + * Get the metadata for fields to be included on the mailing search form. + * + * @throws \CiviCRM_API3_Exception + * + * @todo ideally this would be a trait included on the mailing search & advanced search + * rather than a static function. + */ + public static function getSearchFieldMetadata() { + $fields = []; + $metadata = civicrm_api3('Mailing', 'getfields', [])['values']; + $metadata = array_merge($metadata, civicrm_api3('MailingJob', 'getfields', [])['values']); + return array_intersect_key($metadata, array_flip($fields)); + } + /** * @param $query */ @@ -395,10 +410,14 @@ class CRM_Mailing_BAO_Query { /** * Add all the elements shared between Mailing search and advnaced search. * + * @param \CRM_Mailing_Form_Search $form * - * @param CRM_Core_Form $form + * @throws \CiviCRM_API3_Exception */ public static function buildSearchForm(&$form) { + $form->addSearchFieldMetadata(['Mailing' => self::getSearchFieldMetadata()]); + $form->addFormFieldsFromMetadata(); + // mailing selectors $mailings = CRM_Mailing_BAO_Mailing::getMailingsList();