Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
c037736a | 19 | * Auxiliary class to provide support to the Contact Form class. |
6a488035 | 20 | * |
c037736a | 21 | * Does this by implementing a small set of static methods. |
6a488035 TO |
22 | */ |
23 | class CRM_Contact_Form_Edit_Household { | |
24 | ||
c490a46a | 25 | /** |
c037736a | 26 | * This function provides the HTML form elements that are specific to the Household Contact Type. |
6a488035 | 27 | * |
77c5b619 TO |
28 | * @param CRM_Core_Form $form |
29 | * Form object. | |
30 | * @param int $inlineEditMode | |
31 | * ( 1 for contact summary. | |
6a488035 | 32 | * top bar form and 2 for display name edit ) |
6a488035 TO |
33 | */ |
34 | public static function buildQuickForm(&$form, $inlineEditMode = NULL) { | |
6a488035 TO |
35 | $form->applyFilter('__ALL__', 'trim'); |
36 | ||
481a74f4 | 37 | if (!$inlineEditMode || $inlineEditMode == 1) { |
6a488035 | 38 | // household_name |
b46085d1 | 39 | $form->addField('household_name'); |
6a488035 TO |
40 | } |
41 | ||
481a74f4 | 42 | if (!$inlineEditMode || $inlineEditMode == 2) { |
6a488035 | 43 | // nick_name |
b46085d1 | 44 | $form->addField('nick_name'); |
be2fb01f | 45 | $form->addField('contact_source', ['label' => ts('Source')]); |
6a488035 TO |
46 | } |
47 | ||
481a74f4 | 48 | if (!$inlineEditMode) { |
be2fb01f | 49 | $form->addField('external_identifier', ['label' => ts('External ID')]); |
6a488035 TO |
50 | $form->addRule('external_identifier', |
51 | ts('External ID already exists in Database.'), | |
52 | 'objectExists', | |
be2fb01f | 53 | ['CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier'] |
6a488035 TO |
54 | ); |
55 | } | |
56 | } | |
57 | ||
58 | /** | |
fe482240 | 59 | * Add rule for household. |
6a488035 | 60 | * |
77c5b619 TO |
61 | * @param array $fields |
62 | * Array of form values. | |
63 | * @param array $files | |
64 | * Unused. | |
c490a46a | 65 | * @param int $contactID |
77b97be7 | 66 | * |
72b3a70c CW |
67 | * @return array|bool |
68 | * $error | |
6a488035 | 69 | */ |
00be9182 | 70 | public static function formRule($fields, $files, $contactID = NULL) { |
be2fb01f | 71 | $errors = []; |
d6def514 | 72 | $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID, 'Household'); |
6a488035 TO |
73 | |
74 | // make sure that household name is set | |
a7488080 | 75 | if (empty($fields['household_name'])) { |
6a488035 TO |
76 | $errors['household_name'] = 'Household Name should be set.'; |
77 | } | |
78 | ||
6a488035 TO |
79 | return empty($errors) ? TRUE : $errors; |
80 | } | |
96025800 | 81 | |
6a488035 | 82 | } |