3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Form helper class for communication preferences inline edit section.
21 class CRM_Contact_Form_Inline_CommunicationPreferences
extends CRM_Contact_Form_Inline
{
24 * Build the form object elements for communication preferences.
26 public function buildQuickForm() {
27 parent
::buildQuickForm();
28 CRM_Contact_Form_Edit_CommunicationPreferences
::buildQuickForm($this);
29 $this->addFormRule(['CRM_Contact_Form_Edit_CommunicationPreferences', 'formRule'], $this);
33 * Set defaults for the form.
37 public function setDefaultValues() {
38 $defaults = parent
::setDefaultValues();
40 if (!empty($defaults['preferred_language'])) {
41 $languages = CRM_Contact_BAO_Contact
::buildOptions('preferred_language');
42 $defaults['preferred_language'] = CRM_Utils_Array
::key($defaults['preferred_language'], $languages);
45 // CRM-7119: set preferred_language to default if unset
46 if (empty($defaults['preferred_language'])) {
47 $config = CRM_Core_Config
::singleton();
48 $defaults['preferred_language'] = $config->lcMessages
;
51 // CRM-19135: where CRM_Core_BAO_Contact::getValues() set label as a default value instead of reserved 'value',
52 // the code is to ensure we always set default to value instead of label
53 if (!empty($defaults['preferred_mail_format'])) {
54 $defaults['preferred_mail_format'] = array_search($defaults['preferred_mail_format'], CRM_Core_SelectValues
::pmf());
57 if (empty($defaults['communication_style_id'])) {
58 $defaults['communication_style_id'] = array_pop(CRM_Core_OptionGroup
::values('communication_style', TRUE, NULL, NULL, 'AND is_default = 1'));
61 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
62 $name = "{$greeting}_display";
63 $this->assign($name, CRM_Utils_Array
::value($name, $defaults));
71 public function postProcess() {
72 $params = $this->exportValues();
74 // Process / save communication preferences
76 // this is a chekbox, so mark false if we dont get a POST value
77 $params['is_opt_out'] = CRM_Utils_Array
::value('is_opt_out', $params, FALSE);
78 $params['contact_type'] = $this->_contactType
;
79 $params['contact_id'] = $this->_contactId
;
81 if (!empty($this->_contactSubType
)) {
82 $params['contact_sub_type'] = $this->_contactSubType
;
85 if (!isset($params['preferred_communication_method'])) {
86 $params['preferred_communication_method'] = 'null';
88 CRM_Contact_BAO_Contact
::create($params);