3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Auxiliary class to provide support to the Contact Form class.
21 * Does this by implementing a small set of static methods.
23 class CRM_Contact_Form_Edit_Individual
{
26 * This function provides the HTML form elements that are specific to the Individual Contact Type.
28 * @param CRM_Core_Form $form
30 * @param int $inlineEditMode
31 * ( 1 for contact summary.
32 * top bar form and 2 for display name edit )
34 public static function buildQuickForm(&$form, $inlineEditMode = NULL) {
35 $form->applyFilter('__ALL__', 'trim');
37 if (!$inlineEditMode ||
$inlineEditMode == 1) {
38 $nameFields = CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
39 'contact_edit_options', TRUE, NULL,
40 FALSE, 'name', TRUE, 'AND v.filter = 2'
43 // Use names instead of labels to build form.
44 $nameFields = array_keys($nameFields);
46 // Fixme: dear god why? these come out in a format that is NOT the name of the fields.
47 foreach ($nameFields as &$fix) {
48 $fix = str_replace(' ', '_', strtolower($fix));
49 if ($fix == 'prefix' ||
$fix == 'suffix') {
55 foreach ($nameFields as $name) {
57 if ($name == 'prefix_id' ||
$name == 'suffix_id') {
58 //override prefix/suffix label name as Prefix/Suffix respectively and adjust select size
59 $props = ['class' => 'eight', 'placeholder' => ' ', 'label' => $name == 'prefix_id' ?
ts('Prefix') : ts('Suffix')];
61 $form->addField($name, $props);
65 if (!$inlineEditMode ||
$inlineEditMode == 2) {
67 $form->addField('nick_name');
70 // override the size for UI to look better
71 $form->addField('job_title', ['size' => '30']);
73 //Current Employer Element
75 'api' => ['params' => ['contact_type' => 'Organization']],
78 $form->addField('employer_id', $props);
79 $form->addField('contact_source', ['class' => 'big']);
82 if (!$inlineEditMode) {
83 //External Identifier Element
84 $form->addField('external_identifier', ['label' => 'External ID']);
86 $form->addRule('external_identifier',
87 ts('External ID already exists in Database.'),
89 ['CRM_Contact_DAO_Contact', $form->_contactId
, 'external_identifier']
91 CRM_Core_ShowHideBlocks
::links($form, 'demographics', '', '');
98 * @param array $fields
99 * The input form values.
100 * @param array $files
101 * The uploaded files if any.
102 * @param int $contactID
105 * TRUE if no errors, else array of errors.
107 public static function formRule($fields, $files, $contactID = NULL) {
109 $primaryID = CRM_Contact_Form_Contact
::formRule($fields, $errors, $contactID, 'Individual');
111 // make sure that firstName and lastName or a primary OpenID is set
112 if (!$primaryID && (empty($fields['first_name']) ||
empty($fields['last_name']))) {
113 $errors['_qf_default'] = ts('First Name and Last Name OR an email OR an OpenID in the Primary Location should be set.');
116 return empty($errors) ?
TRUE : $errors;