addFormRule(array('CRM_Contact_Form_Edit_CommunicationPreferences', 'formRule'), $this); } /** * Set defaults for the form * * @return array * @access public */ public function setDefaultValues() { $defaults = parent::setDefaultValues(); if (!empty($defaults['preferred_language'])) { $languages = CRM_Contact_BAO_Contact::buildOptions('preferred_language'); $defaults['preferred_language'] = CRM_Utils_Array::key($defaults['preferred_language'], $languages); } // CRM-7119: set preferred_language to default if unset if (empty($defaults['preferred_language'])) { $config = CRM_Core_Config::singleton(); $defaults['preferred_language'] = $config->lcMessages; } if (empty($defaults['communication_style_id'])) { $defaults['communication_style_id'] = array_pop(CRM_Core_OptionGroup::values('communication_style', TRUE, NULL, NULL, 'AND is_default = 1')); } foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) { $name = "{$greeting}_display"; $this->assign($name, CRM_Utils_Array::value($name, $defaults)); } return $defaults; } /** * Process the form * * @return void * @access public */ public function postProcess() { $params = $this->exportValues(); // Process / save communication preferences // this is a chekbox, so mark false if we dont get a POST value $params['is_opt_out'] = CRM_Utils_Array::value('is_opt_out', $params, FALSE); $params['contact_type'] = $this->_contactType; $params['contact_id'] = $this->_contactId; if (!empty($this->_contactSubType)) { $params['contact_sub_type'] = $this->_contactSubType; } CRM_Contact_BAO_Contact::create($params); $this->response(); } }