From dd4706efd1edd5896255c9c67c376662d78148e7 Mon Sep 17 00:00:00 2001 From: Tim Mallezie Date: Tue, 12 May 2015 18:05:09 +0200 Subject: [PATCH] use addField in communication preferences form --- .../Form/Edit/CommunicationPreferences.php | 23 +++------ CRM/Core/Form.php | 47 ++++++++++++++++++- .../Form/Edit/CommunicationPreferences.tpl | 22 ++++----- xml/schema/Contact/Contact.xml | 3 ++ 4 files changed, 65 insertions(+), 30 deletions(-) diff --git a/CRM/Contact/Form/Edit/CommunicationPreferences.php b/CRM/Contact/Form/Edit/CommunicationPreferences.php index beb88b74f8..f3f3070cf2 100644 --- a/CRM/Contact/Form/Edit/CommunicationPreferences.php +++ b/CRM/Contact/Form/Edit/CommunicationPreferences.php @@ -67,16 +67,15 @@ class CRM_Contact_Form_Edit_CommunicationPreferences { foreach ($privacyOptions as $name => $label) { $privacy[] = $form->createElement('advcheckbox', $name, NULL, $label); } - $form->addGroup($privacy, 'privacy', ts('Privacy'), ' '); + $form->addGroup($privacy, 'privacy', ts('Privacy'), ' 
'); // preferred communication method $comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method', array('loclize' => TRUE)); foreach ($comm as $value => $title) { $commPreff[] = $form->createElement('advcheckbox', $value, NULL, $title); } - $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Method(s)')); - - $form->addSelect('preferred_language'); + $form->addField('preferred_communication_method', array('entity' => 'contact', 'type' => 'CheckBoxGroup')); + $form->addField('preferred_language', array('entity' => 'contact')); if (!empty($privacyOptions)) { $commPreference['privacy'] = $privacyOptions; @@ -88,21 +87,11 @@ class CRM_Contact_Form_Edit_CommunicationPreferences { //using for display purpose. $form->assign('commPreference', $commPreference); - $form->add('select', 'preferred_mail_format', ts('Email Format'), CRM_Core_SelectValues::pmf()); - $form->add('checkbox', 'is_opt_out', ts('NO BULK EMAILS (User Opt Out)')); + $form->addField('preferred_mail_format', array('entity' => 'contact', 'label' => ts('Email Format'))); - $communicationStyleOptions = array(); - $communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id', array('localize' => TRUE)); - foreach ($communicationStyle as $key => $var) { - $communicationStyleOptions[$key] = $form->createElement('radio', NULL, - ts('Communication Style'), $var, $key, - array('id' => "civicrm_communication_style_{$var}_{$key}") - ); - } - if (!empty($communicationStyleOptions)) { - $form->addGroup($communicationStyleOptions, 'communication_style_id', ts('Communication Style')); - } + $form->addField('is_opt_out', array('entity' => 'contact', 'label' => ts('NO BULK EMAILS (User Opt Out)'))); + $form->addField('communication_style_id', array('entity' => 'contact', 'type' => 'RadioGroup')); //check contact type and build filter clause accordingly for greeting types, CRM-4575 $greetings = self::getGreetingFields($form->_contactType); diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 822792605c..43e60e28c1 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -900,6 +900,20 @@ class CRM_Core_Form extends HTML_QuickForm_Page { return $group; } + /** + * @param string $name + * @param $title + * @param $values + * @param array $attributes + * @param null $separator + * @param bool $required + * + * @return HTML_QuickForm_group + */ + public function &addRadioGroup($name, $title, $values, $attributes = array(), $separator = NULL, $required = FALSE) { + return $this->addRadio($name, $title, $values, $attributes, $separator, $required); + } + /** * @param int $id * @param $title @@ -976,6 +990,28 @@ class CRM_Core_Form extends HTML_QuickForm_Page { } } + + /** + * @param int $id + * @param $title + * @param $values + * @param null $other + * @param null $attributes + * @param null $required + * @param null $javascriptMethod + * @param string $separator + * @param bool $flipValues + */ + public function addCheckBoxGroup( + $id, $title, $values, $other = NULL, $attributes = NULL, $required = NULL, + $javascriptMethod = NULL, $separator = '
', $flipValues = FALSE + ) { + $this->addCheckBox( + $id, $title, $values, $other, + $attributes, $required, $javascriptMethod, $separator, $flipValues + ); + } + public function resetValues() { $data = $this->controller->container(); $data['values'][$this->_name] = array(); @@ -1197,7 +1233,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page { 'Select Country', 'Multi-Select Country', 'AdvMulti-Select', - 'CheckBox', + 'CheckBoxGroup', + 'RadioGroup', 'Radio', ))); @@ -1296,6 +1333,14 @@ class CRM_Core_Form extends HTML_QuickForm_Page { // TODO: Add and/or option for fields that store multiple values break; + case 'CheckBoxGroup': + $this->addCheckBoxGroup($name, $label, array_flip($options), $required, $props); + break; + + case 'RadioGroup': + $this->addRadioGroup($name, $label, $options, $props, NULL, $required); + break; + //case 'AdvMulti-Select': case 'CheckBox': $text = isset($props['text']) ? $props['text'] : NULL; diff --git a/templates/CRM/Contact/Form/Edit/CommunicationPreferences.tpl b/templates/CRM/Contact/Form/Edit/CommunicationPreferences.tpl index c4116b4d40..4ec52af45b 100644 --- a/templates/CRM/Contact/Form/Edit/CommunicationPreferences.tpl +++ b/templates/CRM/Contact/Form/Edit/CommunicationPreferences.tpl @@ -107,18 +107,16 @@ {/if} - {foreach key=key item=item from=$commPreference} - -
{$form.$key.label} {help id="id-$key" file="CRM/Contact/Form/Contact.hlp"} - {foreach key=k item=i from=$item} -
{$form.$key.$k.html} - {/foreach} - - {/foreach} - -
{$form.preferred_language.label} -
{$form.preferred_language.html} - + {foreach key=key item=item from=$commPreference} + +
{$form.$key.label} {help id="id-$key" file="CRM/Contact/Form/Contact.hlp"} +
{$form.$key.html} + + {/foreach} + +
{$form.preferred_language.label} +
{$form.preferred_language.html} + {$form.is_opt_out.html} {$form.is_opt_out.label} {help id="id-optOut" file="CRM/Contact/Form/Contact.hlp"} diff --git a/xml/schema/Contact/Contact.xml b/xml/schema/Contact/Contact.xml index 06f6b50d67..4cddbcf7af 100644 --- a/xml/schema/Contact/Contact.xml +++ b/xml/schema/Contact/Contact.xml @@ -493,6 +493,9 @@ true Communication style (e.g. formal vs. familiar) to use with this contact. FK to communication styles in civicrm_option_value. 4.4 + + Select + index_communication_style_id -- 2.25.1