From d2016abd023c32e55905685f48a8c0cc5d70fc2b Mon Sep 17 00:00:00 2001 From: Anjali Ujjainia Date: Sun, 22 May 2016 16:02:30 +0530 Subject: [PATCH] CRM-18560 - Validate either body text or body html --- CRM/Mailing/Form/Component.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/CRM/Mailing/Form/Component.php b/CRM/Mailing/Form/Component.php index f6d0a83df2..e3e5dc3017 100644 --- a/CRM/Mailing/Form/Component.php +++ b/CRM/Mailing/Form/Component.php @@ -76,8 +76,7 @@ class CRM_Mailing_Form_Component extends CRM_Core_Form { TRUE ); $this->add('textarea', 'body_text', ts('Body - TEXT Format'), - CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Component', 'body_text'), - TRUE + CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Component', 'body_text') ); $this->add('textarea', 'body_html', ts('Body - HTML Format'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Component', 'body_html') @@ -86,6 +85,7 @@ class CRM_Mailing_Form_Component extends CRM_Core_Form { $this->addYesNo('is_default', ts('Default?')); $this->addYesNo('is_active', ts('Enabled?')); + $this->addFormRule(array('CRM_Mailing_Form_Component', 'formRule')); $this->addFormRule(array('CRM_Mailing_Form_Component', 'dataRule')); $this->addButtons(array( @@ -181,7 +181,26 @@ class CRM_Mailing_Form_Component extends CRM_Core_Form { )) . '
' . ts('More information on tokens...') . ''; } } + return empty($errors) ? TRUE : $errors; + } + /** + * Validates that either body text or body html is required. + * @param array $params + * (ref.) an assoc array of name/value pairs. + * + * @param $files + * @param $options + * + * @return bool|array + * mixed true or array of errors + */ + public static function formRule($params, $files, $options) { + $errors = array(); + if (empty($params['body_text']) && empty($params['body_html'])) { + $errors['body_text'] = ts("Please provide either HTML or TEXT format for the Body."); + $errors['body_html'] = ts("Please provide either HTML or TEXT format for the Body."); + } return empty($errors) ? TRUE : $errors; } -- 2.25.1