dev/core#481 Ensure that Bulk Mailings is a checkbox rather than radio to allow for...
[civicrm-core.git] / CRM / Contact / Form / Edit / Email.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
8c9251b3 31 * @copyright CiviCRM LLC (c) 2004-2018
6a488035
TO
32 */
33
34/**
c037736a 35 * Form helper class for an Email object.
6a488035
TO
36 */
37class CRM_Contact_Form_Edit_Email {
38
39 /**
fe482240 40 * Build the form object elements for an email object.
6a488035 41 *
77c5b619
TO
42 * @param CRM_Core_Form $form
43 * Reference to the form object.
44 * @param int $blockCount
45 * Block number to build.
46 * @param bool $blockEdit
47 * Is it block edit.
6a488035 48 */
00be9182 49 public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE) {
6a488035
TO
50 // passing this via the session is AWFUL. we need to fix this
51 if (!$blockCount) {
52 $blockId = ($form->get('Email_Block_Count')) ? $form->get('Email_Block_Count') : 1;
53 }
54 else {
55 $blockId = $blockCount;
56 }
57
58 $form->applyFilter('__ALL__', 'trim');
59
60 //Email box
c7915cc9 61 $form->addField("email[$blockId][email]", array('entity' => 'email', 'aria-label' => ts('Email %1', [1 => $blockId])));
6a488035
TO
62 $form->addRule("email[$blockId][email]", ts('Email is not valid.'), 'email');
63 if (isset($form->_contactType) || $blockEdit) {
64 //Block type
a7353b70 65 $form->addField("email[$blockId][location_type_id]", array('entity' => 'email', 'placeholder' => NULL, 'class' => 'eight', 'option_url' => NULL));
6a488035 66
031f9ac8 67 //TODO: Refactor on_hold field to select.
6a488035
TO
68 $multipleBulk = CRM_Core_BAO_Email::isMultipleBulkMail();
69
70 //On-hold select
71 if ($multipleBulk) {
6ea503d4
TO
72 $holdOptions = array(
73 0 => ts('- select -'),
6a488035
TO
74 1 => ts('On Hold Bounce'),
75 2 => ts('On Hold Opt Out'),
76 );
77 $form->addElement('select', "email[$blockId][on_hold]", '', $holdOptions);
78 }
79 else {
c7915cc9 80 $form->addField("email[$blockId][on_hold]", array('entity' => 'email', 'type' => 'advcheckbox', 'aria-label' => ts('On Hold for Email %1?', [1 => $blockId])));
6a488035
TO
81 }
82
83 //Bulkmail checkbox
84 $form->assign('multipleBulk', $multipleBulk);
c7915cc9 85 $js = array('id' => "Email_" . $blockId . "_IsBulkmail" , 'aria-label' => ts('Bulk Mailing for Email %1?', [1 => $blockId]));
c13191a7
SL
86 if (!$blockEdit) {
87 $js['onClick'] = 'singleSelect( this.id );';
6a488035 88 }
c13191a7 89 $form->addElement('advcheckbox', "email[$blockId][is_bulkmail]", NULL, '', $js);
6a488035
TO
90
91 //is_Primary radio
c7915cc9 92 $js = array('id' => "Email_" . $blockId . "_IsPrimary", 'aria-label' => ts('Email %1 is primary?', [1 => $blockId]));
6a488035
TO
93 if (!$blockEdit) {
94 $js['onClick'] = 'singleSelect( this.id );';
95 }
96
97 $form->addElement('radio', "email[$blockId][is_primary]", '', '', '1', $js);
98
99 if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') {
100
101 $form->add('textarea', "email[$blockId][signature_text]", ts('Signature (Text)'),
102 array('rows' => 2, 'cols' => 40)
103 );
104
5d51a2f9 105 $form->add('wysiwyg', "email[$blockId][signature_html]", ts('Signature (HTML)'),
6a488035
TO
106 array('rows' => 2, 'cols' => 40)
107 );
108 }
109 }
110 }
96025800 111
6a488035 112}