Merge pull request #18631 from eileenmcnaughton/ppp
[civicrm-core.git] / CRM / Contact / Form / Edit / Household.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 * Auxiliary class to provide support to the Contact Form class.
20 *
21 * Does this by implementing a small set of static methods.
22 */
23 class CRM_Contact_Form_Edit_Household {
24
25 /**
26 * This function provides the HTML form elements that are specific to the Household Contact Type.
27 *
28 * @param CRM_Core_Form $form
29 * Form object.
30 * @param int $inlineEditMode
31 * ( 1 for contact summary.
32 * top bar form and 2 for display name edit )
33 */
34 public static function buildQuickForm(&$form, $inlineEditMode = NULL) {
35 $form->applyFilter('__ALL__', 'trim');
36
37 if (!$inlineEditMode || $inlineEditMode == 1) {
38 // household_name
39 $form->addField('household_name');
40 }
41
42 if (!$inlineEditMode || $inlineEditMode == 2) {
43 // nick_name
44 $form->addField('nick_name');
45 $form->addField('contact_source', ['label' => ts('Source')]);
46 }
47
48 if (!$inlineEditMode) {
49 $form->addField('external_identifier', ['label' => ts('External ID')]);
50 $form->addRule('external_identifier',
51 ts('External ID already exists in Database.'),
52 'objectExists',
53 ['CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier']
54 );
55 }
56 }
57
58 /**
59 * Add rule for household.
60 *
61 * @param array $fields
62 * Array of form values.
63 * @param array $files
64 * Unused.
65 * @param int $contactID
66 *
67 * @return array|bool
68 * $error
69 */
70 public static function formRule($fields, $files, $contactID = NULL) {
71 $errors = [];
72 $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID, 'Household');
73
74 // make sure that household name is set
75 if (empty($fields['household_name'])) {
76 $errors['household_name'] = 'Household Name should be set.';
77 }
78
79 return empty($errors) ? TRUE : $errors;
80 }
81
82 }