Merge pull request #18115 from sunilpawar/dev_1943
[civicrm-core.git] / CRM / Contact / Form / Edit / Email.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Form helper class for an Email object.
20 */
21 class CRM_Contact_Form_Edit_Email {
22
23 /**
24 * Build the form object elements for an email object.
25 *
26 * @param CRM_Core_Form $form
27 * Reference to the form object.
28 * @param int $blockCount
29 * Block number to build.
30 * @param bool $blockEdit
31 * Is it block edit.
32 */
33 public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE) {
34 // passing this via the session is AWFUL. we need to fix this
35 if (!$blockCount) {
36 $blockId = ($form->get('Email_Block_Count')) ? $form->get('Email_Block_Count') : 1;
37 }
38 else {
39 $blockId = $blockCount;
40 }
41
42 $form->applyFilter('__ALL__', 'trim');
43
44 //Email box
45 $form->addField("email[$blockId][email]", ['entity' => 'email', 'aria-label' => ts('Email %1', [1 => $blockId])]);
46 $form->addRule("email[$blockId][email]", ts('Email is not valid.'), 'email');
47 if (isset($form->_contactType) || $blockEdit) {
48 //Block type
49 $form->addField("email[$blockId][location_type_id]", ['entity' => 'email', 'placeholder' => NULL, 'class' => 'eight', 'option_url' => NULL]);
50
51 //TODO: Refactor on_hold field to select.
52 $multipleBulk = CRM_Core_BAO_Email::isMultipleBulkMail();
53
54 //On-hold select
55 if ($multipleBulk) {
56 $holdOptions = [
57 0 => ts('- select -'),
58 1 => ts('On Hold Bounce'),
59 2 => ts('On Hold Opt Out'),
60 ];
61 $form->addElement('select', "email[$blockId][on_hold]", '', $holdOptions);
62 }
63 else {
64 $form->addField("email[$blockId][on_hold]", ['entity' => 'email', 'type' => 'advcheckbox', 'aria-label' => ts('On Hold for Email %1?', [1 => $blockId])]);
65 }
66
67 //Bulkmail checkbox
68 $form->assign('multipleBulk', $multipleBulk);
69 $js = ['id' => "Email_" . $blockId . "_IsBulkmail" , 'aria-label' => ts('Bulk Mailing for Email %1?', [1 => $blockId])];
70 if (!$blockEdit) {
71 $js['onClick'] = 'singleSelect( this.id );';
72 }
73 $form->addElement('advcheckbox', "email[$blockId][is_bulkmail]", NULL, '', $js);
74
75 //is_Primary radio
76 $js = ['id' => "Email_" . $blockId . "_IsPrimary", 'aria-label' => ts('Email %1 is primary?', [1 => $blockId])];
77 if (!$blockEdit) {
78 $js['onClick'] = 'singleSelect( this.id );';
79 }
80
81 $form->addElement('radio', "email[$blockId][is_primary]", '', '', '1', $js);
82
83 if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') {
84
85 $form->add('textarea', "email[$blockId][signature_text]", ts('Signature (Text)'),
86 ['rows' => 2, 'cols' => 40]
87 );
88
89 $form->add('wysiwyg', "email[$blockId][signature_html]", ts('Signature (HTML)'),
90 ['rows' => 2, 'cols' => 40]
91 );
92 }
93 }
94 }
95
96 }